@visulima/ansi 4.0.0-alpha.1 → 4.0.0-alpha.11

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.
@@ -27,7 +27,7 @@ const formatITerm2FileProperties = (properties) => {
27
27
  options.push(`name=${properties.name}`);
28
28
  }
29
29
  if (properties.size !== void 0) {
30
- options.push(`size=${properties.size}`);
30
+ options.push(`size=${String(properties.size)}`);
31
31
  }
32
32
  if (properties.width !== void 0) {
33
33
  options.push(`width=${properties.width.toString()}`);
@@ -50,7 +50,7 @@ class ITerm2File {
50
50
  fileProps;
51
51
  /**
52
52
  * Constructs an `ITerm2File` payload object.
53
- * @param properties An object containing properties for the file/image, as defined by {@link ITerm2FileProps}.
53
+ * @param properties An object containing properties for the file/image, as defined by {@link ITerm2FileProperties}.
54
54
  * The `name` property within `props` should be pre-Base64 encoded by the caller if it might
55
55
  * contain special characters (like `;`, `=`, or non-ASCII characters).
56
56
  * If `fileData` is provided, `props.content` will be overridden, and `props.size` will be
@@ -66,9 +66,7 @@ class ITerm2File {
66
66
  throw new Error("File size exceeds maximum limit of 10MB");
67
67
  }
68
68
  this.fileProps.content = Buffer.from(fileData).toString("base64");
69
- if (this.fileProps.size === void 0) {
70
- this.fileProps.size = fileData.byteLength;
71
- }
69
+ this.fileProps.size ??= fileData.byteLength;
72
70
  if (this.fileProps.size !== fileData.byteLength) {
73
71
  throw new Error("File size property doesn't match actual data length");
74
72
  }
@@ -107,6 +105,7 @@ class ITerm2FilePart {
107
105
  constructor(base64Chunk) {
108
106
  this.base64Chunk = base64Chunk;
109
107
  }
108
+ base64Chunk;
110
109
  /**
111
110
  * Converts the Base64 encoded chunk into the string payload suitable for the iTerm2 `FilePart=` command.
112
111
  * @returns The string payload (e.g., `"FilePart=U09NRURBVEE="`).
@@ -125,6 +124,7 @@ class ITerm2MultipartFileStart {
125
124
  constructor(properties) {
126
125
  this.properties = properties;
127
126
  }
127
+ properties;
128
128
  /**
129
129
  * Converts the file properties into the string payload suitable for the iTerm2 `MultipartFile=` command.
130
130
  * @returns The string payload (e.g., `"MultipartFile=name=...;size=..."`).
@@ -0,0 +1,72 @@
1
+ import { C as CSI, E as ESC, S as SEP } from './constants-CE7WkXh_.js';
2
+ import './restoreCursor-GfYEeJqN.js';
3
+
4
+ const isBrowser = typeof globalThis !== "undefined" && typeof globalThis.window === "object" && globalThis.window.document !== void 0;
5
+ const OSTYPE_REGEX = /^(?:msys|cygwin)$/;
6
+ const isTerminalApp = !isBrowser && process.env.TERM_PROGRAM === "Apple_Terminal";
7
+ const isWindows = !isBrowser && (process.platform === "win32" || OSTYPE_REGEX.test(process.env.OSTYPE));
8
+
9
+ const SAVE_CURSOR_DEC = `${ESC}7`;
10
+ const RESTORE_CURSOR_DEC = `${ESC}8`;
11
+ const CURSOR_UP_1 = `${CSI}A`;
12
+ const CURSOR_DOWN_1 = `${CSI}B`;
13
+ const CURSOR_FORWARD_1 = `${CSI}C`;
14
+ const CURSOR_BACKWARD_1 = `${CSI}D`;
15
+ const REQUEST_CURSOR_POSITION = `${CSI}6n`;
16
+ const REQUEST_EXTENDED_CURSOR_POSITION = `${CSI}?6n`;
17
+ const cursorBackward = (count = 1) => `${CSI}${String(count)}D`;
18
+ const cursorDown = (count = 1) => `${CSI}${String(count)}B`;
19
+ const cursorForward = (count = 1) => `${CSI}${String(count)}C`;
20
+ const cursorHide = `${CSI}?25l`;
21
+ const cursorToColumn1 = `${CSI}G`;
22
+ const cursorLeft = (count = 1) => cursorBackward(count);
23
+ const cursorHorizontalAbsolute = (column = 1) => `${CSI}${String(column)}G`;
24
+ const cursorMove = (x, y) => {
25
+ let returnValue = "";
26
+ if (x < 0) {
27
+ returnValue += `${CSI}${String(-x)}D`;
28
+ } else if (x > 0) {
29
+ returnValue += `${CSI}${String(x)}C`;
30
+ }
31
+ if (y < 0) {
32
+ returnValue += `${CSI}${String(-y)}A`;
33
+ } else if (y > 0) {
34
+ returnValue += `${CSI}${String(y)}B`;
35
+ }
36
+ return returnValue;
37
+ };
38
+ const cursorNextLine = (count = 1) => `${CSI}${String(count)}E`;
39
+ const cursorPreviousLine = (count = 1) => `${CSI}${String(count)}F`;
40
+ const cursorRestore = isTerminalApp ? RESTORE_CURSOR_DEC : `${ESC}u`;
41
+ const cursorSave = isTerminalApp ? SAVE_CURSOR_DEC : `${ESC}s`;
42
+ const cursorShow = `${CSI}?25h`;
43
+ const cursorTo = (x, y) => {
44
+ if (y === void 0) {
45
+ return cursorHorizontalAbsolute(x + 1);
46
+ }
47
+ return `${CSI}${String(y + 1)}${SEP}${String(x + 1)}H`;
48
+ };
49
+ const cursorPosition = (row, column) => {
50
+ if (column === void 0) {
51
+ return `${CSI}${String(row)}H`;
52
+ }
53
+ return `${CSI}${String(row)}${SEP}${String(column)}H`;
54
+ };
55
+ const cursorHorizontalForwardTab = (count = 1) => `${CSI}${String(count)}I`;
56
+ const cursorBackwardTab = (count = 1) => `${CSI}${String(count)}Z`;
57
+ const eraseCharacter = (count = 1) => `${CSI}${String(count)}X`;
58
+ const cursorVerticalAbsolute = (row = 1) => `${CSI}${String(row)}d`;
59
+ const cursorUp = (count = 1) => `${CSI}${String(count)}A`;
60
+ var CursorStyle = /* @__PURE__ */ ((CursorStyle2) => {
61
+ CursorStyle2[CursorStyle2["Default"] = 0] = "Default";
62
+ CursorStyle2[CursorStyle2["BlinkingBlock"] = 1] = "BlinkingBlock";
63
+ CursorStyle2[CursorStyle2["SteadyBlock"] = 2] = "SteadyBlock";
64
+ CursorStyle2[CursorStyle2["BlinkingUnderline"] = 3] = "BlinkingUnderline";
65
+ CursorStyle2[CursorStyle2["SteadyUnderline"] = 4] = "SteadyUnderline";
66
+ CursorStyle2[CursorStyle2["BlinkingBar"] = 5] = "BlinkingBar";
67
+ CursorStyle2[CursorStyle2["SteadyBar"] = 6] = "SteadyBar";
68
+ return CursorStyle2;
69
+ })(CursorStyle || {});
70
+ const setCursorStyle = (style) => `${CSI}${String(style)} q`;
71
+
72
+ export { isWindows as A, CursorStyle as B, CURSOR_BACKWARD_1 as C, REQUEST_CURSOR_POSITION as R, SAVE_CURSOR_DEC as S, CURSOR_DOWN_1 as a, CURSOR_FORWARD_1 as b, CURSOR_UP_1 as c, REQUEST_EXTENDED_CURSOR_POSITION as d, RESTORE_CURSOR_DEC as e, cursorBackward as f, cursorBackwardTab as g, cursorDown as h, cursorForward as i, cursorHide as j, cursorHorizontalAbsolute as k, cursorHorizontalForwardTab as l, cursorLeft as m, cursorMove as n, cursorNextLine as o, cursorPosition as p, cursorPreviousLine as q, cursorRestore as r, cursorSave as s, cursorShow as t, cursorTo as u, cursorToColumn1 as v, cursorUp as w, cursorVerticalAbsolute as x, eraseCharacter as y, setCursorStyle as z };
@@ -3,16 +3,16 @@ import { O as OSC, B as BEL } from './constants-CE7WkXh_.js';
3
3
  const resetProgressBar = `${OSC}9;4;0${BEL}`;
4
4
  const setProgressBar = (percentage) => {
5
5
  const clamped = Math.min(Math.max(0, percentage), 100);
6
- return `${OSC}9;4;1;${clamped}${BEL}`;
6
+ return `${OSC}9;4;1;${String(clamped)}${BEL}`;
7
7
  };
8
8
  const setErrorProgressBar = (percentage) => {
9
9
  const clamped = Math.min(Math.max(0, percentage), 100);
10
- return `${OSC}9;4;2;${clamped}${BEL}`;
10
+ return `${OSC}9;4;2;${String(clamped)}${BEL}`;
11
11
  };
12
12
  const setIndeterminateProgressBar = `${OSC}9;4;3${BEL}`;
13
13
  const setWarningProgressBar = (percentage) => {
14
14
  const clamped = Math.min(Math.max(0, percentage), 100);
15
- return `${OSC}9;4;4;${clamped}${BEL}`;
15
+ return `${OSC}9;4;4;${String(clamped)}${BEL}`;
16
16
  };
17
17
 
18
18
  export { resetProgressBar, setErrorProgressBar, setIndeterminateProgressBar, setProgressBar, setWarningProgressBar };
package/dist/screen.js CHANGED
@@ -1,27 +1,27 @@
1
1
  import { C as CSI, S as SEP } from './packem_shared/constants-CE7WkXh_.js';
2
2
 
3
- const insertLine = (count = 1) => `${CSI + (count <= 1 ? "" : count)}L`;
4
- const deleteLine = (count = 1) => `${CSI + (count <= 1 ? "" : count)}M`;
3
+ const insertLine = (count = 1) => `${CSI}${count <= 1 ? "" : String(count)}L`;
4
+ const deleteLine = (count = 1) => `${CSI}${count <= 1 ? "" : String(count)}M`;
5
5
  const setTopBottomMargins = (top, bottom) => {
6
6
  const topString = top && top > 0 ? top.toString() : "";
7
7
  const bottomString = bottom && bottom > 0 ? bottom.toString() : "";
8
8
  if (topString === "" && bottomString === "") {
9
- return `${CSI + SEP}r`;
9
+ return `${CSI}${SEP}r`;
10
10
  }
11
- return `${CSI + topString + SEP + bottomString}r`;
11
+ return `${CSI}${topString}${SEP}${bottomString}r`;
12
12
  };
13
13
  const setLeftRightMargins = (left, right) => {
14
14
  const leftString = left && left > 0 ? left.toString() : "";
15
15
  const rightString = right && right > 0 ? right.toString() : "";
16
16
  if (leftString === "" && rightString === "") {
17
- return `${CSI + SEP}s`;
17
+ return `${CSI}${SEP}s`;
18
18
  }
19
- return `${CSI + leftString + SEP + rightString}s`;
19
+ return `${CSI}${leftString}${SEP}${rightString}s`;
20
20
  };
21
- const insertCharacter = (count = 1) => `${CSI + (count <= 1 ? "" : count)}@`;
22
- const deleteCharacter = (count = 1) => `${CSI + (count <= 1 ? "" : count)}P`;
23
- const clearTabStop = (mode = 0) => `${CSI + mode}g`;
24
- const requestPresentationStateReport = (mode) => `${CSI + mode}$u`;
25
- const repeatPreviousCharacter = (count = 1) => `${CSI + (count <= 1 ? "" : count)}b`;
21
+ const insertCharacter = (count = 1) => `${CSI}${count <= 1 ? "" : String(count)}@`;
22
+ const deleteCharacter = (count = 1) => `${CSI}${count <= 1 ? "" : String(count)}P`;
23
+ const clearTabStop = (mode = 0) => `${CSI}${String(mode)}g`;
24
+ const requestPresentationStateReport = (mode) => `${CSI}${String(mode)}$u`;
25
+ const repeatPreviousCharacter = (count = 1) => `${CSI}${count <= 1 ? "" : String(count)}b`;
26
26
 
27
27
  export { clearTabStop, deleteCharacter, deleteLine, insertCharacter, insertLine, repeatPreviousCharacter, requestPresentationStateReport, setLeftRightMargins, setTopBottomMargins };
package/dist/scroll.js CHANGED
@@ -4,13 +4,13 @@ const scrollUp = (count = 1) => {
4
4
  if (count === 0) {
5
5
  return "";
6
6
  }
7
- return `${CSI + (count <= 1 ? "" : count)}S`;
7
+ return `${CSI}${count <= 1 ? "" : String(count)}S`;
8
8
  };
9
9
  const scrollDown = (count = 1) => {
10
10
  if (count === 0) {
11
11
  return "";
12
12
  }
13
- return `${CSI + (count <= 1 ? "" : count)}T`;
13
+ return `${CSI}${count <= 1 ? "" : String(count)}T`;
14
14
  };
15
15
  const SCROLL_UP_1 = `${CSI}S`;
16
16
  const SCROLL_DOWN_1 = `${CSI}T`;
package/dist/status.d.ts CHANGED
@@ -205,8 +205,8 @@ export declare const requestPrimaryDeviceAttributes: string;
205
205
  export declare const DA1: string;
206
206
  /**
207
207
  * Generates the response sequence for Primary Device Attributes (DA1).
208
- * Sequence: `CSI ? Ps ; ... c`
209
- *
208
+ * Sequence: `CSI ? Ps ; ... c`.
209
+ * @remarks
210
210
  * Common attributes include:
211
211
  * - 1 132 columns
212
212
  * - 2 Printer port
@@ -224,7 +224,7 @@ export declare const DA1: string;
224
224
  * - 42 ISO Latin-2 character set
225
225
  * - 44 PCTerm
226
226
  * - 45 Soft key map
227
- * - 46 ASCII emulation
227
+ * - 46 ASCII emulation.
228
228
  * @param attributes Numeric attribute codes.
229
229
  * @returns The DA1 response sequence.
230
230
  * @example
@@ -508,8 +508,9 @@ export declare const RequestLightDarkReport: string;
508
508
  /**
509
509
  * Generates a Light/Dark Color Scheme Report sequence.
510
510
  * This sequence reports the terminal's operating system light/dark color preference.
511
- * - `CSI ? 997 ; 1 n` for dark mode
512
- * - `CSI ? 997 ; 2 n` for light mode
511
+ * @remarks
512
+ * - `CSI ? 997 ; 1 n` for dark mode.
513
+ * - `CSI ? 997 ; 2 n` for light mode.
513
514
  * @param dark Whether the color scheme is dark mode (true) or light mode (false).
514
515
  * @returns The light/dark report sequence string.
515
516
  * @see {@link https://contour-terminal.org/vt-extensions/color-palette-update-notifications/}
package/dist/status.js CHANGED
@@ -1,15 +1,17 @@
1
- import { S as SEP, C as CSI, D as DCS, a as ST } from './packem_shared/constants-CE7WkXh_.js';
1
+ import { C as CSI, S as SEP, D as DCS, a as ST } from './packem_shared/constants-CE7WkXh_.js';
2
2
 
3
3
  class AnsiStatusReportImpl {
4
4
  constructor(reportCode) {
5
5
  this.reportCode = reportCode;
6
6
  }
7
+ reportCode;
7
8
  isDecReport = false;
8
9
  }
9
10
  class DecStatusReportImpl {
10
11
  constructor(reportCode) {
11
12
  this.reportCode = reportCode;
12
13
  }
14
+ reportCode;
13
15
  isDecReport = true;
14
16
  }
15
17
  const createAnsiStatusReport = (code) => new AnsiStatusReportImpl(code);
@@ -18,18 +20,13 @@ const deviceStatusReport = (...reports) => {
18
20
  if (reports.length === 0) {
19
21
  return "";
20
22
  }
21
- let hasDecReport = false;
22
- const reportCodes = reports.map((report) => {
23
- if (report.isDecReport) {
24
- hasDecReport = true;
25
- }
26
- return report.reportCode.toString();
27
- });
23
+ const hasDecReport = reports.some((report) => report.isDecReport);
24
+ const reportCodes = reports.map((report) => report.reportCode.toString());
28
25
  let seq = CSI;
29
26
  if (hasDecReport) {
30
27
  seq += "?";
31
28
  }
32
- return `${seq + reportCodes.join(SEP)}n`;
29
+ return `${seq}${reportCodes.join(SEP)}n`;
33
30
  };
34
31
  const DSR = (report) => deviceStatusReport(report);
35
32
  const requestCursorPositionReport = `${CSI}6n`;
@@ -37,7 +34,7 @@ const requestExtendedCursorPositionReport = `${CSI}?6n`;
37
34
  const cursorPositionReport = (line, column) => {
38
35
  const r = Math.max(1, line);
39
36
  const c = Math.max(1, column);
40
- return `${CSI + r.toString() + SEP + c.toString()}R`;
37
+ return `${CSI}${r.toString()}${SEP}${c.toString()}R`;
41
38
  };
42
39
  const CPR = cursorPositionReport;
43
40
  const extendedCursorPositionReport = (line, column, page) => {
@@ -68,7 +65,7 @@ const reportSecondaryDeviceAttributes = (version, level, cartridge = 0) => {
68
65
  const pv = Math.max(0, version);
69
66
  const pl = Math.max(0, level);
70
67
  const pc = Math.max(0, cartridge);
71
- return `${CSI}>${pv}${SEP}${pl}${SEP}${pc}c`;
68
+ return `${CSI}>${String(pv)}${SEP}${String(pl)}${SEP}${String(pc)}c`;
72
69
  };
73
70
  const requestTertiaryDeviceAttributes = `${CSI}=c`;
74
71
  const DA3 = requestTertiaryDeviceAttributes;
package/dist/strip.d.ts CHANGED
@@ -1,23 +1,2 @@
1
- /**
2
- * Removes ANSI escape codes from a string.
3
- *
4
- * This function first removes OSC (Operating System Command) sequences like title strings
5
- * (e.g., `\u001B]0;title\u0007`) and then uses a comprehensive regex (from the `ansi-regex` package)
6
- * to strip all other ANSI escape codes.
7
- * @param input The string from which to remove ANSI escape codes.
8
- * @returns The input string with all ANSI escape codes stripped.
9
- * @example
10
- * ```typescript
11
- * import { strip } from "@visulima/ansi";
12
- *
13
- * const textWithAnsi = "\x1b[32mHello, \x1b[1mWorld!\x1b[0m";
14
- * const strippedText = strip(textWithAnsi);
15
- * console.log(strippedText); // Output: "Hello, World!"
16
- *
17
- * const titleSequence = "\u001B]0;My Window Title\u0007Some content";
18
- * const strippedTitle = strip(titleSequence);
19
- * console.log(strippedTitle); // Output: "Some content"
20
- * ```
21
- */
22
1
  declare const strip: (input: string) => string;
23
2
  export default strip;
package/dist/strip.js CHANGED
@@ -7,6 +7,7 @@ function ansiRegex({ onlyFirst = false } = {}) {
7
7
  }
8
8
 
9
9
  const regex = ansiRegex();
10
- const strip = (input) => input.replace(/\u001B\]0;.*\u0007/, "").replace(regex, "");
10
+ const OSC_TITLE_REGEX = /\u001B\]0;.*\u0007/;
11
+ const strip = (input) => input.replace(OSC_TITLE_REGEX, "").replace(regex, "");
11
12
 
12
13
  export { strip as default };
package/dist/termcap.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Requests Termcap/Terminfo (XTGETTCAP) strings from the terminal.
3
- * Sequence: DCS + q &lt;Pt> ST
3
+ * Sequence: `DCS + q Pt ST`.
4
4
  * @param caps A list of termcap/terminfo capability names (e.g., "Co", "li", "cols").
5
5
  * @returns The XTGETTCAP sequence string.
6
6
  * @see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Device-Control-Strings-plus-q
package/dist/title.d.ts CHANGED
@@ -64,59 +64,57 @@ export declare const setIconName: (iconName: string) => string;
64
64
  export declare const setWindowTitle: (title: string) => string;
65
65
  /**
66
66
  * Sets a DEC Special Window Title (DECSWT) using an OSC sequence.
67
- * The original Go library implemented this by prepending "1;" to the title and using `setWindowTitle`,
68
- * resulting in an `OSC 2 ; 1;&lt;title&gt; BEL` sequence.
69
- * This differs from some interpretations where DECSWT might use `OSC 1`.
70
- * This implementation replicates the Go library's specific behavior.
71
- *
72
- * Note: DECSWT (`OSC 2;1;...BEL`) was introduced in the DEC VT520/VT525 family
73
- * and is ignored by earlier DEC terminals. Support varies across modern emulators;
74
- * for example, Zutty 0.6+ claims VT520 compatibility, but many others that handle
75
- * common OSC sequences may drop or ignore DECSWT.
76
- * If relying on this sequence, testing on actual VT520 hardware or emulators
77
- * with known VT520 support is recommended. Unsupported sequences are typically
78
- * silently ignored by most terminals.
79
- *
80
- * Uses the sequence: `OSC 2 ; 1;&lt;title&gt; BEL` (based on Go library's behavior)
67
+ *
68
+ * DECSWT was introduced in the DEC VT520/VT525 family and uses the dedicated
69
+ * OSC code `21` (not to be confused with OSC 2 for standard window titles).
70
+ * It is terminated with ST (String Terminator) per the VT520 specification.
71
+ *
72
+ * Uses the sequence: `OSC 21 ; title ST`
73
+ * - `OSC`: Operating System Command (`\x1b]`).
74
+ * - `21`: Parameter for DEC Special Window Title.
75
+ * - `title`: The string to set.
76
+ * - `ST`: String Terminator (`\x1b\\`).
77
+ *
78
+ * Support varies across modern emulators; Zutty 0.6+ claims VT520 compatibility,
79
+ * and Microsoft's Windows Terminal also supports this sequence.
80
+ * Unsupported sequences are typically silently ignored by most terminals.
81
81
  * @param title The title string.
82
- * @returns The ANSI escape sequence for DECSWT (as implemented).
82
+ * @returns The ANSI escape sequence for DECSWT.
83
83
  * @see EK-VT520-RM 5–134 (VT520 Programmer Reference Manual)
84
- * @see setWindowTitle
85
84
  * @example
86
85
  * ```typescript
87
86
  * import { decswt } from "@visulima/ansi";
88
87
  *
89
88
  * process.stdout.write(decswt("My Special Window"));
90
- * // Sends: "\\x1b]2;1;My Special Window\\x07"
89
+ * // Sends: "\x1b]21;My Special Window\x1b\\"
91
90
  * ```
92
91
  */
93
92
  export declare const decswt: (title: string) => string;
94
93
  /**
95
94
  * Sets a DEC Special Icon Name (DECSIN) using an OSC sequence.
96
- * The original Go library implemented this by prepending "L;" to the name and using `setWindowTitle`,
97
- * resulting in an `OSC 2 ; L;&lt;name&gt; BEL` sequence.
98
- * This differs from some interpretations where DECSIN might use `OSC L` or `OSC 1`.
99
- * This implementation replicates the Go library's specific behavior.
100
- *
101
- * Note: DECSIN (`OSC 2;L;...BEL`) was introduced in the DEC VT520/VT525 family
102
- * and is ignored by earlier DEC terminals. Support varies across modern emulators;
103
- * for example, Zutty 0.6+ claims VT520 compatibility, but many others that handle
104
- * common OSC sequences may drop or ignore DECSIN.
105
- * If relying on this sequence, testing on actual VT520 hardware or emulators
106
- * with known VT520 support is recommended. Unsupported sequences are typically
107
- * silently ignored by most terminals.
108
- *
109
- * Uses the sequence: `OSC 2 ; L;&lt;name&gt; BEL` (based on Go library's behavior)
95
+ *
96
+ * DECSIN was introduced in the DEC VT520/VT525 family and uses the dedicated
97
+ * OSC code `2L` (not to be confused with OSC 1 for standard icon names).
98
+ * It is terminated with ST (String Terminator) per the VT520 specification.
99
+ *
100
+ * Uses the sequence: `OSC 2L ; name ST`
101
+ * - `OSC`: Operating System Command (`\x1b]`).
102
+ * - `2L`: Parameter for DEC Special Icon Name.
103
+ * - `name`: The string to set.
104
+ * - `ST`: String Terminator (`\x1b\\`).
105
+ *
106
+ * Support varies across modern emulators; Zutty 0.6+ claims VT520 compatibility,
107
+ * and Microsoft's Windows Terminal also supports this sequence.
108
+ * Unsupported sequences are typically silently ignored by most terminals.
110
109
  * @param name The name or content for the DEC-style icon name.
111
- * @returns The ANSI escape sequence for DECSIN (as implemented).
110
+ * @returns The ANSI escape sequence for DECSIN.
112
111
  * @see EK-VT520-RM 5–134 (VT520 Programmer Reference Manual)
113
- * @see setWindowTitle
114
112
  * @example
115
113
  * ```typescript
116
114
  * import { decsin } from "@visulima/ansi";
117
115
  *
118
116
  * process.stdout.write(decsin("SpecialIcon"));
119
- * // Sends: "\\x1b]2;L;SpecialIcon\\x07"
117
+ * // Sends: "\x1b]2L;SpecialIcon\x1b\\"
120
118
  * ```
121
119
  */
122
120
  export declare const decsin: (name: string) => string;
package/dist/title.js CHANGED
@@ -1,16 +1,17 @@
1
- import { O as OSC, B as BEL, a as ST } from './packem_shared/constants-CE7WkXh_.js';
1
+ import { O as OSC, a as ST, B as BEL } from './packem_shared/constants-CE7WkXh_.js';
2
2
 
3
+ const TITLE_SANITIZE_REGEX = /[\u0007\u001B]/g;
3
4
  const validateTitle = (title) => {
4
5
  if (typeof title !== "string") {
5
6
  throw new TypeError("Title must be a string");
6
7
  }
7
- return title.replaceAll(/[\u0007\u001B]/g, "");
8
+ return title.replaceAll(TITLE_SANITIZE_REGEX, "");
8
9
  };
9
10
  const setIconNameAndWindowTitle = (title) => `${OSC}0;${validateTitle(title)}${BEL}`;
10
11
  const setIconName = (iconName) => `${OSC}1;${iconName}${BEL}`;
11
12
  const setWindowTitle = (title) => `${OSC}2;${title}${BEL}`;
12
- const decswt = (title) => setWindowTitle(`1;${title}`);
13
- const decsin = (name) => setWindowTitle(`L;${name}`);
13
+ const decswt = (title) => `${OSC}21;${title}${ST}`;
14
+ const decsin = (name) => `${OSC}2L;${name}${ST}`;
14
15
  const setIconNameAndWindowTitleWithST = (title) => `${OSC}0;${title}${ST}`;
15
16
  const setIconNameWithST = (iconName) => `${OSC}1;${iconName}${ST}`;
16
17
  const setWindowTitleWithST = (title) => `${OSC}2;${title}${ST}`;
@@ -12,77 +12,65 @@ export declare enum XTermWindowOp {
12
12
  * Iconify window.
13
13
  */
14
14
  ICONIFY_WINDOW = 2,
15
- /**
16
- * Lower the window to the bottom of the stacking order.
17
- */
18
- LOWER_WINDOW = 6,
19
- /**
20
- * Maximize window (i.e., "zoom" or "toggle").
21
- */
22
- MAXIMIZE_WINDOW = 10,
23
- /**
24
- * Maximize window horizontally.
25
- */
26
- MAXIMIZE_WINDOW_HORIZONTALLY = 10.2,
27
- /**
28
- * Maximize window vertically.
29
- */
30
- MAXIMIZE_WINDOW_VERTICALLY = 10.1,
31
15
  /**
32
16
  * Move window to `[x, y]`.
33
17
  */
34
18
  MOVE_WINDOW = 3,
35
19
  /**
36
- * Pop window title from stack.
37
- */
38
- POP_WINDOW_TITLE = 23,
39
- /**
40
- * Push window title on stack.
20
+ * Resize the text area to `[height, width]` in characters.
41
21
  */
42
- PUSH_WINDOW_TITLE = 22,
22
+ RESIZE_TEXT_AREA_CHARS = 4,
43
23
  /**
44
24
  * Raise the window to the front of the stacking order.
45
25
  */
46
26
  RAISE_WINDOW = 5,
27
+ /**
28
+ * Lower the window to the bottom of the stacking order.
29
+ */
30
+ LOWER_WINDOW = 6,
47
31
  /**
48
32
  * Refresh the window.
49
33
  */
50
34
  REFRESH_WINDOW = 7,
51
35
  /**
52
- * Report cell size in pixels.
53
- * Response: `CSI 6 ; height ; width t`
36
+ * Resize the text area to `[height, width]` in pixels.
54
37
  */
55
- REPORT_CELL_SIZE_PIXELS = 16,// From Go code
38
+ RESIZE_TEXT_AREA_PIXELS = 8,
56
39
  /**
57
- * Report icon label.
58
- * Response: `OSC L label ST`
40
+ * Restore maximized window.
59
41
  */
60
- REPORT_ICON_LABEL = 19,
42
+ RESTORE_MAXIMIZED_WINDOW = 9,
61
43
  /**
62
- * Report text area size in characters.
63
- * Response: `CSI 4 ; height ; width t`
44
+ * Maximize window (i.e., "zoom" or "toggle").
64
45
  */
65
- REPORT_TEXT_AREA_SIZE_CHARS = 14,
46
+ MAXIMIZE_WINDOW = 10,
66
47
  /**
67
- * Report text area size in pixels.
68
- * Response: `CSI 8 ; height ; width t`
48
+ * Maximize window vertically.
69
49
  */
70
- REPORT_TEXT_AREA_SIZE_PIXELS = 18,
50
+ MAXIMIZE_WINDOW_VERTICALLY = 10.1,
71
51
  /**
72
- * Report window position.
73
- * Response: `CSI 3 ; x ; y t`
52
+ * Maximize window horizontally.
74
53
  */
75
- REPORT_WINDOW_POSITION = 13,
54
+ MAXIMIZE_WINDOW_HORIZONTALLY = 10.2,
55
+ /**
56
+ * Undo full-screen mode.
57
+ */
58
+ UNDO_FULL_SCREEN_MODE = 10.3,// Note: XTerm docs list 10 ; 0, 10 ; 1, 10 ; 2, this is simplified.
76
59
  /**
77
60
  * Report window state.
78
61
  * Response: `CSI code t` where `code` is 1 if de-iconified, 2 if iconified.
79
62
  */
80
63
  REPORT_WINDOW_STATE = 11,
81
64
  /**
82
- * Report window title.
83
- * Response: `OSC l label ST`
65
+ * Report window position.
66
+ * Response: `CSI 3 ; x ; y t`
84
67
  */
85
- REPORT_WINDOW_TITLE = 21,
68
+ REPORT_WINDOW_POSITION = 13,
69
+ /**
70
+ * Report text area size in characters.
71
+ * Response: `CSI 4 ; height ; width t`
72
+ */
73
+ REPORT_TEXT_AREA_SIZE_CHARS = 14,
86
74
  /**
87
75
  * Report window size in pixels.
88
76
  * Alias for `REPORT_TEXT_AREA_SIZE_PIXELS` for compatibility with some terminals (e.g., mintty).
@@ -91,26 +79,38 @@ export declare enum XTermWindowOp {
91
79
  */
92
80
  REQUEST_WINDOW_SIZE_WIN_OP_COMPAT = 14,// From Go code
93
81
  /**
94
- * Resize the screen to `[width, height]` in pixels and resize the text area to `[cols, lines]` in characters.
95
- * (DECSLPP - Set Lines Per Page)
82
+ * Report cell size in pixels.
83
+ * Response: `CSI 6 ; height ; width t`
96
84
  */
97
- RESIZE_SCREEN_AND_TEXT_AREA = 24,// Typically with one param (lines), but XTerm extends it for width/height too
85
+ REPORT_CELL_SIZE_PIXELS = 16,// From Go code
98
86
  /**
99
- * Resize the text area to `[height, width]` in characters.
87
+ * Report text area size in pixels.
88
+ * Response: `CSI 8 ; height ; width t`
100
89
  */
101
- RESIZE_TEXT_AREA_CHARS = 4,
90
+ REPORT_TEXT_AREA_SIZE_PIXELS = 18,
102
91
  /**
103
- * Resize the text area to `[height, width]` in pixels.
92
+ * Report icon label.
93
+ * Response: `OSC L label ST`
104
94
  */
105
- RESIZE_TEXT_AREA_PIXELS = 8,
95
+ REPORT_ICON_LABEL = 19,
106
96
  /**
107
- * Restore maximized window.
97
+ * Report window title.
98
+ * Response: `OSC l label ST`
108
99
  */
109
- RESTORE_MAXIMIZED_WINDOW = 9,
100
+ REPORT_WINDOW_TITLE = 21,
110
101
  /**
111
- * Undo full-screen mode.
102
+ * Push window title on stack.
103
+ */
104
+ PUSH_WINDOW_TITLE = 22,
105
+ /**
106
+ * Pop window title from stack.
107
+ */
108
+ POP_WINDOW_TITLE = 23,
109
+ /**
110
+ * Resize the screen to `[width, height]` in pixels and resize the text area to `[cols, lines]` in characters.
111
+ * (DECSLPP - Set Lines Per Page)
112
112
  */
113
- UNDO_FULL_SCREEN_MODE = 10.3
113
+ RESIZE_SCREEN_AND_TEXT_AREA = 24
114
114
  }
115
115
  /**
116
116
  * Generates an XTerm Window Operation (XTWINOPS) sequence.
@@ -153,7 +153,7 @@ export declare const resizeTextAreaChars: (height: number, width: number) => str
153
153
  * This function uses `XTermWindowOp.REQUEST_WINDOW_SIZE_WIN_OP_COMPAT` (14), which corresponds to
154
154
  * `XTermWindowOp.REPORT_TEXT_AREA_SIZE_CHARS` in XTerm.
155
155
  *
156
- * Sequence: `CSI 14 t` (which triggers the report `CSI 4 ; height ; width t`)
156
+ * Sequence: `CSI 14 t` (which triggers the report `CSI 4 ; height ; width t`).
157
157
  * @returns The ANSI escape sequence to request the text area size in characters.
158
158
  * @see xtermWindowOp
159
159
  * @see XTermWindowOp.REPORT_TEXT_AREA_SIZE_CHARS
@@ -173,7 +173,7 @@ export declare const requestTextAreaSizeChars: () => string;
173
173
  * The terminal is expected to respond with a sequence like `CSI 6 ; height ; width t`,
174
174
  * where height and width are the dimensions of a single character cell in pixels.
175
175
  *
176
- * Sequence: `CSI 16 t` (which triggers the report `CSI 6 ; height ; width t`)
176
+ * Sequence: `CSI 16 t` (which triggers the report `CSI 6 ; height ; width t`).
177
177
  * @returns The ANSI escape sequence to request the cell size in pixels.
178
178
  * @see xtermWindowOp
179
179
  * @see XTermWindowOp.REPORT_CELL_SIZE_PIXELS
@@ -191,7 +191,7 @@ export declare const requestCellSizePixels: () => string;
191
191
  * Requests a report of the terminal window's text area size in pixels.
192
192
  * The terminal is expected to respond with a sequence like `CSI 8 ; height ; width t`.
193
193
  *
194
- * Sequence: `CSI 18 t` (which triggers the report `CSI 8 ; height ; width t`)
194
+ * Sequence: `CSI 18 t` (which triggers the report `CSI 8 ; height ; width t`).
195
195
  * @returns The ANSI escape sequence to request the text area size in pixels.
196
196
  * @see xtermWindowOp
197
197
  * @see XTermWindowOp.REPORT_TEXT_AREA_SIZE_PIXELS
@@ -344,7 +344,7 @@ export declare const restoreMaximizedWindow: () => string;
344
344
  * Some terminals might use `CSI 10 t` for a general maximize/toggle.
345
345
  * This function uses `XTermWindowOp.MAXIMIZE_WINDOW` which is 10.
346
346
  *
347
- * Sequence: `CSI 10 t` (using `XTermWindowOp.MAXIMIZE_WINDOW`)
347
+ * Sequence: `CSI 10 t` (using `XTermWindowOp.MAXIMIZE_WINDOW`).
348
348
  * @returns The ANSI escape sequence to maximize the window.
349
349
  * @see xtermWindowOp
350
350
  * @see XTermWindowOp.MAXIMIZE_WINDOW