@visulima/ansi 1.0.18 → 2.0.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.
Files changed (130) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/LICENSE.md +76 -74
  3. package/README.md +335 -2
  4. package/dist/alternative-screen.cjs +11 -5
  5. package/dist/alternative-screen.d.cts +74 -4
  6. package/dist/alternative-screen.d.mts +74 -4
  7. package/dist/alternative-screen.d.ts +74 -4
  8. package/dist/alternative-screen.mjs +8 -4
  9. package/dist/clear.cjs +10 -18
  10. package/dist/clear.d.cts +77 -7
  11. package/dist/clear.d.mts +77 -7
  12. package/dist/clear.d.ts +77 -7
  13. package/dist/clear.mjs +8 -15
  14. package/dist/constants.d.cts +20 -0
  15. package/dist/constants.d.mts +20 -0
  16. package/dist/constants.d.ts +20 -0
  17. package/dist/cursor.cjs +19 -2
  18. package/dist/cursor.d.cts +436 -30
  19. package/dist/cursor.d.mts +436 -30
  20. package/dist/cursor.d.ts +436 -30
  21. package/dist/cursor.mjs +2 -2
  22. package/dist/erase.cjs +44 -13
  23. package/dist/erase.d.cts +206 -9
  24. package/dist/erase.d.mts +206 -9
  25. package/dist/erase.d.ts +206 -9
  26. package/dist/erase.mjs +40 -14
  27. package/dist/helpers.d.cts +14 -0
  28. package/dist/helpers.d.mts +14 -0
  29. package/dist/helpers.d.ts +14 -0
  30. package/dist/hyperlink.cjs +9 -0
  31. package/dist/hyperlink.d.cts +29 -0
  32. package/dist/hyperlink.d.mts +27 -0
  33. package/dist/hyperlink.d.ts +29 -0
  34. package/dist/hyperlink.mjs +7 -0
  35. package/dist/image.cjs +12 -5
  36. package/dist/image.d.cts +69 -58
  37. package/dist/image.d.mts +69 -58
  38. package/dist/image.d.ts +69 -58
  39. package/dist/image.mjs +10 -5
  40. package/dist/index.cjs +209 -11
  41. package/dist/index.d.cts +35 -12
  42. package/dist/index.d.mts +35 -12
  43. package/dist/index.d.ts +35 -12
  44. package/dist/index.mjs +20 -7
  45. package/dist/iterm2/iterm2-properties.d.cts +135 -0
  46. package/dist/iterm2/iterm2-properties.d.mts +135 -0
  47. package/dist/iterm2/iterm2-properties.d.ts +135 -0
  48. package/dist/iterm2/iterm2-sequences.d.cts +96 -0
  49. package/dist/iterm2/iterm2-sequences.d.mts +96 -0
  50. package/dist/iterm2/iterm2-sequences.d.ts +96 -0
  51. package/dist/iterm2.cjs +26 -0
  52. package/dist/iterm2.d.cts +58 -0
  53. package/dist/iterm2.d.mts +58 -0
  54. package/dist/iterm2.d.ts +58 -0
  55. package/dist/iterm2.mjs +14 -0
  56. package/dist/mode.cjs +388 -0
  57. package/dist/mode.d.cts +657 -0
  58. package/dist/mode.d.mts +657 -0
  59. package/dist/mode.d.ts +657 -0
  60. package/dist/mode.mjs +235 -0
  61. package/dist/mouse.cjs +127 -0
  62. package/dist/mouse.d.cts +230 -0
  63. package/dist/mouse.d.mts +230 -0
  64. package/dist/mouse.d.ts +230 -0
  65. package/dist/mouse.mjs +108 -0
  66. package/dist/packem_shared/IT2_AUTO-5vTJQMm6.cjs +15 -0
  67. package/dist/packem_shared/IT2_AUTO-DnfCUXso.mjs +8 -0
  68. package/dist/packem_shared/ITerm2File-BGPqNSjB.cjs +137 -0
  69. package/dist/packem_shared/ITerm2File-DKFkdqdA.mjs +130 -0
  70. package/dist/packem_shared/{constants-D8u2npjW.cjs → constants-BK26O-46.cjs} +4 -0
  71. package/dist/packem_shared/constants-CE7WkXh_.mjs +9 -0
  72. package/dist/packem_shared/cursor-CQKLCu7U.cjs +105 -0
  73. package/dist/packem_shared/cursor-DhFQcQ9g.mjs +73 -0
  74. package/dist/passthrough.cjs +38 -0
  75. package/dist/passthrough.d.cts +77 -0
  76. package/dist/passthrough.d.mts +77 -0
  77. package/dist/passthrough.d.ts +77 -0
  78. package/dist/passthrough.mjs +31 -0
  79. package/dist/reset.cjs +9 -0
  80. package/dist/reset.d.cts +26 -0
  81. package/dist/reset.d.mts +26 -0
  82. package/dist/reset.d.ts +26 -0
  83. package/dist/reset.mjs +4 -0
  84. package/dist/screen.cjs +41 -0
  85. package/dist/screen.d.cts +234 -0
  86. package/dist/screen.d.mts +234 -0
  87. package/dist/screen.d.ts +234 -0
  88. package/dist/screen.mjs +29 -0
  89. package/dist/scroll.cjs +17 -3
  90. package/dist/scroll.d.cts +67 -4
  91. package/dist/scroll.d.mts +67 -4
  92. package/dist/scroll.d.ts +67 -4
  93. package/dist/scroll.mjs +16 -4
  94. package/dist/status.cjs +147 -0
  95. package/dist/status.d.cts +501 -0
  96. package/dist/status.d.mts +501 -0
  97. package/dist/status.d.ts +501 -0
  98. package/dist/status.mjs +104 -0
  99. package/dist/strip.d.cts +23 -1
  100. package/dist/strip.d.mts +22 -2
  101. package/dist/strip.d.ts +23 -1
  102. package/dist/termcap.cjs +33 -0
  103. package/dist/termcap.d.cts +38 -0
  104. package/dist/termcap.d.mts +38 -0
  105. package/dist/termcap.d.ts +38 -0
  106. package/dist/termcap.mjs +27 -0
  107. package/dist/title.cjs +31 -0
  108. package/dist/title.d.cts +185 -0
  109. package/dist/title.d.mts +185 -0
  110. package/dist/title.d.ts +185 -0
  111. package/dist/title.mjs +20 -0
  112. package/dist/window-ops.cjs +85 -0
  113. package/dist/window-ops.d.cts +418 -0
  114. package/dist/window-ops.d.mts +418 -0
  115. package/dist/window-ops.d.ts +418 -0
  116. package/dist/window-ops.mjs +63 -0
  117. package/dist/xterm.cjs +48 -0
  118. package/dist/xterm.d.cts +94 -0
  119. package/dist/xterm.d.mts +94 -0
  120. package/dist/xterm.d.ts +94 -0
  121. package/dist/xterm.mjs +35 -0
  122. package/package.json +153 -9
  123. package/dist/link.cjs +0 -9
  124. package/dist/link.d.cts +0 -3
  125. package/dist/link.d.mts +0 -3
  126. package/dist/link.d.ts +0 -3
  127. package/dist/link.mjs +0 -7
  128. package/dist/packem_shared/constants-CqXMfQy0.mjs +0 -7
  129. package/dist/packem_shared/cursor-2tHgT9r6.cjs +0 -57
  130. package/dist/packem_shared/cursor-CDCWqbC9.mjs +0 -42
@@ -0,0 +1,501 @@
1
+ /** Represents an ANSI terminal status report type. */
2
+ export type AnsiStatusReport = StatusReport;
3
+ /** Represents a DEC terminal status report type. */
4
+ export type DecStatusReport = StatusReport;
5
+ /**
6
+ * Interface for terminal status reports.
7
+ */
8
+ export interface StatusReport {
9
+ readonly isDecReport: boolean;
10
+ readonly reportCode: number;
11
+ }
12
+ /**
13
+ * Creates an ANSI-type status report object.
14
+ * These reports are typically requested using `CSI Ps n`.
15
+ * @param code The numeric code for the ANSI status report.
16
+ * @returns An object implementing the {@link StatusReport} interface, marked as not DEC-specific.
17
+ * @example
18
+ * ```typescript
19
+ * import { createAnsiStatusReport, deviceStatusReport } from "@visulima/ansi";
20
+ *
21
+ * const report = createAnsiStatusReport(5);
22
+ * const sequence = deviceStatusReport(report);
23
+ * console.log(sequence);
24
+ * ```
25
+ */
26
+ export declare const createAnsiStatusReport: (code: number) => AnsiStatusReport;
27
+ /**
28
+ * Creates a DEC private status report object.
29
+ * These reports are typically requested using `CSI ? Ps n`.
30
+ * @param code The numeric code for the DEC private status report.
31
+ * @returns An object implementing the {@link StatusReport} interface, marked as DEC-specific.
32
+ * @example
33
+ * ```typescript
34
+ * import { createDecStatusReport, deviceStatusReport } from "@visulima/ansi";
35
+ *
36
+ * const report = createDecStatusReport(15);
37
+ * const sequence = deviceStatusReport(report);
38
+ * console.log(sequence);
39
+ * ```
40
+ */
41
+ export declare const createDecStatusReport: (code: number) => DecStatusReport;
42
+ /**
43
+ * Generates a Device Status Report (DSR) sequence to request terminal status information.
44
+ *
45
+ * Standard DSR: `CSI Ps n` (where `Ps` are numeric parameters separated by semicolons).
46
+ * DEC-specific DSR: `CSI ? Ps n` (where `Ps` are numeric parameters separated by semicolons).
47
+ *
48
+ * If any of the provided {@link StatusReport} objects are DEC-specific (i.e., `isDecReport` is true),
49
+ * the entire sequence will be prefixed with `?`, indicating a DEC private DSR query.
50
+ * Mixing standard and DEC-specific report types in a single request is handled by this logic,
51
+ * but typically, a DSR query is either entirely standard or entirely DEC-specific.
52
+ * @param reports One or more {@link StatusReport} objects indicating the statuses to request.
53
+ * If no reports are provided, an empty string is returned.
54
+ * @returns The DSR sequence string (e.g., `"\x1b[5n"`, `"\x1b[?1;2n"`).
55
+ * @see https://vt100.net/docs/vt510-rm/DSR.html
56
+ * @example
57
+ * ```typescript
58
+ * import { deviceStatusReport, createAnsiStatusReport, createDecStatusReport } from "@visulima/ansi";
59
+ *
60
+ * const ansiReport = createAnsiStatusReport(5);
61
+ * const decReport = createDecStatusReport(25);
62
+ *
63
+ * console.log(deviceStatusReport(ansiReport));
64
+ * console.log(deviceStatusReport(decReport));
65
+ * console.log(deviceStatusReport(ansiReport, decReport));
66
+ * ```
67
+ */
68
+ export declare const deviceStatusReport: (...reports: StatusReport[]) => string;
69
+ /**
70
+ * DSR (Device Status Report) alias.
71
+ * This function serves as a shorthand for {@link deviceStatusReport} when requesting a single status.
72
+ * @param report A single {@link StatusReport} object.
73
+ * @returns The DSR sequence string.
74
+ * @see deviceStatusReport
75
+ * @example
76
+ * ```typescript
77
+ * import { DSR, requestTerminalStatus } from "@visulima/ansi";
78
+ *
79
+ * console.log(DSR(requestTerminalStatus));
80
+ * ```
81
+ */
82
+ export declare const DSR: (report: StatusReport) => string;
83
+ /**
84
+ * ANSI escape sequence to request the cursor's current position (row and column).
85
+ * This is a common Device Status Report (DSR) request.
86
+ * Sequence: `CSI 6 n`
87
+ * The terminal typically responds with a Cursor Position Report (CPR) like `CSI Pl ; Pc R`.
88
+ * @see cursorPositionReport
89
+ * @see https://vt100.net/docs/vt510-rm/CPR.html
90
+ * @example
91
+ * ```typescript
92
+ * import { requestCursorPositionReport } from "@visulima/ansi";
93
+ *
94
+ * process.stdout.write(requestCursorPositionReport);
95
+ * ```
96
+ */
97
+ export declare const requestCursorPositionReport: string;
98
+ /**
99
+ * ANSI escape sequence to request the cursor's current position including page number (DEC private).
100
+ * This is a DEC-specific Device Status Report (DSR) request, often called DECXCPR.
101
+ * Sequence: `CSI ? 6 n`
102
+ * The terminal typically responds with an Extended Cursor Position Report (DECXCPR) like `CSI ? Pl ; Pc ; Pp R`.
103
+ * @see extendedCursorPositionReport
104
+ * @see https://vt100.net/docs/vt510-rm/DECXCPR.html
105
+ * @example
106
+ * ```typescript
107
+ * import { requestExtendedCursorPositionReport } from "@visulima/ansi";
108
+ *
109
+ * process.stdout.write(requestExtendedCursorPositionReport);
110
+ * ```
111
+ */
112
+ export declare const requestExtendedCursorPositionReport: string;
113
+ /**
114
+ * Generates the Cursor Position Report (CPR) response sequence.
115
+ * This sequence is typically sent by the terminal in response to a DSR CPR request (`CSI 6 n`).
116
+ *
117
+ * Sequence: `CSI Pl ; Pc R`
118
+ * - `Pl`: Line number (1-based).
119
+ * - `Pc`: Column number (1-based).
120
+ * @param line The line number (1-based). Values less than 1 are treated as 1.
121
+ * @param column The column number (1-based). Values less than 1 are treated as 1.
122
+ * @returns The CPR sequence string.
123
+ * @example
124
+ * ```typescript
125
+ * import { cursorPositionReport } from "@visulima/ansi";
126
+ *
127
+ * console.log(cursorPositionReport(10, 5));
128
+ * ```
129
+ */
130
+ export declare const cursorPositionReport: (line: number, column: number) => string;
131
+ /**
132
+ * Alias for {@link cursorPositionReport}.
133
+ * Provides a shorter name for the CPR response sequence generator.
134
+ * @see cursorPositionReport
135
+ * @example
136
+ * ```typescript
137
+ * import { CPR } from "@visulima/ansi";
138
+ *
139
+ * console.log(CPR(10, 5));
140
+ * ```
141
+ */
142
+ export declare const CPR: (line: number, column: number) => string;
143
+ /**
144
+ * Extended Cursor Position Report (DECXCPR) response format.
145
+ * @param line The line number (1-based).
146
+ * @param column The column number (1-based).
147
+ * @param page The page number (1-based). If 0 or less, it's omitted.
148
+ * @returns The DECXCPR sequence string.
149
+ * @example
150
+ * ```typescript
151
+ * import { extendedCursorPositionReport } from "@visulima/ansi";
152
+ *
153
+ * console.log(extendedCursorPositionReport(10, 5, 1));
154
+ *
155
+ * console.log(extendedCursorPositionReport(10, 5, 0));
156
+ * ```
157
+ */
158
+ export declare const extendedCursorPositionReport: (line: number, column: number, page: number) => string;
159
+ /**
160
+ * Alias for {@link extendedCursorPositionReport}.
161
+ * Provides a shorter name for the DECXCPR response sequence generator.
162
+ * @see extendedCursorPositionReport
163
+ * @example
164
+ * ```typescript
165
+ * import { DECXCPR } from "@visulima/ansi";
166
+ *
167
+ * console.log(DECXCPR(10, 5, 1));
168
+ * ```
169
+ */
170
+ export declare const DECXCPR: (line: number, column: number, page: number) => string;
171
+ /**
172
+ * ANSI escape sequence to request the terminal's name and version (XTVERSION).
173
+ * Sequence: `CSI > 0 q`
174
+ * The terminal typically responds with a DCS sequence: `DCS > | text ST`
175
+ * Where `text` is the terminal name and version.
176
+ * @see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-PC-Style-Function-Keys
177
+ * @example
178
+ * ```typescript
179
+ * import { RequestNameVersion } from "@visulima/ansi";
180
+ *
181
+ * process.stdout.write(RequestNameVersion);
182
+ * ```
183
+ */
184
+ export declare const RequestNameVersion: string;
185
+ /**
186
+ * Alias for {@link RequestNameVersion}.
187
+ * @see RequestNameVersion
188
+ */
189
+ export declare const XTVERSION: string;
190
+ /**
191
+ * ANSI escape sequence to request Primary Device Attributes (DA1).
192
+ * Sequence: `CSI c` or `CSI 0 c`. Using `CSI c` as it's the more common base form.
193
+ * The terminal responds with `CSI ? Pn ; Pn ; ... c`.
194
+ * @example
195
+ * ```typescript
196
+ * import { requestPrimaryDeviceAttributes } from "@visulima/ansi";
197
+ *
198
+ * process.stdout.write(requestPrimaryDeviceAttributes);
199
+ * ```
200
+ */
201
+ export declare const requestPrimaryDeviceAttributes: string;
202
+ /**
203
+ * Alias for {@link requestPrimaryDeviceAttributes}.
204
+ */
205
+ export declare const DA1: string;
206
+ /**
207
+ * Generates the response sequence for Primary Device Attributes (DA1).
208
+ * Sequence: `CSI ? Ps ; ... c`
209
+ *
210
+ * Common attributes include:
211
+ * - 1 132 columns
212
+ * - 2 Printer port
213
+ * - 4 Sixel
214
+ * - 6 Selective erase
215
+ * - 7 Soft character set (DRCS)
216
+ * - 8 User-defined keys (UDKs)
217
+ * - 9 National replacement character sets (NRCS) (International terminal only)
218
+ * - 12 Yugoslavian (SCS)
219
+ * - 15 Technical character set
220
+ * - 18 Windowing capability
221
+ * - 21 Horizontal scrolling
222
+ * - 23 Greek
223
+ * - 24 Turkish
224
+ * - 42 ISO Latin-2 character set
225
+ * - 44 PCTerm
226
+ * - 45 Soft key map
227
+ * - 46 ASCII emulation
228
+ * @param attributes Numeric attribute codes.
229
+ * @returns The DA1 response sequence.
230
+ * @example
231
+ * ```typescript
232
+ * import { reportPrimaryDeviceAttributes } from "@visulima/ansi";
233
+ *
234
+ * console.log(reportPrimaryDeviceAttributes(1, 9));
235
+ * console.log(reportPrimaryDeviceAttributes(61));
236
+ * ```
237
+ */
238
+ export declare const reportPrimaryDeviceAttributes: (...attributes: number[]) => string;
239
+ /**
240
+ * ANSI escape sequence to request Secondary Device Attributes (DA2).
241
+ * Sequence: `CSI > c` or `CSI > 0 c`. Using `CSI > c` as the base.
242
+ * The terminal responds with `CSI > Pv ; Pl ; Pc c` (Version; Level; Cartridge).
243
+ * @example
244
+ * ```typescript
245
+ * import { requestSecondaryDeviceAttributes } from "@visulima/ansi";
246
+ *
247
+ * process.stdout.write(requestSecondaryDeviceAttributes);
248
+ * ```
249
+ */
250
+ export declare const requestSecondaryDeviceAttributes: string;
251
+ /**
252
+ * Alias for {@link requestSecondaryDeviceAttributes}.
253
+ */
254
+ export declare const DA2: string;
255
+ /**
256
+ * Generates the response sequence for Secondary Device Attributes (DA2).
257
+ * Sequence: `CSI > Pv ; Pl ; Pc c`
258
+ * @param version Terminal version number.
259
+ * @param level Terminal model/level number.
260
+ * @param cartridge ROM cartridge (0 for none).
261
+ * @returns The DA2 response sequence.
262
+ * @example
263
+ * ```typescript
264
+ * import { reportSecondaryDeviceAttributes } from "@visulima/ansi";
265
+ *
266
+ * console.log(reportSecondaryDeviceAttributes(0, 2, 0));
267
+ * console.log(reportSecondaryDeviceAttributes(41, 370, 0));
268
+ * ```
269
+ */
270
+ export declare const reportSecondaryDeviceAttributes: (version: number, level: number, cartridge?: number) => string;
271
+ /**
272
+ * ANSI escape sequence to request Tertiary Device Attributes (DA3).
273
+ * Sequence: `CSI = c` or `CSI = 0 c`. Using `CSI = c` as the base.
274
+ * The terminal responds with `DCS ! | unitID ST`. (DECRPTUI - Report Unit ID)
275
+ * @example
276
+ * ```typescript
277
+ * import { requestTertiaryDeviceAttributes } from "@visulima/ansi";
278
+ *
279
+ * process.stdout.write(requestTertiaryDeviceAttributes);
280
+ * ```
281
+ */
282
+ export declare const requestTertiaryDeviceAttributes: string;
283
+ /**
284
+ * Alias for {@link requestTertiaryDeviceAttributes}.
285
+ */
286
+ export declare const DA3: string;
287
+ /**
288
+ * Generates the response sequence for Tertiary Device Attributes (DA3), which is a DECRPTUI.
289
+ * Sequence: `DCS ! | unitID ST`
290
+ * @param unitID The unit ID string for the terminal.
291
+ * @returns The DA3 response sequence (DECRPTUI).
292
+ * If unitID is empty, it's arguably an invalid report, but we'll return `DCS ! | ST` to match some behaviors.
293
+ * @example
294
+ * ```typescript
295
+ * import { reportTertiaryDeviceAttributes } from "@visulima/ansi";
296
+ *
297
+ * console.log(reportTertiaryDeviceAttributes("MYTERM001"));
298
+ * console.log(reportTertiaryDeviceAttributes(""));
299
+ * ```
300
+ */
301
+ export declare const reportTertiaryDeviceAttributes: (unitID: string) => string;
302
+ /**
303
+ * ANSI escape sequence to request Primary Device Attributes (DA1) with explicit parameter 0.
304
+ * Sequence: `CSI 0 c`.
305
+ * This is an alternative form of {@link requestPrimaryDeviceAttributes}.
306
+ * @example
307
+ * ```typescript
308
+ * import { requestPrimaryDeviceAttributesParam0 } from "@visulima/ansi";
309
+ *
310
+ * process.stdout.write(requestPrimaryDeviceAttributesParam0);
311
+ * ```
312
+ */
313
+ export declare const requestPrimaryDeviceAttributesParam0: string;
314
+ /**
315
+ * ANSI escape sequence to request Secondary Device Attributes (DA2) with explicit parameter 0.
316
+ * Sequence: `CSI > 0 c`.
317
+ * This is an alternative form of {@link requestSecondaryDeviceAttributes}.
318
+ * Note: This is also what XTerm uses for `sendDeviceAttributes` with no arguments in some contexts,
319
+ * but it's different from `XTVERSION` (`CSI > 0 q`).
320
+ * @example
321
+ * ```typescript
322
+ * import { requestSecondaryDeviceAttributesParam0 } from "@visulima/ansi";
323
+ *
324
+ * process.stdout.write(requestSecondaryDeviceAttributesParam0);
325
+ * ```
326
+ */
327
+ export declare const requestSecondaryDeviceAttributesParam0: string;
328
+ /**
329
+ * ANSI escape sequence to request Tertiary Device Attributes (DA3) with explicit parameter 0.
330
+ * Sequence: `CSI = 0 c`.
331
+ * This is an alternative form of {@link requestTertiaryDeviceAttributes}.
332
+ * @example
333
+ * ```typescript
334
+ * import { requestTertiaryDeviceAttributesParam0 } from "@visulima/ansi";
335
+ *
336
+ * process.stdout.write(requestTertiaryDeviceAttributesParam0);
337
+ * ```
338
+ */
339
+ export declare const requestTertiaryDeviceAttributesParam0: string;
340
+ /**
341
+ * A {@link StatusReport} object to request the terminal's general status.
342
+ * Corresponds to DSR request `CSI 5 n`.
343
+ * The terminal is expected to respond with `CSI 0 n` (OK) or `CSI 3 n` (Failure).
344
+ * @see DSR_TerminalStatus
345
+ * @see reportTerminalOK
346
+ * @see reportTerminalNotOK
347
+ * @example
348
+ * ```typescript
349
+ * import { DSR, requestTerminalStatus } from "@visulima/ansi";
350
+ *
351
+ * const reportSequence = DSR(requestTerminalStatus);
352
+ * console.log(reportSequence);
353
+ * ```
354
+ */
355
+ export declare const requestTerminalStatus: StatusReport;
356
+ /**
357
+ * ANSI escape sequence `CSI 5 n` to request terminal status.
358
+ * This is generated using `deviceStatusReport(requestTerminalStatus)`.
359
+ * @see requestTerminalStatus
360
+ * @example
361
+ * ```typescript
362
+ * import { DSR_TerminalStatus } from "@visulima/ansi";
363
+ *
364
+ * process.stdout.write(DSR_TerminalStatus);
365
+ * ```
366
+ */
367
+ export declare const DSR_TerminalStatus: string;
368
+ /**
369
+ * ANSI escape sequence `CSI 0 n` indicating Terminal is OK (Operating Normally).
370
+ * This is a typical response to {@link DSR_TerminalStatus} (`CSI 5 n`) or `deviceStatusReport(requestTerminalStatus)`.
371
+ * @see requestTerminalStatus
372
+ * @see DSR_TerminalStatus
373
+ */
374
+ export declare const reportTerminalOK: string;
375
+ /**
376
+ * ANSI escape sequence `CSI 3 n` indicating Terminal is NOT OK (Malfunction).
377
+ * This is a typical response to {@link DSR_TerminalStatus} (`CSI 5 n`) or `deviceStatusReport(requestTerminalStatus)`.
378
+ * @see requestTerminalStatus
379
+ * @see DSR_TerminalStatus
380
+ */
381
+ export declare const reportTerminalNotOK: string;
382
+ /**
383
+ * A DEC-specific {@link StatusReport} object to request printer status.
384
+ * Corresponds to DSR request `CSI ? 15 n`.
385
+ * The terminal is expected to respond with sequences like `CSI ? 10 n` (Ready), `CSI ? 11 n` (Not Ready), or `CSI ? 13 n` (No Paper).
386
+ * @see DSR_PrinterStatusDEC
387
+ * @see reportPrinterReadyDEC
388
+ * @see reportPrinterNotReadyDEC
389
+ * @see reportPrinterNoPaperDEC
390
+ * @example
391
+ * ```typescript
392
+ * import { DSR, requestPrinterStatusDEC } from "@visulima/ansi";
393
+ *
394
+ * const reportSequence = DSR(requestPrinterStatusDEC);
395
+ * console.log(reportSequence);
396
+ * ```
397
+ */
398
+ export declare const requestPrinterStatusDEC: StatusReport;
399
+ /**
400
+ * ANSI escape sequence `CSI ? 15 n` to request DEC-specific printer status.
401
+ * This is generated using `deviceStatusReport(requestPrinterStatusDEC)`.
402
+ * @see requestPrinterStatusDEC
403
+ * @example
404
+ * ```typescript
405
+ * import { DSR_PrinterStatusDEC } from "@visulima/ansi";
406
+ *
407
+ * process.stdout.write(DSR_PrinterStatusDEC);
408
+ * ```
409
+ */
410
+ export declare const DSR_PrinterStatusDEC: string;
411
+ /**
412
+ * ANSI escape sequence `CSI ? 10 n` indicating Printer is Ready (DEC-specific response).
413
+ * Typical response to {@link DSR_PrinterStatusDEC} or `deviceStatusReport(requestPrinterStatusDEC)`.
414
+ * @see requestPrinterStatusDEC
415
+ * @see DSR_PrinterStatusDEC
416
+ */
417
+ export declare const reportPrinterReadyDEC: string;
418
+ /**
419
+ * ANSI escape sequence `CSI ? 11 n` indicating Printer is Not Ready (DEC-specific response).
420
+ * Typical response to {@link DSR_PrinterStatusDEC} or `deviceStatusReport(requestPrinterStatusDEC)`.
421
+ * @see requestPrinterStatusDEC
422
+ * @see DSR_PrinterStatusDEC
423
+ */
424
+ export declare const reportPrinterNotReadyDEC: string;
425
+ /**
426
+ * ANSI escape sequence `CSI ? 13 n` indicating Printer has No Paper (DEC-specific response).
427
+ * Typical response to {@link DSR_PrinterStatusDEC} or `deviceStatusReport(requestPrinterStatusDEC)`.
428
+ * @see requestPrinterStatusDEC
429
+ * @see DSR_PrinterStatusDEC
430
+ */
431
+ export declare const reportPrinterNoPaperDEC: string;
432
+ /**
433
+ * A DEC-specific {@link StatusReport} object to request User Defined Keys (UDK) status.
434
+ * Corresponds to DSR request `CSI ? 25 n`.
435
+ * The terminal is expected to respond with `CSI ? 20 n` (UDKs locked) or `CSI ? 21 n` (UDKs unlocked).
436
+ * @see DSR_UDKStatusDEC
437
+ * @see reportUDKLockedDEC
438
+ * @see reportUDKUnlockedDEC
439
+ */
440
+ export declare const requestUDKStatusDEC: StatusReport;
441
+ /**
442
+ * ANSI escape sequence `CSI ? 25 n` to request DEC-specific UDK status.
443
+ * This is generated using `deviceStatusReport(requestUDKStatusDEC)`.
444
+ * @see requestUDKStatusDEC
445
+ * @example
446
+ * ```typescript
447
+ * import { DSR_UDKStatusDEC } from "@visulima/ansi";
448
+ *
449
+ * process.stdout.write(DSR_UDKStatusDEC);
450
+ * ```
451
+ */
452
+ export declare const DSR_UDKStatusDEC: string;
453
+ /**
454
+ * ANSI escape sequence `CSI ? 20 n` indicating User Defined Keys (UDKs) are locked (DEC-specific response).
455
+ * Typical response to {@link DSR_UDKStatusDEC}.
456
+ */
457
+ export declare const reportUDKLockedDEC: string;
458
+ /**
459
+ * ANSI escape sequence `CSI ? 21 n` indicating User Defined Keys (UDKs) are unlocked (DEC-specific response).
460
+ * Typical response to {@link DSR_UDKStatusDEC}.
461
+ */
462
+ export declare const reportUDKUnlockedDEC: string;
463
+ /**
464
+ * A DEC-specific {@link StatusReport} object to request keyboard language status.
465
+ * This is often related to DECRQPSR (Request Presentation State Report) rather than a simple DSR with 'n'.
466
+ * For the purpose of this module, following the DSR pattern `CSI ? Ps n`.
467
+ * Corresponds to DSR request `CSI ? 26 n`.
468
+ * @see DSR_KeyboardLanguageDEC
469
+ * @see reportKeyboardLanguageDEC
470
+ */
471
+ export declare const requestKeyboardLanguageDEC: StatusReport;
472
+ /**
473
+ * ANSI escape sequence `CSI ? 26 n` to request DEC-specific keyboard language status.
474
+ * This is generated using `deviceStatusReport(requestKeyboardLanguageDEC)`.
475
+ * Note: Keyboard language reporting is complex and varies; this is a simplified DSR-style request.
476
+ * @see requestKeyboardLanguageDEC
477
+ * @see reportKeyboardLanguageDEC
478
+ * @example
479
+ * ```typescript
480
+ * import { DSR_KeyboardLanguageDEC } from "@visulima/ansi";
481
+ *
482
+ * process.stdout.write(DSR_KeyboardLanguageDEC);
483
+ * ```
484
+ */
485
+ export declare const DSR_KeyboardLanguageDEC: string;
486
+ /**
487
+ * Generates a DEC Keyboard Language Report sequence.
488
+ * This is an example of how a terminal might report its keyboard language.
489
+ * Sequence: `CSI ? Pl ; Pv n` (example format)
490
+ * - `Pl`: Parameter indicating language report (e.g., 27).
491
+ * - `Pv`: Value representing the language code.
492
+ * @param langCode The numeric code representing the keyboard language.
493
+ * @returns The keyboard language report sequence string.
494
+ * @example
495
+ * ```typescript
496
+ * import { reportKeyboardLanguageDEC } from "@visulima/ansi";
497
+ *
498
+ * console.log(reportKeyboardLanguageDEC(1));
499
+ * ```
500
+ */
501
+ export declare const reportKeyboardLanguageDEC: (langCode: number) => string;
@@ -0,0 +1,104 @@
1
+ import { S as SEP, C as CSI, D as DCS, a as ST } from './packem_shared/constants-CE7WkXh_.mjs';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ class AnsiStatusReportImpl {
6
+ constructor(reportCode) {
7
+ this.reportCode = reportCode;
8
+ }
9
+ static {
10
+ __name(this, "AnsiStatusReportImpl");
11
+ }
12
+ isDecReport = false;
13
+ }
14
+ class DecStatusReportImpl {
15
+ constructor(reportCode) {
16
+ this.reportCode = reportCode;
17
+ }
18
+ static {
19
+ __name(this, "DecStatusReportImpl");
20
+ }
21
+ isDecReport = true;
22
+ }
23
+ const createAnsiStatusReport = /* @__PURE__ */ __name((code) => new AnsiStatusReportImpl(code), "createAnsiStatusReport");
24
+ const createDecStatusReport = /* @__PURE__ */ __name((code) => new DecStatusReportImpl(code), "createDecStatusReport");
25
+ const deviceStatusReport = /* @__PURE__ */ __name((...reports) => {
26
+ if (reports.length === 0) {
27
+ return "";
28
+ }
29
+ let hasDecReport = false;
30
+ const reportCodes = reports.map((report) => {
31
+ if (report.isDecReport) {
32
+ hasDecReport = true;
33
+ }
34
+ return report.reportCode.toString();
35
+ });
36
+ let seq = CSI;
37
+ if (hasDecReport) {
38
+ seq += "?";
39
+ }
40
+ return `${seq + reportCodes.join(SEP)}n`;
41
+ }, "deviceStatusReport");
42
+ const DSR = /* @__PURE__ */ __name((report) => deviceStatusReport(report), "DSR");
43
+ const requestCursorPositionReport = `${CSI}6n`;
44
+ const requestExtendedCursorPositionReport = `${CSI}?6n`;
45
+ const cursorPositionReport = /* @__PURE__ */ __name((line, column) => {
46
+ const r = Math.max(1, line);
47
+ const c = Math.max(1, column);
48
+ return `${CSI + r.toString() + SEP + c.toString()}R`;
49
+ }, "cursorPositionReport");
50
+ const CPR = cursorPositionReport;
51
+ const extendedCursorPositionReport = /* @__PURE__ */ __name((line, column, page) => {
52
+ const r = Math.max(1, line);
53
+ const c = Math.max(1, column);
54
+ let seq = `${CSI}?`;
55
+ seq += r.toString() + SEP + c.toString();
56
+ if (page > 0) {
57
+ seq += SEP + page.toString();
58
+ }
59
+ seq += "R";
60
+ return seq;
61
+ }, "extendedCursorPositionReport");
62
+ const DECXCPR = extendedCursorPositionReport;
63
+ const RequestNameVersion = `${CSI}>0q`;
64
+ const XTVERSION = RequestNameVersion;
65
+ const requestPrimaryDeviceAttributes = `${CSI}c`;
66
+ const DA1 = requestPrimaryDeviceAttributes;
67
+ const reportPrimaryDeviceAttributes = /* @__PURE__ */ __name((...attributes) => {
68
+ if (attributes.length === 0) {
69
+ return "";
70
+ }
71
+ return `${CSI}?${attributes.join(SEP)}c`;
72
+ }, "reportPrimaryDeviceAttributes");
73
+ const requestSecondaryDeviceAttributes = `${CSI}>c`;
74
+ const DA2 = requestSecondaryDeviceAttributes;
75
+ const reportSecondaryDeviceAttributes = /* @__PURE__ */ __name((version, level, cartridge = 0) => {
76
+ const pv = Math.max(0, version);
77
+ const pl = Math.max(0, level);
78
+ const pc = Math.max(0, cartridge);
79
+ return `${CSI}>${pv}${SEP}${pl}${SEP}${pc}c`;
80
+ }, "reportSecondaryDeviceAttributes");
81
+ const requestTertiaryDeviceAttributes = `${CSI}=c`;
82
+ const DA3 = requestTertiaryDeviceAttributes;
83
+ const reportTertiaryDeviceAttributes = /* @__PURE__ */ __name((unitID) => `${DCS}!|${unitID}${ST}`, "reportTertiaryDeviceAttributes");
84
+ const requestPrimaryDeviceAttributesParam0 = `${CSI}0c`;
85
+ const requestSecondaryDeviceAttributesParam0 = `${CSI}>0c`;
86
+ const requestTertiaryDeviceAttributesParam0 = `${CSI}=0c`;
87
+ const requestTerminalStatus = createAnsiStatusReport(5);
88
+ const DSR_TerminalStatus = deviceStatusReport(requestTerminalStatus);
89
+ const reportTerminalOK = `${CSI}0n`;
90
+ const reportTerminalNotOK = `${CSI}3n`;
91
+ const requestPrinterStatusDEC = createDecStatusReport(15);
92
+ const DSR_PrinterStatusDEC = deviceStatusReport(requestPrinterStatusDEC);
93
+ const reportPrinterReadyDEC = `${CSI}?10n`;
94
+ const reportPrinterNotReadyDEC = `${CSI}?11n`;
95
+ const reportPrinterNoPaperDEC = `${CSI}?13n`;
96
+ const requestUDKStatusDEC = createDecStatusReport(25);
97
+ const DSR_UDKStatusDEC = deviceStatusReport(requestUDKStatusDEC);
98
+ const reportUDKLockedDEC = `${CSI}?20n`;
99
+ const reportUDKUnlockedDEC = `${CSI}?21n`;
100
+ const requestKeyboardLanguageDEC = createDecStatusReport(26);
101
+ const DSR_KeyboardLanguageDEC = deviceStatusReport(requestKeyboardLanguageDEC);
102
+ const reportKeyboardLanguageDEC = /* @__PURE__ */ __name((langCode) => `${CSI}?27${SEP}${langCode.toString()}n`, "reportKeyboardLanguageDEC");
103
+
104
+ export { CPR, DA1, DA2, DA3, DECXCPR, DSR, DSR_KeyboardLanguageDEC, DSR_PrinterStatusDEC, DSR_TerminalStatus, DSR_UDKStatusDEC, RequestNameVersion, XTVERSION, createAnsiStatusReport, createDecStatusReport, cursorPositionReport, deviceStatusReport, extendedCursorPositionReport, reportKeyboardLanguageDEC, reportPrimaryDeviceAttributes, reportPrinterNoPaperDEC, reportPrinterNotReadyDEC, reportPrinterReadyDEC, reportSecondaryDeviceAttributes, reportTerminalNotOK, reportTerminalOK, reportTertiaryDeviceAttributes, reportUDKLockedDEC, reportUDKUnlockedDEC, requestCursorPositionReport, requestExtendedCursorPositionReport, requestKeyboardLanguageDEC, requestPrimaryDeviceAttributes, requestPrimaryDeviceAttributesParam0, requestPrinterStatusDEC, requestSecondaryDeviceAttributes, requestSecondaryDeviceAttributesParam0, requestTerminalStatus, requestTertiaryDeviceAttributes, requestTertiaryDeviceAttributesParam0, requestUDKStatusDEC };
package/dist/strip.d.cts CHANGED
@@ -1,3 +1,25 @@
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
+ */
1
22
  declare const strip: (input: string) => string;
2
23
 
3
- export = strip;
24
+
25
+ export = strip;
package/dist/strip.d.mts CHANGED
@@ -1,3 +1,23 @@
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
+ */
1
22
  declare const strip: (input: string) => string;
2
-
3
- export { strip as default };
23
+ export default strip;
package/dist/strip.d.ts CHANGED
@@ -1,3 +1,25 @@
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
+ */
1
22
  declare const strip: (input: string) => string;
2
23
 
3
- export = strip;
24
+
25
+ export = strip;