@peteanderson/ansi 3.5.0 → 3.7.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/README.md CHANGED
@@ -166,8 +166,10 @@ Available if feature is enabled:
166
166
  - `cursor.position.get` - get the current cursor position (terminal sends position to stdin)
167
167
  - `cursor.position.set(row, col)` - set cursor position (1-based indexing)
168
168
  - `cursor.shape.block` / `cursor.shape.underline` / `cursor.shape.bar` - change cursor shape
169
- - `cursor.up(n)` / `cursor.down(n)` / `cursor.forward(n)` / `cursor.backward(n)` - move cursor
170
- - `cursor.nextLine(n)` / `cursor.prevLine(n)` - move cursor to next/previous line
169
+ - `cursor.up(n)` / `cursor.down(n)` / `cursor.forward(n)` / `cursor.backward(n)` - move cursor;
170
+ negative values move in the opposite direction
171
+ - `cursor.nextLine(n)` / `cursor.prevLine(n)` - move cursor to next/previous line; negative values
172
+ move in the opposite direction
171
173
  - `cursor.x(col)` - move cursor to column (1-based)
172
174
  - `cursor.save` / `cursor.restore` - save/restore cursor position (VT100)
173
175
 
@@ -187,15 +189,15 @@ Terminal control features (available if feature is enabled):
187
189
 
188
190
  Available if feature is enabled:
189
191
 
190
- - `insert.char(count)` - insert characters (default 1)
191
- - `insert.line(count)` - insert lines (default 1)
192
+ - `insert.char(count)` - insert characters (default 1); negative values delete characters
193
+ - `insert.line(count)` - insert lines (default 1); negative values delete lines
192
194
 
193
195
  ### `delete`
194
196
 
195
197
  Available if feature is enabled:
196
198
 
197
- - `delete.char(count)` - delete characters (default 1)
198
- - `delete.line(count)` - delete lines (default 1)
199
+ - `delete.char(count)` - delete characters (default 1); negative values insert characters
200
+ - `delete.line(count)` - delete lines (default 1); negative values insert lines
199
201
 
200
202
  ### `erase`
201
203
 
@@ -210,8 +212,10 @@ Available if feature is enabled:
210
212
 
211
213
  Available if feature is enabled:
212
214
 
213
- - `scroll.up(lines)` - scroll up (default 1 line)
214
- - `scroll.down(lines)` - scroll down (default 1 line)
215
+ - `scroll.up(lines)` - scroll up (default 1 line); negative values scroll down
216
+ - `scroll.down(lines)` - scroll down (default 1 line); negative values scroll up
217
+ - `scroll.setRegion(top, bottom)` - set scroll region; omit top/bottom to use defaults (top/bottom
218
+ of viewport)
215
219
 
216
220
  ### `strip(text)`
217
221
 
@@ -47,6 +47,7 @@ export declare const fg: import("./sgr/types").Channel<"bg" | import("./sgr/type
47
47
  }, scroll: {
48
48
  up: (lines?: number | undefined) => string;
49
49
  down: (lines?: number | undefined) => string;
50
+ setRegion: (top?: number, bottom?: number) => string;
50
51
  }, terminal: {
51
52
  focusReporting: {
52
53
  enable: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../../src/ansi.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAuB,OAAO,CAAC;AAKxD,OAAO,EAAC,OAAO,EAAC,MAAgC,YAAY,CAAC;AAC7D,OAAO,EAAW,KAAK,EAAE,aAAa,EAAC,MAAS,SAAS,CAAC;AAG1D,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AACrC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAElC,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,IAAI,GAAG,IAAI,CA0B5C;AAED,eAAO,MAAM,IAAI,MAAiB,CAAC;AACnC,eAAO,MAAM,QAAQ,MAAkB,CAAC;AAExC,eAAO,MAAO,EAAE,wEAAE,EAAE,wEAAE,KAAK,+DAAE,KAAK,UAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;GAAE,KAAK;;;;;;;;;;;;;GAAE,MAAM;;;GAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;CAAQ,CAAC;AAE5E,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAC,CAAA;;;;;;;;;;;;;;;;;;;;AAExD,wBAIE"}
1
+ {"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../../src/ansi.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAuB,OAAO,CAAC;AAKxD,OAAO,EAAC,OAAO,EAAC,MAAgC,YAAY,CAAC;AAC7D,OAAO,EAAW,KAAK,EAAE,aAAa,EAAC,MAAS,SAAS,CAAC;AAG1D,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AACrC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAElC,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,IAAI,GAAG,IAAI,CA0B5C;AAED,eAAO,MAAM,IAAI,MAAiB,CAAC;AACnC,eAAO,MAAM,QAAQ,MAAkB,CAAC;AAExC,eAAO,MAAO,EAAE,wEAAE,EAAE,wEAAE,KAAK,+DAAE,KAAK,UAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;GAAE,KAAK;;;;;;;;;;;;;GAAE,MAAM;;;;GAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;CAAQ,CAAC;AAE5E,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAC,CAAA;;;;;;;;;;;;;;;;;;;;AAExD,wBAIE"}
@@ -1 +1 @@
1
- {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/cursor.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;;;;;WAWJ,MAAM;;;;;;;iBAkBH,MAAM,KAAK,MAAM,KAAG,MAAM;;;;;;;;;;;CAYpC,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAkCnC,eAAO,MAAM,UAAU,GAAI,iBAAc,KAAG,MAAqC,CAAC"}
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/cursor.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;;;;;WAQJ,MAAM;;;;;;;iBAkBF,MAAM,KAAK,MAAM,KAAG,MAAM;;;;;;;;;;;CAmBrC,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAkCnC,eAAO,MAAM,UAAU,GAAI,iBAAc,KAAG,MAAqC,CAAC"}
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeCursor = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  const cursor = {
6
- up: (0, utils_1.count)("A"),
7
- down: (0, utils_1.count)("B"),
8
- forward: (0, utils_1.count)("C"),
9
- backward: (0, utils_1.count)("D"),
10
- nextLine: (0, utils_1.count)("E"),
11
- prevLine: (0, utils_1.count)("F"),
12
- // Don't use `move`/`count` here, because it will output an empty string if `x` is `0`, but the
13
- // terminal accepts `\x1b[0G` and will process it the same as `\x1b[1G`/`x1b[G`. Also, the
14
- // parameter for `move`/`count` is optional, but the parameter for `x` is required.
15
- x: (x) => (0, utils_1.csi)(x, "G"),
6
+ up: (0, utils_1.count)("A", "B"),
7
+ down: (0, utils_1.count)("B", "A"),
8
+ forward: (0, utils_1.count)("C", "D"),
9
+ backward: (0, utils_1.count)("D", "C"),
10
+ nextLine: (0, utils_1.count)("E", "F"),
11
+ prevLine: (0, utils_1.count)("F", "E"),
12
+ x: (x) => (0, utils_1.csi)(x < 2 ? undefined : x, "G"),
16
13
  // These are the old VT100 codes, but they're widely supported by old and new terminals. The
17
14
  // newer VT220 codes are standardized by ECMA and ISO, and are also widely supported, but might
18
15
  // not work in some older terminals. The VT220 codes are:
@@ -27,7 +24,11 @@ const cursor = {
27
24
  show: (0, utils_1.csi)("?25h"),
28
25
  position: {
29
26
  get: (0, utils_1.csi)("6n"),
30
- set: (x, y) => (0, utils_1.csi)(`${y};${x}H`),
27
+ set: (x, y) => (0, utils_1.csi)(x < 2 ? // Omit x if we can use the default.
28
+ y < 2 ? undefined : y : // Omit y too if we can use both defaults.
29
+ y < 2 ?
30
+ `;${x}` :
31
+ `${y};${x}`, "H"),
31
32
  },
32
33
  shape: {
33
34
  steadyBlock: (0, utils_1.csi)("2 q"),
@@ -1 +1 @@
1
- {"version":3,"file":"cursor.js","sourceRoot":"","sources":["../../src/cursor.ts"],"names":[],"mappings":";;;AAAA,mCAAiD;AAEjD,MAAM,MAAM,GAAG;IACd,EAAE,EAAS,IAAA,aAAI,EAAC,GAAG,CAAC;IACpB,IAAI,EAAO,IAAA,aAAI,EAAC,GAAG,CAAC;IACpB,OAAO,EAAI,IAAA,aAAI,EAAC,GAAG,CAAC;IACpB,QAAQ,EAAG,IAAA,aAAI,EAAC,GAAG,CAAC;IACpB,QAAQ,EAAG,IAAA,aAAI,EAAC,GAAG,CAAC;IACpB,QAAQ,EAAG,IAAA,aAAI,EAAC,GAAG,CAAC;IAEpB,+FAA+F;IAC/F,0FAA0F;IAC1F,mFAAmF;IACnF,CAAC,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAA,WAAG,EAAC,CAAC,EAAE,GAAG,CAAC;IAE7B,4FAA4F;IAC5F,+FAA+F;IAC/F,yDAAyD;IACzD,EAAE;IACF,MAAM;IACN,sBAAsB;IACtB,sBAAsB;IACtB,MAAM;IACN,IAAI,EAAM,OAAO;IACjB,OAAO,EAAG,OAAO;IAEjB,IAAI,EAAG,IAAA,WAAG,EAAC,MAAM,CAAC;IAClB,IAAI,EAAG,IAAA,WAAG,EAAC,MAAM,CAAC;IAElB,QAAQ,EAAE;QACT,GAAG,EAAE,IAAA,WAAG,EAAC,IAAI,CAAC;QACd,GAAG,EAAE,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,IAAA,WAAG,EAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;KACxD;IAED,KAAK,EAAE;QACN,WAAW,EAAS,IAAA,WAAG,EAAC,KAAK,CAAC;QAC9B,SAAS,EAAW,IAAA,WAAG,EAAC,KAAK,CAAC;QAC9B,eAAe,EAAK,IAAA,WAAG,EAAC,KAAK,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,IAAA,WAAG,EAAC,KAAK,CAAC;QAC9B,iBAAiB,EAAG,IAAA,WAAG,EAAC,KAAK,CAAC;QAC9B,OAAO,EAAa,IAAA,WAAG,EAAC,KAAK,CAAC;KAC9B;CACD,CAAC;AAIF,MAAM,QAAQ,GAAW;IACxB,EAAE,EAAS,YAAI;IACf,IAAI,EAAO,YAAI;IACf,OAAO,EAAI,YAAI;IACf,QAAQ,EAAG,YAAI;IACf,QAAQ,EAAG,YAAI;IACf,QAAQ,EAAG,YAAI;IAEf,CAAC,EAAE,YAAI;IAEP,IAAI,EAAM,EAAE;IACZ,OAAO,EAAG,EAAE;IAEZ,IAAI,EAAG,EAAE;IACT,IAAI,EAAG,EAAE;IAET,QAAQ,EAAE;QACT,GAAG,EAAE,EAAE;QACP,GAAG,EAAE,YAAI;KACT;IAED,KAAK,EAAE;QACN,WAAW,EAAS,EAAE;QACtB,SAAS,EAAW,EAAE;QACtB,eAAe,EAAK,EAAE;QACtB,aAAa,EAAO,EAAE;QACtB,WAAW,EAAS,EAAE;QACtB,iBAAiB,EAAG,EAAE;QACtB,OAAO,EAAa,EAAE;KACtB;CACD,CAAC;AAEK,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AAArE,QAAA,UAAU,cAA2D"}
@@ -71,6 +71,7 @@ declare const ansi: typeof $ansi.makeAnsi & import("./sgr").SGR & {
71
71
  scroll: {
72
72
  up: (lines?: number | undefined) => string;
73
73
  down: (lines?: number | undefined) => string;
74
+ setRegion: (top?: number, bottom?: number) => string;
74
75
  };
75
76
  terminal: {
76
77
  focusReporting: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/require.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,QAAQ,CAAC;AAEhC,OAAO,WAAW,IAAI,CAAC;IACtB,KAAY,IAAI,GAAG,OAAO,SAAS,EAAE,IAAI,CAAC;CAC1C;AAID,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAkC,CAAC;AAE7C,SAAS,IAAI,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/require.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,QAAQ,CAAC;AAEhC,OAAO,WAAW,IAAI,CAAC;IACtB,KAAY,IAAI,GAAG,OAAO,SAAS,EAAE,IAAI,CAAC;CAC1C;AAID,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAkC,CAAC;AAE7C,SAAS,IAAI,CAAC"}
@@ -17,12 +17,12 @@ const erase = {
17
17
  },
18
18
  };
19
19
  const insert = {
20
- char: (0, utils_1.count)("@"),
21
- line: (0, utils_1.count)("L"),
20
+ char: (0, utils_1.count)("@", "P"),
21
+ line: (0, utils_1.count)("L", "M"),
22
22
  };
23
23
  const del = {
24
- char: (0, utils_1.count)("P"),
25
- line: (0, utils_1.count)("M"),
24
+ char: (0, utils_1.count)("P", "@"),
25
+ line: (0, utils_1.count)("M", "L"),
26
26
  };
27
27
  const disabledErase = {
28
28
  char: utils_1.noop,
@@ -1 +1 @@
1
- {"version":3,"file":"ins-del.js","sourceRoot":"","sources":["../../src/ins-del.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AAEzC,MAAM,KAAK,GAAG;IACb,IAAI,EAAE,IAAA,aAAK,EAAC,GAAG,CAAC;IAEhB,IAAI,EAAE;QACL,OAAO,EAAG,IAAA,WAAG,EAAC,IAAI,CAAC;QACnB,KAAK,EAAK,IAAA,WAAG,EAAC,IAAI,CAAC;QACnB,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IAAI,EAAS,EAAE;QACf,UAAU,EAAG,EAAE;KACf;CACD,CAAC;AAEF,MAAM,cAAc,GAAW;IAC9B,IAAI,EAAE,YAAI;IACV,IAAI,EAAE,YAAI;CACV,CAAC;AAEF,MAAM,cAAc,GAAW,cAAc,CAAC;AAEvC,MAAM,SAAS,GAAI,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,CAAC,aAAa,CAAC;AAA1E,QAAA,SAAS,aAAiE;AAChF,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC;AAA3E,QAAA,UAAU,cAAiE;AACjF,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAI,CAAC,CAAC,cAAc,CAAC;AAA3E,QAAA,UAAU,cAAiE"}
@@ -1,6 +1,7 @@
1
1
  declare const scroll: {
2
2
  up: (lines?: number | undefined) => string;
3
3
  down: (lines?: number | undefined) => string;
4
+ setRegion: (top?: number, bottom?: number) => string;
4
5
  };
5
6
  export type Scroll = typeof scroll;
6
7
  export declare const makeScroll: (enabled?: boolean) => Scroll;
@@ -1 +1 @@
1
- {"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../src/scroll.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;CAGX,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAOnC,eAAO,MAAM,UAAU,GAAI,iBAAc,KAAG,MAAqC,CAAC"}
1
+ {"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../src/scroll.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;sBAGQ,MAAM,WAAW,MAAM;CAS1C,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAQnC,eAAO,MAAM,UAAU,GAAI,iBAAc,KAAG,MAAqC,CAAC"}
@@ -3,12 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeScroll = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  const scroll = {
6
- up: (0, utils_1.count)("S"),
7
- down: (0, utils_1.count)("T"),
6
+ up: (0, utils_1.count)("S", "T"),
7
+ down: (0, utils_1.count)("T", "S"),
8
+ setRegion: (top, bottom) => (0, utils_1.csi)(!top || top < 2 ? // Omit top if we can use the default.
9
+ bottom :
10
+ !bottom ?
11
+ top :
12
+ `${top};${bottom}`, "r"),
8
13
  };
9
14
  const disabled = {
10
15
  up: utils_1.noop,
11
16
  down: utils_1.noop,
17
+ setRegion: utils_1.noop,
12
18
  };
13
19
  const makeScroll = (enabled = true) => enabled ? scroll : disabled;
14
20
  exports.makeScroll = makeScroll;
@@ -1 +1 @@
1
- {"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../src/scroll.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC,MAAM,MAAM,GAAG;IACd,EAAE,EAAK,IAAA,aAAK,EAAmB,GAAG,CAAC;IACnC,IAAI,EAAG,IAAA,aAAK,EAAmB,GAAG,CAAC;CACnC,CAAC;AAIF,MAAM,QAAQ,GAAW;IACxB,EAAE,EAAK,YAAI;IACX,IAAI,EAAG,YAAI;CACX,CAAC;AAEK,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AAArE,QAAA,UAAU,cAA2D"}
1
+ {"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../src/scroll.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AAEzC,MAAM,MAAM,GAAG;IACd,EAAE,EAAU,IAAA,aAAK,EAAmB,GAAG,EAAE,GAAG,CAAC;IAC7C,IAAI,EAAQ,IAAA,aAAK,EAAmB,GAAG,EAAE,GAAG,CAAC;IAC7C,SAAS,EAAG,CAAC,GAAY,EAAE,MAAe,EAAE,EAAE,CAC7C,IAAA,WAAG,EACF,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,sCAAsC;QACvD,MAAM,CAAC,CAAC;QACT,CAAC,MAAM,CAAC,CAAC;YACR,GAAG,CAAC,CAAC;YACN,GAAG,GAAG,IAAI,MAAM,EAAE,EAClB,GAAG,CACH;CACF,CAAC;AAIF,MAAM,QAAQ,GAAW;IACxB,EAAE,EAAU,YAAI;IAChB,IAAI,EAAQ,YAAI;IAChB,SAAS,EAAG,YAAI;CAChB,CAAC;AAEK,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AAArE,QAAA,UAAU,cAA2D"}
@@ -1,5 +1,5 @@
1
1
  export declare function csi(command: string): string;
2
2
  export declare function csi(params: string | number | undefined, command: string): string;
3
- export declare const count: <Param extends [number?] = [count?: number]>(code: string) => (...args: Param) => string;
3
+ export declare const count: <Param extends [number?] = [count?: number]>(code: string, negativeCode?: string) => (...args: Param) => string;
4
4
  export declare const noop: () => string;
5
5
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AAC7C,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AAQlF,eAAO,MAAM,KAAK,GAAI,KAAK,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAC/D,MAAM,MAAM,KACV,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MACmE,CAAC;AAE3F,eAAO,MAAM,IAAI,cAAW,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AAC7C,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AAyBlF,eAAO,MAAM,KAAK,GAAI,KAAK,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAC/D,MAAgB,MAAM,EACtB,eAAgB,MAAM,KACpB,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MACqD,CAAC;AAE7E,eAAO,MAAM,IAAI,cAAW,CAAC"}
package/dist/cjs/utils.js CHANGED
@@ -7,7 +7,19 @@ function csi(...args) {
7
7
  const params = args.pop();
8
8
  return `\x1b[${params === undefined ? "" : params}${command}`;
9
9
  }
10
- const count = (code) => (count) => count === 0 ? "" : csi(count === 1 ? undefined : count, code);
10
+ const forwardOnlyCount = (code) => (count) => {
11
+ if (count === 0 || count < 0)
12
+ return "";
13
+ return csi(count === 1 ? undefined : count, code);
14
+ };
15
+ const reversibleCount = (forwardCode, backwardCode) => (count) => {
16
+ if (count === 0)
17
+ return "";
18
+ if (!count || count > 0)
19
+ return csi(count === 1 ? undefined : count, forwardCode);
20
+ return csi(count === -1 ? undefined : -count, backwardCode);
21
+ };
22
+ const count = (code, negativeCode) => negativeCode ? reversibleCount(code, negativeCode) : forwardOnlyCount(code);
11
23
  exports.count = count;
12
24
  const noop = () => "";
13
25
  exports.noop = noop;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAEA,kBAKC;AALD,SAAgB,GAAG,CAAC,GAAG,IAAsD;IAC5E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,MAAM,eAAe,GAAG,CAAC,WAAmB,EAAE,YAAoB,EAAE,EAAE,CAAC,CAAC,KAAc,EAAU,EAAE;IACjG,IAAI,KAAK,KAAK,CAAC;QACd,OAAO,EAAE,CAAC;IAEX,IAAI,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC;QACtB,OAAO,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAE1D,OAAO,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAC7D,CAAC,CAAA;AAEM,MAAM,KAAK,GAAG,CACpB,IAAsB,EACtB,YAAsB,EACO,EAAE,CAC/B,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAJhE,QAAA,KAAK,SAI2D;AAEtE,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC;AAAhB,QAAA,IAAI,QAAY"}
@@ -47,6 +47,7 @@ export declare const fg: import("./sgr/types.js").Channel<"bg" | import("./sgr/t
47
47
  }, scroll: {
48
48
  up: (lines?: number | undefined) => string;
49
49
  down: (lines?: number | undefined) => string;
50
+ setRegion: (top?: number, bottom?: number) => string;
50
51
  }, terminal: {
51
52
  focusReporting: {
52
53
  enable: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../../src/ansi.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAuB,OAAO,CAAC;AAKxD,OAAO,EAAC,OAAO,EAAC,MAAgC,YAAY,CAAC;AAC7D,OAAO,EAAW,KAAK,EAAE,aAAa,EAAC,MAAS,SAAS,CAAC;AAG1D,OAAO,KAAK,EAAC,IA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;;;CAAQ,CAAC;AAE5E,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAC,CAAA;;;;;;;;;;;;;;;;;;;;AAExD,wBAIE"}
@@ -1 +1 @@
1
- {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/cursor.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;;;;;WAWJ,MAAM;;;;;;;iBAkBH,MAAM,KAAK,MAAM,KAAG,MAAM;;;;;;;;;;;CAYpC,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAkCnC,eAAO,MAAM,UAAU,GAAI,iBAAc,KAAG,MAAqC,CAAC"}
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/cursor.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;;;;;WAQJ,MAAM;;;;;;;iBAkBF,MAAM,KAAK,MAAM,KAAG,MAAM;;;;;;;;;;;CAmBrC,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAkCnC,eAAO,MAAM,UAAU,GAAI,iBAAc,KAAG,MAAqC,CAAC"}
@@ -1,15 +1,12 @@
1
1
  import { csi, count as move, noop } from "./utils.js";
2
2
  const cursor = {
3
- up: move("A"),
4
- down: move("B"),
5
- forward: move("C"),
6
- backward: move("D"),
7
- nextLine: move("E"),
8
- prevLine: move("F"),
9
- // Don't use `move`/`count` here, because it will output an empty string if `x` is `0`, but the
10
- // terminal accepts `\x1b[0G` and will process it the same as `\x1b[1G`/`x1b[G`. Also, the
11
- // parameter for `move`/`count` is optional, but the parameter for `x` is required.
12
- x: (x) => csi(x, "G"),
3
+ up: move("A", "B"),
4
+ down: move("B", "A"),
5
+ forward: move("C", "D"),
6
+ backward: move("D", "C"),
7
+ nextLine: move("E", "F"),
8
+ prevLine: move("F", "E"),
9
+ x: (x) => csi(x < 2 ? undefined : x, "G"),
13
10
  // These are the old VT100 codes, but they're widely supported by old and new terminals. The
14
11
  // newer VT220 codes are standardized by ECMA and ISO, and are also widely supported, but might
15
12
  // not work in some older terminals. The VT220 codes are:
@@ -24,7 +21,11 @@ const cursor = {
24
21
  show: csi("?25h"),
25
22
  position: {
26
23
  get: csi("6n"),
27
- set: (x, y) => csi(`${y};${x}H`),
24
+ set: (x, y) => csi(x < 2 ? // Omit x if we can use the default.
25
+ y < 2 ? undefined : y : // Omit y too if we can use both defaults.
26
+ y < 2 ?
27
+ `;${x}` :
28
+ `${y};${x}`, "H"),
28
29
  },
29
30
  shape: {
30
31
  steadyBlock: csi("2 q"),
@@ -1 +1 @@
1
- {"version":3,"file":"cursor.js","sourceRoot":"","sources":["../../src/cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,KAAK,IAAI,IAAI,EAAE,IAAI,EAAC,MAAM,SAAS,CAAC;AAEjD,MAAM,MAAM,GAAG;IACd,EAAE,EAAS,IAAI,CAAC,GAAG,CAAC;IACpB,IAAI,EAAO,IAAI,CAAC,GAAG,CAAC;IACpB,OAAO,EAAI,IAAI,CAAC,GAAG,CAAC;IACpB,QAAQ,EAAG,IAAI,CAAC,GAAG,CAAC;IACpB,QAAQ,EAAG,IAAI,CAAC,GAAG,CAAC;IACpB,QAAQ,EAAG,IAAI,CAAC,GAAG,CAAC;IAEpB,+FAA+F;IAC/F,0FAA0F;IAC1F,mFAAmF;IACnF,CAAC,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IAE7B,4FAA4F;IAC5F,+FAA+F;IAC/F,yDAAyD;IACzD,EAAE;IACF,MAAM;IACN,sBAAsB;IACtB,sBAAsB;IACtB,MAAM;IACN,IAAI,EAAM,OAAO;IACjB,OAAO,EAAG,OAAO;IAEjB,IAAI,EAAG,GAAG,CAAC,MAAM,CAAC;IAClB,IAAI,EAAG,GAAG,CAAC,MAAM,CAAC;IAElB,QAAQ,EAAE;QAC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AE,EACX,GAAG,CACH;KACD;IAED,KAAK,EAAE;QACN,WAAW,EAAS,GAAG,CAAC,KAAK,CAAC;QAC9B,SAAS,EAAW,GAAG,CAAC,KAAK,CAAC;QAC9B,eAAe,EAAK,GAAG,CAAC,KAAK,CAAC;QAC9B,aAAa,EAAO,GAAG,CAAC,KAAK,CAAC;QAC9B,WAAW,EAAS,GAAG,CAAC,KAAK,CAAC;QAC9B,iBAAiB,EAAG,GAAG,CAAC,KAAK,CAAC;QAC9B,OAAO,EAAa,GAAG,CAAC,KAAK,CAAC;KAC9B;CACD,CAAC;AAIF,MAAM,QAAQ,GAAW;IACxB,EAAE,EAAS,IAAI;IACf,IAAI,EAAO,IAAI;IACf,OAAO,EAAI,IAAI;IACf,QAAQ,EAAG,IAAI;IACf,QAAQ,EAAG,IAAI;IACf,QAAQ,EAAG,IAAI;IAEf,CAAC,EAAE,IAAI;IAEP,IAAI,EAAM,EAAE;IACZ,OAAO,EAAG,EAAE;IAEZ,IAAI,EAAG,EAAE;IACT,IAAI,EAAG,EAAE;IAET,QAAQ,EAAE;QACT,GAAG,EAAE,EAAE;QACP,GAAG,EAAE,IAAI;KACT;IAED,KAAK,EAAE;QACN,WAAW,EAAS,EAAE;QACtB,SAAS,EAAW,EAAE;QACtB,eAAe,EAAK,EAAE;QACtB,aAAa,EAAO,EAAE;QACtB,WAAW,EAAS,EAAE;QACtB,iBAAiB,EAAG,EAAE;QACtB,OAAO,EAAa,EAAE;KACtB;CACD,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC"}
@@ -14,12 +14,12 @@ const erase = {
14
14
  },
15
15
  };
16
16
  const insert = {
17
- char: count("@"),
18
- line: count("L"),
17
+ char: count("@", "P"),
18
+ line: count("L", "M"),
19
19
  };
20
20
  const del = {
21
- char: count("P"),
22
- line: count("M"),
21
+ char: count("P", "@"),
22
+ line: count("M", "L"),
23
23
  };
24
24
  const disabledErase = {
25
25
  char: noop,
@@ -1 +1 @@
1
- {"version":3,"file":"ins-del.js","sourceRoot":"","sources":["../../src/ins-del.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAC,MAAM,SAAS,CAAC;AAEzC,MAAM,KAAK,GAAG;IACb,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAEhB,IAAI,EAAE;QACL,OAAO,EAAG,GAAG,CAAC,IAAI,CAAC;QACnB,KAAK,EAAK,GAAG,CAAC,IAAI,CAAC;QACnB,IAAI,EAAM,GAAG,CAAC,IAAI,CAAC;KACnB;IACD,MAAM,EAAE;QACP,OAAO,EAAM,GAAG,CAAC,IAAI,CAAC;QACtB,KAAK,EAAQ,GAAG,CAAC,IAAI,CAAC;QACtB,IAAI,EAAS,GAAG,CAAC,IAAI,CAAC;QACtB,UAAU,EAAG,GAAG,CAAC,IAAI,CAAC;KACtB;CACD,CAAC;AAEF,MAAM,MAAM,GAAG;IACd,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;CAChB,CAAC;AAEF,MAAM,GAAG,GAAG;IACX,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;CAChB,CAAC;AAMF,MAAM,aAAa,GAAU;IAC5B,IAAI,EAAE,IAAI;IAEV,IAAI,EAAE;QACL,OAAO,EAAG,EAAE;QACZ,KAAK,EAAK,EAAE;QACZ,IAAI,EAAM,EAAE;KACZ;IACD,MAAM,EAAE;QACP,OAAO,EAAM,EAAE;QACf,KAAK,EAAQ,EAAE;QACf,IAAI,EAAS,EAAE;QACf,UAAU,EAAG,EAAE;KACf;CACD,CAAC;AAEF,MAAM,cAAc,GAAW;IAC9B,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;CACV,C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G,CAAC;IACrB,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC;CACrB,CAAC;AAMF,MAAM,aAAa,GAAU;IAC5B,IAAI,EAAE,IAAI;IAEV,IAAI,EAAE;QACL,OAAO,EAAG,EAAE;QACZ,KAAK,EAAK,EAAE;QACZ,IAAI,EAAM,EAAE;KACZ;IACD,MAAM,EAAE;QACP,OAAO,EAAM,EAAE;QACf,KAAK,EAAQ,EAAE;QACf,IAAI,EAAS,EAAE;QACf,UAAU,EAAG,EAAE;KACf;CACD,CAAC;AAEF,MAAM,cAAc,GAAW;IAC9B,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;CACV,CAAC;AAEF,MAAM,cAAc,GAAW,cAAc,CAAC;AAE9C,MAAM,CAAC,MAAM,SAAS,GAAI,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,CAAC,aAAa,CAAC;AACvF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC;AACxF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAI,CAAC,CAAC,cAAc,CAAC"}
@@ -1,6 +1,7 @@
1
1
  declare const scroll: {
2
2
  up: (lines?: number | undefined) => string;
3
3
  down: (lines?: number | undefined) => string;
4
+ setRegion: (top?: number, bottom?: number) => string;
4
5
  };
5
6
  export type Scroll = typeof scroll;
6
7
  export declare const makeScroll: (enabled?: boolean) => Scroll;
@@ -1 +1 @@
1
- {"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../src/scroll.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;CAGX,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAOnC,eAAO,MAAM,UAAU,GAAI,iBAAc,KAAG,MAAqC,CAAC"}
1
+ {"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../src/scroll.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;sBAGQ,MAAM,WAAW,MAAM;CAS1C,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAQnC,eAAO,MAAM,UAAU,GAAI,iBAAc,KAAG,MAAqC,CAAC"}
@@ -1,11 +1,17 @@
1
- import { count, noop } from "./utils.js";
1
+ import { csi, count, noop } from "./utils.js";
2
2
  const scroll = {
3
- up: count("S"),
4
- down: count("T"),
3
+ up: count("S", "T"),
4
+ down: count("T", "S"),
5
+ setRegion: (top, bottom) => csi(!top || top < 2 ? // Omit top if we can use the default.
6
+ bottom :
7
+ !bottom ?
8
+ top :
9
+ `${top};${bottom}`, "r"),
5
10
  };
6
11
  const disabled = {
7
12
  up: noop,
8
13
  down: noop,
14
+ setRegion: noop,
9
15
  };
10
16
  export const makeScroll = (enabled = true) => enabled ? scroll : disabled;
11
17
  //# sourceMappingURL=scroll.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../src/scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,SAAS,CAAC;AAEpC,MAAM,MAAM,GAAG;IACd,EAAE,EAAK,KAAK,CAAmB,GAAG,CAAC;IACnC,IAAI,EAAG,KAAK,CAAmB,GAAG,CAAC;CACnC,CAAC;AAIF,MAAM,QAAQ,GAAW;IACxB,EAAE,EAAK,IAAI;IACX,IAAI,EAAG,IAAI;CACX,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC"}
1
+ {"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../src/scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAC,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,GAAG;IACd,EAAE,EAAU,KAAK,CAAmB,GAAG,EAAE,GAAG,CAAC;IAC7C,IAAI,EAAQ,KAAK,CAAmB,GAAG,EAAE,GAAG,CAAC;IAC7C,SAAS,EAAG,CAAC,GAAY,EAAE,MAAe,EAAE,EAAE,CAC7C,GAAG,CACF,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,sCAAsC;QACvD,MAAM,CAAC,CAAC;QACT,CAAC,MAAM,CAAC,CAAC;YACR,GAAG,CAAC,CAAC;YACN,GAAG,GAAG,IAAI,MAAM,EAAE,EAClB,GAAG,CACH;CACF,CAAC;AAIF,MAAM,QAAQ,GAAW;IACxB,EAAE,EAAU,IAAI;IAChB,IAAI,EAAQ,IAAI;IAChB,SAAS,EAAG,IAAI;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,IAAI,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export declare function csi(command: string): string;
2
2
  export declare function csi(params: string | number | undefined, command: string): string;
3
- export declare const count: <Param extends [number?] = [count?: number]>(code: string) => (...args: Param) => string;
3
+ export declare const count: <Param extends [number?] = [count?: number]>(code: string, negativeCode?: string) => (...args: Param) => string;
4
4
  export declare const noop: () => string;
5
5
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AAC7C,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AAQlF,eAAO,MAAM,KAAK,GAAI,KAAK,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAC/D,MAAM,MAAM,KACV,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MACmE,CAAC;AAE3F,eAAO,MAAM,IAAI,cAAW,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AAC7C,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AAyBlF,eAAO,MAAM,KAAK,GAAI,KAAK,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAC/D,MAAgB,MAAM,EACtB,eAAgB,MAAM,KACpB,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MACqD,CAAC;AAE7E,eAAO,MAAM,IAAI,cAAW,CAAC"}
package/dist/esm/utils.js CHANGED
@@ -3,6 +3,18 @@ export function csi(...args) {
3
3
  const params = args.pop();
4
4
  return `\x1b[${params === undefined ? "" : params}${command}`;
5
5
  }
6
- export const count = (code) => (count) => count === 0 ? "" : csi(count === 1 ? undefined : count, code);
6
+ const forwardOnlyCount = (code) => (count) => {
7
+ if (count === 0 || count < 0)
8
+ return "";
9
+ return csi(count === 1 ? undefined : count, code);
10
+ };
11
+ const reversibleCount = (forwardCode, backwardCode) => (count) => {
12
+ if (count === 0)
13
+ return "";
14
+ if (!count || count > 0)
15
+ return csi(count === 1 ? undefined : count, forwardCode);
16
+ return csi(count === -1 ? undefined : -count, backwardCode);
17
+ };
18
+ export const count = (code, negativeCode) => negativeCode ? reversibleCount(code, negativeCode) : forwardOnlyCount(code);
7
19
  export const noop = () => "";
8
20
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,CAAC,GAAG,IAAsD;IAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAY,CAAC;IACrC,MAAM,MAAM,GAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAE3B,OAAO,QAAQ,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC;AAC/D,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,CACpB,IAAY,EACiB,EAAE,CAC/B,CAAC,KAAc,EAAU,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAE3F,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,CAAC,GAAG,IAAsD;IAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAY,CAAC;IACrC,MAAM,MAAM,GAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAE3B,OAAO,QAAQ,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC;AAC/D,CAAC;AAED,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,KAAc,EAAU,EAAE;IACrE,IAAI,KAAK,KAAK,CAAC,IAAI,KAAM,GAAG,CAAC;QAC5B,OAAO,EAAE,CAAC;IAEX,OAAO,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,WAAmB,EAAE,YAAoB,EAAE,EAAE,CAAC,CAAC,KAAc,EAAU,EAAE;IACjG,IAAI,KAAK,KAAK,CAAC;QACd,OAAO,EAAE,CAAC;IAEX,IAAI,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC;QACtB,OAAO,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAE1D,OAAO,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAC7D,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,CACpB,IAAsB,EACtB,YAAsB,EACO,EAAE,CAC/B,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name" : "@peteanderson/ansi",
3
- "version" : "3.5.0",
3
+ "version" : "3.7.0",
4
4
  "description" : "ANSI escape sequence generation with automatic feature detection",
5
5
  "author" : {
6
6
  "name" : "Pete Anderson",
package/src/cursor.ts CHANGED
@@ -1,17 +1,14 @@
1
1
  import {csi, count as move, noop} from "./utils";
2
2
 
3
3
  const cursor = {
4
- up : move("A"),
5
- down : move("B"),
6
- forward : move("C"),
7
- backward : move("D"),
8
- nextLine : move("E"),
9
- prevLine : move("F"),
4
+ up : move("A", "B"),
5
+ down : move("B", "A"),
6
+ forward : move("C", "D"),
7
+ backward : move("D", "C"),
8
+ nextLine : move("E", "F"),
9
+ prevLine : move("F", "E"),
10
10
 
11
- // Don't use `move`/`count` here, because it will output an empty string if `x` is `0`, but the
12
- // terminal accepts `\x1b[0G` and will process it the same as `\x1b[1G`/`x1b[G`. Also, the
13
- // parameter for `move`/`count` is optional, but the parameter for `x` is required.
14
- x: (x: number) => csi(x, "G"),
11
+ x: (x: number) => csi(x < 2 ? undefined : x, "G"),
15
12
 
16
13
  // These are the old VT100 codes, but they're widely supported by old and new terminals. The
17
14
  // newer VT220 codes are standardized by ECMA and ISO, and are also widely supported, but might
@@ -29,7 +26,14 @@ const cursor = {
29
26
 
30
27
  position: {
31
28
  get: csi("6n"),
32
- set: (x: number, y: number): string => csi(`${y};${x}H`),
29
+ set : (x: number, y: number): string => csi(
30
+ x < 2 ? // Omit x if we can use the default.
31
+ y < 2 ? undefined : y : // Omit y too if we can use both defaults.
32
+ y < 2 ?
33
+ `;${x}` :
34
+ `${y};${x}`,
35
+ "H", // "f" is equivalent, but "H" is more widely supported
36
+ ),
33
37
  },
34
38
 
35
39
  shape: {
package/src/ins-del.ts CHANGED
@@ -17,13 +17,13 @@ const erase = {
17
17
  };
18
18
 
19
19
  const insert = {
20
- char: count("@"),
21
- line: count("L"),
20
+ char: count("@", "P"),
21
+ line: count("L", "M"),
22
22
  };
23
23
 
24
24
  const del = {
25
- char: count("P"),
26
- line: count("M"),
25
+ char: count("P", "@"),
26
+ line: count("M", "L"),
27
27
  };
28
28
 
29
29
  export type Erase = typeof erase;
package/src/scroll.ts CHANGED
@@ -1,15 +1,25 @@
1
- import {count, noop} from "./utils";
1
+ import {csi, count, noop} from "./utils";
2
2
 
3
3
  const scroll = {
4
- up : count<[lines?: number]>("S"),
5
- down : count<[lines?: number]>("T"),
4
+ up : count<[lines?: number]>("S", "T"),
5
+ down : count<[lines?: number]>("T", "S"),
6
+ setRegion : (top?: number, bottom?: number) =>
7
+ csi(
8
+ !top || top < 2 ? // Omit top if we can use the default.
9
+ bottom :
10
+ !bottom ?
11
+ top :
12
+ `${top};${bottom}`,
13
+ "r",
14
+ ),
6
15
  };
7
16
 
8
17
  export type Scroll = typeof scroll;
9
18
 
10
19
  const disabled: Scroll = {
11
- up : noop,
12
- down : noop,
20
+ up : noop,
21
+ down : noop,
22
+ setRegion : noop,
13
23
  };
14
24
 
15
25
  export const makeScroll = (enabled = true): Scroll => enabled ? scroll : disabled;
package/src/utils.ts CHANGED
@@ -7,9 +7,27 @@ export function csi(...args: [string] | [string | number | undefined, string]):
7
7
  return `\x1b[${params === undefined ? "" : params}${command}`;
8
8
  }
9
9
 
10
+ const forwardOnlyCount = (code: string) => (count?: number): string => {
11
+ if (count === 0 || count! < 0)
12
+ return "";
13
+
14
+ return csi(count === 1 ? undefined : count, code);
15
+ };
16
+
17
+ const reversibleCount = (forwardCode: string, backwardCode: string) => (count?: number): string => {
18
+ if (count === 0)
19
+ return "";
20
+
21
+ if (!count || count > 0)
22
+ return csi(count === 1 ? undefined : count, forwardCode);
23
+
24
+ return csi(count === -1 ? undefined : -count, backwardCode);
25
+ }
26
+
10
27
  export const count = <Param extends [number?] = [count?: number]>(
11
- code: string
28
+ code : string,
29
+ negativeCode? : string,
12
30
  ): (...args: Param) => string =>
13
- (count?: number): string => count === 0 ? "" : csi(count === 1 ? undefined : count, code);
31
+ negativeCode ? reversibleCount(code, negativeCode) : forwardOnlyCount(code);
14
32
 
15
33
  export const noop = () => "";