@peteanderson/ansi 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/slice.d.ts +2 -1
- package/dist/cjs/slice.d.ts.map +1 -1
- package/dist/cjs/slice.js +7 -7
- package/dist/cjs/slice.js.map +1 -1
- package/dist/cjs/split-at.d.ts +4 -4
- package/dist/cjs/split-at.d.ts.map +1 -1
- package/dist/cjs/split-at.js +11 -5
- package/dist/cjs/split-at.js.map +1 -1
- package/dist/esm/slice.d.ts +2 -1
- package/dist/esm/slice.d.ts.map +1 -1
- package/dist/esm/slice.js +7 -8
- package/dist/esm/slice.js.map +1 -1
- package/dist/esm/split-at.d.ts +4 -4
- package/dist/esm/split-at.d.ts.map +1 -1
- package/dist/esm/split-at.js +12 -6
- package/dist/esm/split-at.js.map +1 -1
- package/package.json +1 -1
- package/src/slice.ts +10 -9
- package/src/split-at.ts +18 -6
package/dist/cjs/slice.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare function scanCSI(text: string, fromStringIndex: number, visibleCo
|
|
|
2
2
|
index: number;
|
|
3
3
|
length: number;
|
|
4
4
|
};
|
|
5
|
+
export declare function skippedSequences(text: string, start: number, end?: number): string;
|
|
5
6
|
/**
|
|
6
7
|
* Return a slice of the given text, counting only visible characters (i.e. ignoring ANSI escape
|
|
7
8
|
* codes). The returned slice will include any ANSI escape codes from within the slice. In addition,
|
|
@@ -21,6 +22,6 @@ export declare function scanCSI(text: string, fromStringIndex: number, visibleCo
|
|
|
21
22
|
* of the slice as it would be if the whole string were printed. This function is intended mostly
|
|
22
23
|
* for text that contains SGR codes, but no other ANSI codes or control characters.
|
|
23
24
|
*/
|
|
24
|
-
export declare function slice(text: string, start: number, end
|
|
25
|
+
export declare function slice(text: string, start: number, end?: number): string;
|
|
25
26
|
export type Slice = typeof slice;
|
|
26
27
|
//# sourceMappingURL=slice.d.ts.map
|
package/dist/cjs/slice.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../../src/slice.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CACtB,IAAI,EAAc,MAAM,EACxB,eAAe,EAAG,MAAM,EACxB,YAAY,EAAM,MAAM,GACtB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAsBjC;
|
|
1
|
+
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../../src/slice.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CACtB,IAAI,EAAc,MAAM,EACxB,eAAe,EAAG,MAAM,EACxB,YAAY,EAAM,MAAM,GACtB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAsBjC;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAGlF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BvE;AAED,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC"}
|
package/dist/cjs/slice.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.scanCSI = scanCSI;
|
|
4
|
+
exports.skippedSequences = skippedSequences;
|
|
4
5
|
exports.slice = slice;
|
|
5
6
|
const patterns_1 = require("./patterns");
|
|
6
7
|
const simplify_1 = require("./simplify");
|
|
@@ -50,13 +51,12 @@ function skippedSequences(text, start, end) {
|
|
|
50
51
|
function slice(text, start, end) {
|
|
51
52
|
let textVisibleLength;
|
|
52
53
|
const getVisibleLength = () => textVisibleLength ??= (0, strip_1.visibleLength)(text);
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
54
|
+
if (end === undefined)
|
|
55
|
+
end = getVisibleLength();
|
|
56
|
+
if (start < 0)
|
|
57
|
+
start = Math.max(0, getVisibleLength() + start);
|
|
58
|
+
if (end < 0)
|
|
59
|
+
end = Math.max(0, getVisibleLength() + end);
|
|
60
60
|
if (start > end)
|
|
61
61
|
return "";
|
|
62
62
|
if (start === 0 && (end >= text.length || end >= getVisibleLength()))
|
package/dist/cjs/slice.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.js","sourceRoot":"","sources":["../../src/slice.ts"],"names":[],"mappings":";;AAIA,0BA0BC;
|
|
1
|
+
{"version":3,"file":"slice.js","sourceRoot":"","sources":["../../src/slice.ts"],"names":[],"mappings":";;AAIA,0BA0BC;AAED,4CAGC;AAqBD,sBA8BC;AAtFD,yCAAyC;AACzC,yCAAyC;AACzC,mCAAsC;AAEtC,SAAgB,OAAO,CACtB,IAAwB,EACxB,eAAwB,EACxB,YAAwB;IAExB,gEAAgE;IAChE,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,gBAAK,CAAC,CAAC;IAE7B,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,KAAK,GAAI,eAAe,CAAC;IAE7B,OAAO,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,MAAM,GAAG,YAAY,EAAE,CAAC;QACrD,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,MAAM,EAAE,CAAC;YAC5B,EAAE,CAAC,SAAS,GAAG,KAAK,CAAC;YACrB,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,KAAK,EAAE,KAAK,KAAK,KAAK,EAAE,CAAC;gBAC5B,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MA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AAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAE5E,MAAM,QAAQ,GACb,UAAU,GAAG,IAAI,CAAC,MAAM,IAAI,cAAc,GAAG,GAAG;QAC/C,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,KAAK;QACvD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAEhB,mGAAmG;IACnG,MAAM,gBAAgB,GAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;IAChE,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE3D,OAAO,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,iBAAiB,CAAC;AAChF,CAAC"}
|
package/dist/cjs/split-at.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* ignoring ANSI escape codes). The returned strings will include any ANSI escape codes from within
|
|
4
4
|
* each slice.
|
|
5
5
|
*
|
|
6
|
-
* Note that unlike {@linkcode slice}, this function
|
|
7
|
-
* or after the split point. If you need to preserve the terminal state before and after
|
|
8
|
-
|
|
6
|
+
* Note that unlike {@linkcode slice}, this function doesn't, by default include any SGR codes (m)
|
|
7
|
+
* from before or after the split point. If you need to preserve the terminal state before and after
|
|
8
|
+
* the split, pass `true` for the `includeSkipped` parameter.
|
|
9
9
|
*/
|
|
10
|
-
export declare function splitAt(text: string, visibleIndex: number): [start: string, end: string];
|
|
10
|
+
export declare function splitAt(text: string, visibleIndex: number, includeSkipped?: boolean): [start: string, end: string];
|
|
11
11
|
export type SplitAt = typeof splitAt;
|
|
12
12
|
//# sourceMappingURL=split-at.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-at.d.ts","sourceRoot":"","sources":["../../src/split-at.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,OAAO,
|
|
1
|
+
{"version":3,"file":"split-at.d.ts","sourceRoot":"","sources":["../../src/split-at.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CACtB,IAAI,EAAa,MAAM,EACvB,YAAY,EAAK,MAAM,EACvB,cAAc,GAAG,OAAe,GAC9B,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAwB9B;AAED,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC"}
|
package/dist/cjs/split-at.js
CHANGED
|
@@ -7,11 +7,11 @@ const slice_1 = require("./slice");
|
|
|
7
7
|
* ignoring ANSI escape codes). The returned strings will include any ANSI escape codes from within
|
|
8
8
|
* each slice.
|
|
9
9
|
*
|
|
10
|
-
* Note that unlike {@linkcode slice}, this function
|
|
11
|
-
* or after the split point. If you need to preserve the terminal state before and after
|
|
12
|
-
|
|
10
|
+
* Note that unlike {@linkcode slice}, this function doesn't, by default include any SGR codes (m)
|
|
11
|
+
* from before or after the split point. If you need to preserve the terminal state before and after
|
|
12
|
+
* the split, pass `true` for the `includeSkipped` parameter.
|
|
13
13
|
*/
|
|
14
|
-
function splitAt(text, visibleIndex) {
|
|
14
|
+
function splitAt(text, visibleIndex, includeSkipped = false) {
|
|
15
15
|
if (!visibleIndex)
|
|
16
16
|
return ["", text];
|
|
17
17
|
if (visibleIndex < 0)
|
|
@@ -21,6 +21,12 @@ function splitAt(text, visibleIndex) {
|
|
|
21
21
|
const { index } = (0, slice_1.scanCSI)(text, 0, visibleIndex);
|
|
22
22
|
if (index === text.length)
|
|
23
23
|
return [text, ""];
|
|
24
|
-
|
|
24
|
+
let start = text.slice(0, index);
|
|
25
|
+
let end = text.slice(index);
|
|
26
|
+
if (includeSkipped) {
|
|
27
|
+
start += (0, slice_1.skippedSequences)(text, index);
|
|
28
|
+
end = (0, slice_1.skippedSequences)(text, 0, index) + end;
|
|
29
|
+
}
|
|
30
|
+
return [start, end];
|
|
25
31
|
}
|
|
26
32
|
//# sourceMappingURL=split-at.js.map
|
package/dist/cjs/split-at.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-at.js","sourceRoot":"","sources":["../../src/split-at.ts"],"names":[],"mappings":";;AAaA,
|
|
1
|
+
{"version":3,"file":"split-at.js","sourceRoot":"","sources":["../../src/split-at.ts"],"names":[],"mappings":";;AAaA,0BA4BC;AAzCD,mCAAkD;AAIlD;;;;;;;;GAQG;AACH,SAAgB,OAAO,CACtB,IAAuB,EACvB,YAAuB,EACvB,iBAA2B,KAAK;IAEhC,IAAI,CAAC,YAAY;QAChB,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAEnB,IAAI,YAAY,GAAG,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEtD,IAAI,YAAY,GAAG,IAAI,CAAC,MAAM;QAC7B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAEnB,MAAM,EAAC,KAAK,EAAC,GAAG,IAAA,eAAO,EAAC,IAAI,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC;IAE/C,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM;QACxB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAEnB,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACjC,IAAI,GAAG,GAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAE9B,IAAI,cAAc,EAAE,CAAC;QACpB,KAAK,IAAI,IAAA,wBAAgB,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACvC,GAAG,GAAM,IAAA,wBAAgB,EAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC;IACjD,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACrB,CAAC"}
|
package/dist/esm/slice.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare function scanCSI(text: string, fromStringIndex: number, visibleCo
|
|
|
2
2
|
index: number;
|
|
3
3
|
length: number;
|
|
4
4
|
};
|
|
5
|
+
export declare function skippedSequences(text: string, start: number, end?: number): string;
|
|
5
6
|
/**
|
|
6
7
|
* Return a slice of the given text, counting only visible characters (i.e. ignoring ANSI escape
|
|
7
8
|
* codes). The returned slice will include any ANSI escape codes from within the slice. In addition,
|
|
@@ -21,6 +22,6 @@ export declare function scanCSI(text: string, fromStringIndex: number, visibleCo
|
|
|
21
22
|
* of the slice as it would be if the whole string were printed. This function is intended mostly
|
|
22
23
|
* for text that contains SGR codes, but no other ANSI codes or control characters.
|
|
23
24
|
*/
|
|
24
|
-
export declare function slice(text: string, start: number, end
|
|
25
|
+
export declare function slice(text: string, start: number, end?: number): string;
|
|
25
26
|
export type Slice = typeof slice;
|
|
26
27
|
//# sourceMappingURL=slice.d.ts.map
|
package/dist/esm/slice.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../../src/slice.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CACtB,IAAI,EAAc,MAAM,EACxB,eAAe,EAAG,MAAM,EACxB,YAAY,EAAM,MAAM,GACtB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAsBjC;
|
|
1
|
+
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../../src/slice.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CACtB,IAAI,EAAc,MAAM,EACxB,eAAe,EAAG,MAAM,EACxB,YAAY,EAAM,MAAM,GACtB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAsBjC;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAGlF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BvE;AAED,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC"}
|
package/dist/esm/slice.js
CHANGED
|
@@ -20,7 +20,7 @@ export function scanCSI(text, fromStringIndex, visibleCount) {
|
|
|
20
20
|
}
|
|
21
21
|
return { index, length };
|
|
22
22
|
}
|
|
23
|
-
function skippedSequences(text, start, end) {
|
|
23
|
+
export function skippedSequences(text, start, end) {
|
|
24
24
|
const sequences = text.slice(start, end).match(new RegExp(rxSGR));
|
|
25
25
|
return sequences ? simplify(sequences.join("")) : "";
|
|
26
26
|
}
|
|
@@ -46,13 +46,12 @@ function skippedSequences(text, start, end) {
|
|
|
46
46
|
export function slice(text, start, end) {
|
|
47
47
|
let textVisibleLength;
|
|
48
48
|
const getVisibleLength = () => textVisibleLength ??= visibleLength(text);
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
49
|
+
if (end === undefined)
|
|
50
|
+
end = getVisibleLength();
|
|
51
|
+
if (start < 0)
|
|
52
|
+
start = Math.max(0, getVisibleLength() + start);
|
|
53
|
+
if (end < 0)
|
|
54
|
+
end = Math.max(0, getVisibleLength() + end);
|
|
56
55
|
if (start > end)
|
|
57
56
|
return "";
|
|
58
57
|
if (start === 0 && (end >= text.length || end >= getVisibleLength()))
|
package/dist/esm/slice.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.js","sourceRoot":"","sources":["../../src/slice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,KAAK,EAAC,MAA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AI,CAAC,GAAG,CAAC,CAAC,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC,CAAC;IACjD,IAAI,GAAG,GAAG,CAAC;QACV,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAC,CAAC;IAE7C,IAAI,KAAK,GAAG,GAAG;QACd,OAAO,EAAE,CAAC;IAEX,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACnE,OAAO,IAAI,CAAC;IAEb,MAAM,EAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAE5E,MAAM,QAAQ,GACb,UAAU,GAAG,IAAI,CAAC,MAAM,IAAI,cAAc,GAAG,GAAG;QAC/C,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,GAAG,cAAc,CAAC,CAAC,KAAK;QACvD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAEhB,mGAAmG;IACnG,MAAM,gBAAgB,GAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;IAChE,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE3D,OAAO,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,iBAAiB,CAAC;AAChF,CAAC"}
|
package/dist/esm/split-at.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* ignoring ANSI escape codes). The returned strings will include any ANSI escape codes from within
|
|
4
4
|
* each slice.
|
|
5
5
|
*
|
|
6
|
-
* Note that unlike {@linkcode slice}, this function
|
|
7
|
-
* or after the split point. If you need to preserve the terminal state before and after
|
|
8
|
-
|
|
6
|
+
* Note that unlike {@linkcode slice}, this function doesn't, by default include any SGR codes (m)
|
|
7
|
+
* from before or after the split point. If you need to preserve the terminal state before and after
|
|
8
|
+
* the split, pass `true` for the `includeSkipped` parameter.
|
|
9
9
|
*/
|
|
10
|
-
export declare function splitAt(text: string, visibleIndex: number): [start: string, end: string];
|
|
10
|
+
export declare function splitAt(text: string, visibleIndex: number, includeSkipped?: boolean): [start: string, end: string];
|
|
11
11
|
export type SplitAt = typeof splitAt;
|
|
12
12
|
//# sourceMappingURL=split-at.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-at.d.ts","sourceRoot":"","sources":["../../src/split-at.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,OAAO,
|
|
1
|
+
{"version":3,"file":"split-at.d.ts","sourceRoot":"","sources":["../../src/split-at.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CACtB,IAAI,EAAa,MAAM,EACvB,YAAY,EAAK,MAAM,EACvB,cAAc,GAAG,OAAe,GAC9B,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAwB9B;AAED,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC"}
|
package/dist/esm/split-at.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { scanCSI } from "./slice.js";
|
|
1
|
+
import { scanCSI, skippedSequences } from "./slice.js";
|
|
2
2
|
/**
|
|
3
3
|
* Split a string into two parts at the given visible index (i.e., the given visible character,
|
|
4
4
|
* ignoring ANSI escape codes). The returned strings will include any ANSI escape codes from within
|
|
5
5
|
* each slice.
|
|
6
6
|
*
|
|
7
|
-
* Note that unlike {@linkcode slice}, this function
|
|
8
|
-
* or after the split point. If you need to preserve the terminal state before and after
|
|
9
|
-
|
|
7
|
+
* Note that unlike {@linkcode slice}, this function doesn't, by default include any SGR codes (m)
|
|
8
|
+
* from before or after the split point. If you need to preserve the terminal state before and after
|
|
9
|
+
* the split, pass `true` for the `includeSkipped` parameter.
|
|
10
10
|
*/
|
|
11
|
-
export function splitAt(text, visibleIndex) {
|
|
11
|
+
export function splitAt(text, visibleIndex, includeSkipped = false) {
|
|
12
12
|
if (!visibleIndex)
|
|
13
13
|
return ["", text];
|
|
14
14
|
if (visibleIndex < 0)
|
|
@@ -18,6 +18,12 @@ export function splitAt(text, visibleIndex) {
|
|
|
18
18
|
const { index } = scanCSI(text, 0, visibleIndex);
|
|
19
19
|
if (index === text.length)
|
|
20
20
|
return [text, ""];
|
|
21
|
-
|
|
21
|
+
let start = text.slice(0, index);
|
|
22
|
+
let end = text.slice(index);
|
|
23
|
+
if (includeSkipped) {
|
|
24
|
+
start += skippedSequences(text, index);
|
|
25
|
+
end = skippedSequences(text, 0, index) + end;
|
|
26
|
+
}
|
|
27
|
+
return [start, end];
|
|
22
28
|
}
|
|
23
29
|
//# sourceMappingURL=split-at.js.map
|
package/dist/esm/split-at.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-at.js","sourceRoot":"","sources":["../../src/split-at.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"split-at.js","sourceRoot":"","sources":["../../src/split-at.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAIlD;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO,CACtB,IAAuB,EACvB,YAAuB,EACvB,iBAA2B,KAAK;IAEhC,IAAI,CAAC,YAAY;QAChB,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAEnB,IAAI,YAAY,GAAG,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEtD,IAAI,YAAY,GAAG,IAAI,CAAC,MAAM;QAC7B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAEnB,MAAM,EAAC,KAAK,EAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC;IAE/C,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM;QACxB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAEnB,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACjC,IAAI,GAAG,GAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAE9B,IAAI,cAAc,EAAE,CAAC;QACpB,KAAK,IAAI,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACvC,GAAG,GAAM,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC;IACjD,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACrB,CAAC"}
|
package/package.json
CHANGED
package/src/slice.ts
CHANGED
|
@@ -30,7 +30,7 @@ export function scanCSI(
|
|
|
30
30
|
return {index, length};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function skippedSequences(text: string, start: number, end?: number): string {
|
|
33
|
+
export function skippedSequences(text: string, start: number, end?: number): string {
|
|
34
34
|
const sequences = text.slice(start, end).match(new RegExp(rxSGR));
|
|
35
35
|
return sequences ? simplify(sequences.join("")) : "";
|
|
36
36
|
}
|
|
@@ -54,17 +54,18 @@ function skippedSequences(text: string, start: number, end?: number): string {
|
|
|
54
54
|
* of the slice as it would be if the whole string were printed. This function is intended mostly
|
|
55
55
|
* for text that contains SGR codes, but no other ANSI codes or control characters.
|
|
56
56
|
*/
|
|
57
|
-
export function slice(text: string, start: number, end
|
|
57
|
+
export function slice(text: string, start: number, end?: number): string {
|
|
58
58
|
let textVisibleLength: number | undefined;
|
|
59
59
|
const getVisibleLength = () => textVisibleLength ??= visibleLength(text);
|
|
60
60
|
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
if (end === undefined)
|
|
62
|
+
end = getVisibleLength();
|
|
63
|
+
|
|
64
|
+
if (start < 0)
|
|
65
|
+
start = Math.max(0, getVisibleLength() + start);
|
|
66
|
+
if (end < 0)
|
|
67
|
+
end = Math.max(0, getVisibleLength() + end);
|
|
68
|
+
|
|
68
69
|
if (start > end)
|
|
69
70
|
return "";
|
|
70
71
|
|
package/src/split-at.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {scanCSI} from "./slice";
|
|
1
|
+
import {scanCSI, skippedSequences} from "./slice";
|
|
2
2
|
|
|
3
3
|
import type {slice} from "./slice";
|
|
4
4
|
|
|
@@ -7,11 +7,15 @@ import type {slice} from "./slice";
|
|
|
7
7
|
* ignoring ANSI escape codes). The returned strings will include any ANSI escape codes from within
|
|
8
8
|
* each slice.
|
|
9
9
|
*
|
|
10
|
-
* Note that unlike {@linkcode slice}, this function
|
|
11
|
-
* or after the split point. If you need to preserve the terminal state before and after
|
|
12
|
-
|
|
10
|
+
* Note that unlike {@linkcode slice}, this function doesn't, by default include any SGR codes (m)
|
|
11
|
+
* from before or after the split point. If you need to preserve the terminal state before and after
|
|
12
|
+
* the split, pass `true` for the `includeSkipped` parameter.
|
|
13
13
|
*/
|
|
14
|
-
export function splitAt(
|
|
14
|
+
export function splitAt(
|
|
15
|
+
text : string,
|
|
16
|
+
visibleIndex : number,
|
|
17
|
+
includeSkipped : boolean = false,
|
|
18
|
+
): [start: string, end: string] {
|
|
15
19
|
if (!visibleIndex)
|
|
16
20
|
return ["", text];
|
|
17
21
|
|
|
@@ -26,7 +30,15 @@ export function splitAt(text: string, visibleIndex: number): [start: string, end
|
|
|
26
30
|
if (index === text.length)
|
|
27
31
|
return [text, ""];
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
let start = text.slice(0, index);
|
|
34
|
+
let end = text.slice(index);
|
|
35
|
+
|
|
36
|
+
if (includeSkipped) {
|
|
37
|
+
start += skippedSequences(text, index);
|
|
38
|
+
end = skippedSequences(text, 0, index) + end;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return [start, end];
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
export type SplitAt = typeof splitAt;
|