@node-core/utils 7.1.0 → 7.2.1

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 (232) hide show
  1. package/components/metadata.js +2 -1
  2. package/lib/ci/build-types/test_build.js +3 -3
  3. package/lib/ci/failure_aggregator.js +2 -2
  4. package/lib/ci/run_ci.js +3 -2
  5. package/lib/cli.js +6 -6
  6. package/lib/figures.js +6 -6
  7. package/lib/prepare_security.js +20 -21
  8. package/lib/request.js +1 -1
  9. package/lib/update-v8/backport.js +3 -4
  10. package/lib/utils.js +4 -2
  11. package/lib/verbosity.js +2 -4
  12. package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/README.md +4 -4
  13. package/node_modules/@listr2/prompt-adapter-inquirer/dist/index.d.mts +21 -0
  14. package/node_modules/@listr2/prompt-adapter-inquirer/dist/index.mjs +46 -0
  15. package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/LICENSE +22 -0
  16. package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/index.d.ts +2 -0
  17. package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/index.js +2 -0
  18. package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/inquirer.d.ts +35 -0
  19. package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/inquirer.js +1 -0
  20. package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/utils.d.ts +34 -0
  21. package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/utils.js +2 -0
  22. package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/package.json +88 -0
  23. package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/package.json +25 -20
  24. package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/base.d.ts +48 -3
  25. package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/base.js +58 -19
  26. package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/package.json +1 -1
  27. package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/readme.md +36 -1
  28. package/node_modules/ansi-regex/index.js +9 -4
  29. package/node_modules/ansi-regex/package.json +1 -1
  30. package/node_modules/ansi-regex/readme.md +6 -0
  31. package/node_modules/ansi-styles/index.d.ts +12 -12
  32. package/node_modules/ansi-styles/index.js +3 -3
  33. package/node_modules/ansi-styles/package.json +4 -4
  34. package/node_modules/cli-truncate/index.d.ts +3 -3
  35. package/node_modules/cli-truncate/index.js +40 -14
  36. package/node_modules/cli-truncate/node_modules/string-width/index.js +133 -15
  37. package/node_modules/cli-truncate/node_modules/string-width/package.json +4 -4
  38. package/node_modules/cli-truncate/node_modules/string-width/readme.md +1 -1
  39. package/node_modules/cli-truncate/package.json +7 -7
  40. package/node_modules/cli-truncate/readme.md +2 -3
  41. package/node_modules/ghauth/.github/dependabot.yml +11 -3
  42. package/node_modules/ghauth/.github/workflows/depsound.yml +33 -0
  43. package/node_modules/ghauth/.github/workflows/test-and-release.yml +4 -4
  44. package/node_modules/ghauth/CHANGELOG.md +60 -0
  45. package/node_modules/ghauth/package.json +30 -6
  46. package/node_modules/js-yaml/README.md +20 -187
  47. package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs +1008 -946
  48. package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs.map +1 -1
  49. package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js +29 -23
  50. package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js.map +1 -1
  51. package/node_modules/js-yaml/dist/js-yaml.cjs.js +1043 -583
  52. package/node_modules/js-yaml/dist/js-yaml.cjs.js.map +1 -1
  53. package/node_modules/js-yaml/dist/js-yaml.d.ts +877 -133
  54. package/node_modules/js-yaml/dist/js-yaml.mjs +995 -556
  55. package/node_modules/js-yaml/dist/js-yaml.mjs.map +1 -1
  56. package/node_modules/js-yaml/package.json +8 -7
  57. package/node_modules/listr2/dist/{index.d.cts → index.d.mts} +90 -60
  58. package/node_modules/listr2/dist/{index.js → index.mjs} +496 -373
  59. package/node_modules/listr2/node_modules/string-width/index.d.ts +39 -0
  60. package/node_modules/listr2/node_modules/string-width/index.js +207 -0
  61. package/node_modules/listr2/node_modules/string-width/package.json +65 -0
  62. package/node_modules/listr2/node_modules/string-width/readme.md +66 -0
  63. package/node_modules/listr2/node_modules/wrap-ansi/index.d.ts +1 -1
  64. package/node_modules/listr2/node_modules/wrap-ansi/index.js +544 -116
  65. package/node_modules/listr2/node_modules/wrap-ansi/package.json +10 -13
  66. package/node_modules/listr2/node_modules/wrap-ansi/readme.md +2 -0
  67. package/node_modules/listr2/package.json +16 -19
  68. package/node_modules/log-update/index.d.ts +64 -1
  69. package/node_modules/log-update/index.js +268 -18
  70. package/node_modules/log-update/node_modules/string-width/index.d.ts +39 -0
  71. package/node_modules/log-update/node_modules/string-width/index.js +207 -0
  72. package/node_modules/log-update/node_modules/string-width/package.json +65 -0
  73. package/node_modules/log-update/node_modules/string-width/readme.md +66 -0
  74. package/node_modules/log-update/node_modules/wrap-ansi/index.d.ts +1 -1
  75. package/node_modules/log-update/node_modules/wrap-ansi/index.js +544 -116
  76. package/node_modules/log-update/node_modules/wrap-ansi/package.json +10 -13
  77. package/node_modules/log-update/node_modules/wrap-ansi/readme.md +2 -0
  78. package/node_modules/log-update/package.json +14 -12
  79. package/node_modules/log-update/readme.md +61 -0
  80. package/node_modules/slice-ansi/index.d.ts +2 -2
  81. package/node_modules/slice-ansi/index.js +260 -112
  82. package/node_modules/slice-ansi/package.json +10 -9
  83. package/node_modules/slice-ansi/readme.md +3 -2
  84. package/node_modules/slice-ansi/tokenize-ansi.js +752 -0
  85. package/node_modules/smol-toml/README.md +205 -191
  86. package/node_modules/smol-toml/dist/date.d.ts +0 -1
  87. package/node_modules/smol-toml/dist/date.js +0 -1
  88. package/node_modules/smol-toml/dist/error.d.ts +0 -1
  89. package/node_modules/smol-toml/dist/error.js +0 -1
  90. package/node_modules/smol-toml/dist/extract.js +32 -65
  91. package/node_modules/smol-toml/dist/index.cjs +302 -288
  92. package/node_modules/smol-toml/dist/index.d.ts +0 -1
  93. package/node_modules/smol-toml/dist/index.js +0 -1
  94. package/node_modules/smol-toml/dist/parse.d.ts +1 -3
  95. package/node_modules/smol-toml/dist/parse.js +22 -21
  96. package/node_modules/smol-toml/dist/primitive.js +75 -76
  97. package/node_modules/smol-toml/dist/stringify.d.ts +0 -1
  98. package/node_modules/smol-toml/dist/stringify.js +43 -30
  99. package/node_modules/smol-toml/dist/struct.js +90 -93
  100. package/node_modules/smol-toml/dist/util.d.ts +1 -1
  101. package/node_modules/smol-toml/dist/util.js +36 -39
  102. package/node_modules/smol-toml/package.json +6 -6
  103. package/node_modules/strip-ansi/index.js +5 -0
  104. package/node_modules/strip-ansi/package.json +5 -5
  105. package/package.json +3 -9
  106. package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.cjs +0 -127
  107. package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.d.cts +0 -152
  108. package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.d.ts +0 -152
  109. package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.js +0 -92
  110. package/node_modules/chalk/package.json +0 -92
  111. package/node_modules/chalk/readme.md +0 -331
  112. package/node_modules/chalk/source/index.d.ts +0 -437
  113. package/node_modules/chalk/source/index.js +0 -261
  114. package/node_modules/chalk/source/utilities.js +0 -33
  115. package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +0 -299
  116. package/node_modules/chalk/source/vendor/ansi-styles/index.js +0 -261
  117. package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +0 -1
  118. package/node_modules/chalk/source/vendor/supports-color/browser.js +0 -32
  119. package/node_modules/chalk/source/vendor/supports-color/index.d.ts +0 -55
  120. package/node_modules/chalk/source/vendor/supports-color/index.js +0 -206
  121. package/node_modules/colorette/LICENSE.md +0 -7
  122. package/node_modules/colorette/README.md +0 -134
  123. package/node_modules/colorette/index.cjs +0 -218
  124. package/node_modules/colorette/index.d.ts +0 -93
  125. package/node_modules/colorette/index.js +0 -150
  126. package/node_modules/colorette/package.json +0 -40
  127. package/node_modules/eventemitter3/LICENSE +0 -21
  128. package/node_modules/eventemitter3/README.md +0 -94
  129. package/node_modules/eventemitter3/dist/eventemitter3.esm.js +0 -347
  130. package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js +0 -1
  131. package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js.map +0 -1
  132. package/node_modules/eventemitter3/dist/eventemitter3.umd.js +0 -355
  133. package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js +0 -1
  134. package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js.map +0 -1
  135. package/node_modules/eventemitter3/index.d.ts +0 -135
  136. package/node_modules/eventemitter3/index.js +0 -336
  137. package/node_modules/eventemitter3/index.mjs +0 -4
  138. package/node_modules/eventemitter3/package.json +0 -67
  139. package/node_modules/figures/index.d.ts +0 -279
  140. package/node_modules/figures/index.js +0 -292
  141. package/node_modules/figures/package.json +0 -49
  142. package/node_modules/figures/readme.md +0 -337
  143. package/node_modules/isexe/LICENSE.md +0 -55
  144. package/node_modules/isexe/README.md +0 -80
  145. package/node_modules/isexe/dist/commonjs/index.d.ts +0 -14
  146. package/node_modules/isexe/dist/commonjs/index.d.ts.map +0 -1
  147. package/node_modules/isexe/dist/commonjs/index.js +0 -56
  148. package/node_modules/isexe/dist/commonjs/index.js.map +0 -1
  149. package/node_modules/isexe/dist/commonjs/index.min.js +0 -2
  150. package/node_modules/isexe/dist/commonjs/index.min.js.map +0 -7
  151. package/node_modules/isexe/dist/commonjs/options.d.ts +0 -32
  152. package/node_modules/isexe/dist/commonjs/options.d.ts.map +0 -1
  153. package/node_modules/isexe/dist/commonjs/options.js +0 -3
  154. package/node_modules/isexe/dist/commonjs/options.js.map +0 -1
  155. package/node_modules/isexe/dist/commonjs/package.json +0 -3
  156. package/node_modules/isexe/dist/commonjs/posix.d.ts +0 -18
  157. package/node_modules/isexe/dist/commonjs/posix.d.ts.map +0 -1
  158. package/node_modules/isexe/dist/commonjs/posix.js +0 -67
  159. package/node_modules/isexe/dist/commonjs/posix.js.map +0 -1
  160. package/node_modules/isexe/dist/commonjs/win32.d.ts +0 -18
  161. package/node_modules/isexe/dist/commonjs/win32.d.ts.map +0 -1
  162. package/node_modules/isexe/dist/commonjs/win32.js +0 -63
  163. package/node_modules/isexe/dist/commonjs/win32.js.map +0 -1
  164. package/node_modules/isexe/dist/esm/index.d.ts +0 -14
  165. package/node_modules/isexe/dist/esm/index.d.ts.map +0 -1
  166. package/node_modules/isexe/dist/esm/index.js +0 -16
  167. package/node_modules/isexe/dist/esm/index.js.map +0 -1
  168. package/node_modules/isexe/dist/esm/index.min.js +0 -2
  169. package/node_modules/isexe/dist/esm/index.min.js.map +0 -7
  170. package/node_modules/isexe/dist/esm/options.d.ts +0 -32
  171. package/node_modules/isexe/dist/esm/options.d.ts.map +0 -1
  172. package/node_modules/isexe/dist/esm/options.js +0 -2
  173. package/node_modules/isexe/dist/esm/options.js.map +0 -1
  174. package/node_modules/isexe/dist/esm/package.json +0 -3
  175. package/node_modules/isexe/dist/esm/posix.d.ts +0 -18
  176. package/node_modules/isexe/dist/esm/posix.d.ts.map +0 -1
  177. package/node_modules/isexe/dist/esm/posix.js +0 -62
  178. package/node_modules/isexe/dist/esm/posix.js.map +0 -1
  179. package/node_modules/isexe/dist/esm/win32.d.ts +0 -18
  180. package/node_modules/isexe/dist/esm/win32.d.ts.map +0 -1
  181. package/node_modules/isexe/dist/esm/win32.js +0 -58
  182. package/node_modules/isexe/dist/esm/win32.js.map +0 -1
  183. package/node_modules/isexe/package.json +0 -78
  184. package/node_modules/listr2/dist/index.cjs +0 -2189
  185. package/node_modules/listr2/dist/index.d.ts +0 -1528
  186. package/node_modules/rfdc/.github/workflows/ci.yml +0 -21
  187. package/node_modules/rfdc/LICENSE +0 -15
  188. package/node_modules/rfdc/default.js +0 -3
  189. package/node_modules/rfdc/index.d.ts +0 -13
  190. package/node_modules/rfdc/index.js +0 -198
  191. package/node_modules/rfdc/index.test-d.ts +0 -13
  192. package/node_modules/rfdc/package.json +0 -73
  193. package/node_modules/rfdc/readme.md +0 -181
  194. package/node_modules/rfdc/test/index.js +0 -306
  195. package/node_modules/smol-toml/dist/date.d.ts.map +0 -1
  196. package/node_modules/smol-toml/dist/date.js.map +0 -1
  197. package/node_modules/smol-toml/dist/error.d.ts.map +0 -1
  198. package/node_modules/smol-toml/dist/error.js.map +0 -1
  199. package/node_modules/smol-toml/dist/extract.js.map +0 -1
  200. package/node_modules/smol-toml/dist/index.cjs.map +0 -1
  201. package/node_modules/smol-toml/dist/index.d.ts.map +0 -1
  202. package/node_modules/smol-toml/dist/index.js.map +0 -1
  203. package/node_modules/smol-toml/dist/parse.d.ts.map +0 -1
  204. package/node_modules/smol-toml/dist/parse.js.map +0 -1
  205. package/node_modules/smol-toml/dist/primitive.d.ts +0 -29
  206. package/node_modules/smol-toml/dist/primitive.d.ts.map +0 -1
  207. package/node_modules/smol-toml/dist/primitive.js.map +0 -1
  208. package/node_modules/smol-toml/dist/stringify.d.ts.map +0 -1
  209. package/node_modules/smol-toml/dist/stringify.js.map +0 -1
  210. package/node_modules/smol-toml/dist/struct.js.map +0 -1
  211. package/node_modules/smol-toml/dist/util.d.ts.map +0 -1
  212. package/node_modules/smol-toml/dist/util.js.map +0 -1
  213. package/node_modules/smol-toml/src/date.ts +0 -152
  214. package/node_modules/smol-toml/src/error.ts +0 -77
  215. package/node_modules/smol-toml/src/extract.ts +0 -113
  216. package/node_modules/smol-toml/src/index.ts +0 -42
  217. package/node_modules/smol-toml/src/parse.ts +0 -184
  218. package/node_modules/smol-toml/src/primitive.ts +0 -249
  219. package/node_modules/smol-toml/src/stringify.ts +0 -191
  220. package/node_modules/smol-toml/src/struct.ts +0 -202
  221. package/node_modules/smol-toml/src/util.ts +0 -106
  222. package/node_modules/which/LICENSE +0 -15
  223. package/node_modules/which/README.md +0 -51
  224. package/node_modules/which/bin/which.js +0 -52
  225. package/node_modules/which/lib/index.js +0 -111
  226. package/node_modules/which/package.json +0 -52
  227. /package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/LICENSE +0 -0
  228. /package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/index.d.ts +0 -0
  229. /package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/index.js +0 -0
  230. /package/node_modules/{chalk → ansi-escapes}/license +0 -0
  231. /package/node_modules/{figures → listr2/node_modules/string-width}/license +0 -0
  232. /package/node_modules/log-update/node_modules/{ansi-escapes → string-width}/license +0 -0
@@ -200,7 +200,21 @@ Scroll display down one line.
200
200
  export const scrollDown: string;
201
201
 
202
202
  /**
203
- Clear the terminal screen. (Viewport)
203
+ Clear only the visible terminal screen (viewport) without affecting scrollback buffer or terminal state.
204
+
205
+ This is a safer alternative to `clearScreen` that works consistently across terminals.
206
+ */
207
+ export const clearViewport: string;
208
+
209
+ /**
210
+ Clear the terminal screen.
211
+
212
+ ⚠️ **Warning:** Uses RIS (Reset to Initial State) which may also:
213
+ - Clear scrollback buffer in some terminals (xterm.js, VTE)
214
+ - Reset terminal modes and state
215
+ - Not behave consistently across different terminals
216
+
217
+ Consider using `clearViewport` for safer viewport-only clearing.
204
218
  */
205
219
  export const clearScreen: string;
206
220
 
@@ -219,6 +233,21 @@ Exit the [alternative screen](https://terminalguide.namepad.de/mode/p47/), assum
219
233
  */
220
234
  export const exitAlternativeScreen: string;
221
235
 
236
+ /**
237
+ Begin [synchronized output](https://contour-terminal.org/vt-extensions/synchronized-output/) to reduce flicker during renders.
238
+ */
239
+ export const beginSynchronizedOutput: string;
240
+
241
+ /**
242
+ End [synchronized output](https://contour-terminal.org/vt-extensions/synchronized-output/).
243
+ */
244
+ export const endSynchronizedOutput: string;
245
+
246
+ /**
247
+ Wrap output in [synchronized output](https://contour-terminal.org/vt-extensions/synchronized-output/) sequences to reduce flicker during renders.
248
+ */
249
+ export function synchronizedOutput(text: string): string;
250
+
222
251
  /**
223
252
  Output a beeping sound.
224
253
  */
@@ -246,7 +275,7 @@ export const iTerm: {
246
275
 
247
276
  @param cwd - Current directory. Default: `process.cwd()`.
248
277
  */
249
- setCwd(cwd?: string): string,
278
+ setCwd(cwd?: string): string;
250
279
 
251
280
  /**
252
281
  An annotation looks like this when shown:
@@ -258,5 +287,21 @@ export const iTerm: {
258
287
  @param message - The message to display within the annotation. The `|` character is disallowed and will be stripped.
259
288
  @returns An escape code which will create an annotation when printed in iTerm2.
260
289
  */
261
- annotation(message: string, options?: AnnotationOptions): string
290
+ annotation(message: string, options?: AnnotationOptions): string;
291
+ };
292
+
293
+ export const ConEmu: {
294
+ /**
295
+ [Inform ConEmu](https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC) about shell current working directory.
296
+
297
+ @param cwd - Current directory. Default: `process.cwd()`.
298
+ */
299
+ setCwd(cwd?: string): string;
262
300
  };
301
+
302
+ /**
303
+ Set the current working directory for both iTerm2 and ConEmu.
304
+
305
+ @param cwd - Current directory. Default: `process.cwd()`.
306
+ */
307
+ export function setCwd(cwd?: string): string;
@@ -1,4 +1,5 @@
1
1
  import process from 'node:process';
2
+ import os from 'node:os';
2
3
  import {isBrowser} from 'environment';
3
4
 
4
5
  const ESC = '\u001B[';
@@ -8,11 +9,23 @@ const SEP = ';';
8
9
 
9
10
  const isTerminalApp = !isBrowser && process.env.TERM_PROGRAM === 'Apple_Terminal';
10
11
  const isWindows = !isBrowser && process.platform === 'win32';
12
+ const isTmux = !isBrowser && (process.env.TERM?.startsWith('screen') || process.env.TERM?.startsWith('tmux') || process.env.TMUX !== undefined);
11
13
 
12
14
  const cwdFunction = isBrowser ? () => {
13
15
  throw new Error('`process.cwd()` only works in Node.js, not the browser.');
14
16
  } : process.cwd;
15
17
 
18
+ const wrapOsc = sequence => {
19
+ if (isTmux) {
20
+ // Tmux requires OSC sequences to be wrapped with DCS tmux; <sequence> ST
21
+ // and all ESCs in <sequence> to be replaced with ESC ESC.
22
+ // It only accepts ESC backslash for ST.
23
+ return '\u001BPtmux;' + sequence.replaceAll('\u001B', '\u001B\u001B') + '\u001B\\';
24
+ }
25
+
26
+ return sequence;
27
+ };
28
+
16
29
  export const cursorTo = (x, y) => {
17
30
  if (typeof x !== 'number') {
18
31
  throw new TypeError('The `x` argument is required');
@@ -86,33 +99,50 @@ export const scrollDown = ESC + 'T';
86
99
 
87
100
  export const clearScreen = '\u001Bc';
88
101
 
89
- export const clearTerminal = isWindows
102
+ export const clearViewport = `${eraseScreen}${ESC}H`;
103
+
104
+ const isOldWindows = () => {
105
+ if (isBrowser || !isWindows) {
106
+ return false;
107
+ }
108
+
109
+ const parts = os.release().split('.');
110
+ const major = Number(parts[0]);
111
+ const build = Number(parts[2] ?? 0);
112
+
113
+ if (major < 10) {
114
+ return true;
115
+ }
116
+
117
+ if (major === 10 && build < 10_586) {
118
+ return true;
119
+ }
120
+
121
+ return false;
122
+ };
123
+
124
+ export const clearTerminal = isOldWindows()
90
125
  ? `${eraseScreen}${ESC}0f`
91
126
  // 1. Erases the screen (Only done in case `2` is not supported)
92
127
  // 2. Erases the whole screen including scrollback buffer
93
128
  // 3. Moves cursor to the top-left position
94
129
  // More info: https://www.real-world-systems.com/docs/ANSIcode.html
95
- : `${eraseScreen}${ESC}3J${ESC}H`;
130
+ : `${eraseScreen}${ESC}3J${ESC}H`;
96
131
 
97
132
  export const enterAlternativeScreen = ESC + '?1049h';
98
133
  export const exitAlternativeScreen = ESC + '?1049l';
99
134
 
135
+ export const beginSynchronizedOutput = ESC + '?2026h';
136
+ export const endSynchronizedOutput = ESC + '?2026l';
137
+ export const synchronizedOutput = text => beginSynchronizedOutput + text + endSynchronizedOutput;
138
+
100
139
  export const beep = BEL;
101
140
 
102
- export const link = (text, url) => [
103
- OSC,
104
- '8',
105
- SEP,
106
- SEP,
107
- url,
108
- BEL,
109
- text,
110
- OSC,
111
- '8',
112
- SEP,
113
- SEP,
114
- BEL,
115
- ].join('');
141
+ export const link = (text, url) => {
142
+ const openLink = wrapOsc(`${OSC}8${SEP}${SEP}${url}${BEL}`);
143
+ const closeLink = wrapOsc(`${OSC}8${SEP}${SEP}${BEL}`);
144
+ return openLink + text + closeLink;
145
+ };
116
146
 
117
147
  export const image = (data, options = {}) => {
118
148
  let returnValue = `${OSC}1337;File=inline=1`;
@@ -129,11 +159,14 @@ export const image = (data, options = {}) => {
129
159
  returnValue += ';preserveAspectRatio=0';
130
160
  }
131
161
 
132
- return returnValue + ':' + Buffer.from(data).toString('base64') + BEL;
162
+ const imageBuffer = Buffer.from(data);
163
+
164
+ // `size` is optional in the spec, but xterm.js requires it.
165
+ return wrapOsc(returnValue + `;size=${imageBuffer.byteLength}` + ':' + imageBuffer.toString('base64') + BEL);
133
166
  };
134
167
 
135
168
  export const iTerm = {
136
- setCwd: (cwd = cwdFunction()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
169
+ setCwd: (cwd = cwdFunction()) => wrapOsc(`${OSC}50;CurrentDir=${cwd}${BEL}`),
137
170
 
138
171
  annotation(message, options = {}) {
139
172
  let returnValue = `${OSC}1337;`;
@@ -158,6 +191,12 @@ export const iTerm = {
158
191
  returnValue += message;
159
192
  }
160
193
 
161
- return returnValue + BEL;
194
+ return wrapOsc(returnValue + BEL);
162
195
  },
163
196
  };
197
+
198
+ export const ConEmu = {
199
+ setCwd: (cwd = cwdFunction()) => wrapOsc(`${OSC}9;9;${cwd}${BEL}`),
200
+ };
201
+
202
+ export const setCwd = (cwd = cwdFunction()) => iTerm.setCwd(cwd) + ConEmu.setCwd(cwd);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ansi-escapes",
3
- "version": "7.0.0",
3
+ "version": "7.3.0",
4
4
  "description": "ANSI escape codes for manipulating the terminal",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/ansi-escapes",
@@ -134,9 +134,18 @@ Scroll display up one line.
134
134
 
135
135
  Scroll display down one line.
136
136
 
137
+ ### clearViewport
138
+
139
+ Clear only the visible terminal screen (viewport) without affecting scrollback buffer or terminal state.
140
+
141
+ This is a safer alternative to `clearScreen` that works consistently across terminals.
142
+
137
143
  ### clearScreen
138
144
 
139
- Clear the terminal screen. (Viewport)
145
+ Clear the terminal screen.
146
+
147
+ > [!WARNING]
148
+ > This uses RIS (Reset to Initial State) which may also clear scrollback buffer in some terminals (xterm.js, VTE) and reset terminal modes. Consider using `clearViewport()` for safer viewport-only clearing.
140
149
 
141
150
  ### clearTerminal
142
151
 
@@ -150,6 +159,18 @@ Enter the [alternative screen](https://terminalguide.namepad.de/mode/p47/).
150
159
 
151
160
  Exit the [alternative screen](https://terminalguide.namepad.de/mode/p47/), assuming `enterAlternativeScreen` was called before.
152
161
 
162
+ ### beginSynchronizedOutput
163
+
164
+ Begin [synchronized output](https://contour-terminal.org/vt-extensions/synchronized-output/) to reduce flicker during renders.
165
+
166
+ ### endSynchronizedOutput
167
+
168
+ End [synchronized output](https://contour-terminal.org/vt-extensions/synchronized-output/).
169
+
170
+ ### synchronizedOutput(text)
171
+
172
+ Wrap output in [synchronized output](https://contour-terminal.org/vt-extensions/synchronized-output/) sequences to reduce flicker during renders.
173
+
153
174
  ### beep
154
175
 
155
176
  Output a beeping sound.
@@ -193,6 +214,13 @@ The width and height are given as a number followed by a unit, or the word "auto
193
214
  Type: `boolean`\
194
215
  Default: `true`
195
216
 
217
+ ### setCwd(path?)
218
+
219
+ Type: `string`\
220
+ Default: `process.cwd()`
221
+
222
+ Set the current working directory for both iTerm2 and ConEmu.
223
+
196
224
  ### iTerm.setCwd(path?)
197
225
 
198
226
  Type: `string`\
@@ -200,6 +228,13 @@ Default: `process.cwd()`
200
228
 
201
229
  [Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
202
230
 
231
+ ### ConEmu.setCwd(path?)
232
+
233
+ Type: `string`\
234
+ Default: `process.cwd()`
235
+
236
+ [Inform ConEmu](https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC) about shell current working directory.
237
+
203
238
  ### iTerm.annotation(message, options?)
204
239
 
205
240
  Creates an escape code to display an "annotation" in iTerm2.
@@ -1,10 +1,15 @@
1
1
  export default function ansiRegex({onlyFirst = false} = {}) {
2
2
  // Valid string terminator sequences are BEL, ESC\, and 0x9c
3
3
  const ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)';
4
- const pattern = [
5
- `[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
6
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
7
- ].join('|');
4
+
5
+ // OSC sequences only: ESC ] ... ST
6
+ // The payload stops at the first terminator character rather than scanning ahead for one, so an unterminated `ESC ]` cannot rescan the rest of the input. Terminals likewise abort a control string on an unexpected ESC.
7
+ const osc = `(?:\\u001B\\][^\\u0007\\u001B\\u009C]*${ST})`;
8
+
9
+ // CSI and related: ESC/C1, optional intermediates, optional params (supports ; and :) then final byte
10
+ const csi = '[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]';
11
+
12
+ const pattern = `${osc}|${csi}`;
8
13
 
9
14
  return new RegExp(pattern, onlyFirst ? undefined : 'g');
10
15
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ansi-regex",
3
- "version": "6.1.0",
3
+ "version": "6.3.0",
4
4
  "description": "Regular expression for matching ANSI escape codes",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/ansi-regex",
@@ -46,6 +46,12 @@ Default: `false` *(Matches any ANSI escape codes in a string)*
46
46
 
47
47
  Match only the first ANSI escape.
48
48
 
49
+ ## Important
50
+
51
+ If you run the regex against untrusted user input in a server context, you should [give it a timeout](https://github.com/sindresorhus/super-regex).
52
+
53
+ **I do not consider [ReDoS](https://blog.yossarian.net/2022/12/28/ReDoS-vulnerabilities-and-misaligned-incentives) a valid vulnerability for this package.**
54
+
49
55
  ## FAQ
50
56
 
51
57
  ### Why do you test for codes not in the ECMA 48 standard?
@@ -1,4 +1,4 @@
1
- export interface CSPair { // eslint-disable-line @typescript-eslint/naming-convention
1
+ export type CSPair = { // eslint-disable-line @typescript-eslint/naming-convention
2
2
  /**
3
3
  The ANSI terminal control sequence for starting this style.
4
4
  */
@@ -8,9 +8,9 @@ export interface CSPair { // eslint-disable-line @typescript-eslint/naming-conve
8
8
  The ANSI terminal control sequence for ending this style.
9
9
  */
10
10
  readonly close: string;
11
- }
11
+ };
12
12
 
13
- export interface ColorBase {
13
+ export type ColorBase = {
14
14
  /**
15
15
  The ANSI terminal control sequence for ending this color.
16
16
  */
@@ -21,9 +21,9 @@ export interface ColorBase {
21
21
  ansi256(code: number): string;
22
22
 
23
23
  ansi16m(red: number, green: number, blue: number): string;
24
- }
24
+ };
25
25
 
26
- export interface Modifier {
26
+ export type Modifier = {
27
27
  /**
28
28
  Resets the current color chain.
29
29
  */
@@ -70,9 +70,9 @@ export interface Modifier {
70
70
  Puts a horizontal line through the center of the text. (Not widely supported)
71
71
  */
72
72
  readonly strikethrough: CSPair;
73
- }
73
+ };
74
74
 
75
- export interface ForegroundColor {
75
+ export type ForegroundColor = {
76
76
  readonly black: CSPair;
77
77
  readonly red: CSPair;
78
78
  readonly green: CSPair;
@@ -100,9 +100,9 @@ export interface ForegroundColor {
100
100
  readonly cyanBright: CSPair;
101
101
  readonly magentaBright: CSPair;
102
102
  readonly whiteBright: CSPair;
103
- }
103
+ };
104
104
 
105
- export interface BackgroundColor {
105
+ export type BackgroundColor = {
106
106
  readonly bgBlack: CSPair;
107
107
  readonly bgRed: CSPair;
108
108
  readonly bgGreen: CSPair;
@@ -130,9 +130,9 @@ export interface BackgroundColor {
130
130
  readonly bgCyanBright: CSPair;
131
131
  readonly bgMagentaBright: CSPair;
132
132
  readonly bgWhiteBright: CSPair;
133
- }
133
+ };
134
134
 
135
- export interface ConvertColor {
135
+ export type ConvertColor = {
136
136
  /**
137
137
  Convert from the RGB color space to the ANSI 256 color space.
138
138
 
@@ -178,7 +178,7 @@ export interface ConvertColor {
178
178
  @param hex - A hexadecimal string containing RGB data.
179
179
  */
180
180
  hexToAnsi(hex: string): number;
181
- }
181
+ };
182
182
 
183
183
  /**
184
184
  Basic modifier names.
@@ -109,7 +109,7 @@ function assembleStyles() {
109
109
  // From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
110
110
  Object.defineProperties(styles, {
111
111
  rgbToAnsi256: {
112
- value: (red, green, blue) => {
112
+ value(red, green, blue) {
113
113
  // We use the extended greyscale palette here, with the exception of
114
114
  // black and white. normal palette only has 4 greyscale shades.
115
115
  if (red === green && green === blue) {
@@ -132,7 +132,7 @@ function assembleStyles() {
132
132
  enumerable: false,
133
133
  },
134
134
  hexToRgb: {
135
- value: hex => {
135
+ value(hex) {
136
136
  const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
137
137
  if (!matches) {
138
138
  return [0, 0, 0];
@@ -161,7 +161,7 @@ function assembleStyles() {
161
161
  enumerable: false,
162
162
  },
163
163
  ansi256ToAnsi: {
164
- value: code => {
164
+ value(code) {
165
165
  if (code < 8) {
166
166
  return 30 + code;
167
167
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ansi-styles",
3
- "version": "6.2.1",
3
+ "version": "6.2.3",
4
4
  "description": "ANSI escape codes for styling strings in the terminal",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/ansi-styles",
@@ -46,9 +46,9 @@
46
46
  "text"
47
47
  ],
48
48
  "devDependencies": {
49
- "ava": "^3.15.0",
49
+ "ava": "^6.1.3",
50
50
  "svg-term-cli": "^2.1.1",
51
- "tsd": "^0.19.0",
52
- "xo": "^0.47.0"
51
+ "tsd": "^0.31.1",
52
+ "xo": "^0.58.0"
53
53
  }
54
54
  }
@@ -76,7 +76,7 @@ export type Options = {
76
76
  Truncate a string to a specific width in the terminal.
77
77
 
78
78
  @param text - The text to truncate.
79
- @param columns - The number of columns to occupy in the terminal.
79
+ @param columns - The finite number of columns to occupy in the terminal.
80
80
 
81
81
  @example
82
82
  ```
@@ -107,12 +107,12 @@ cliTruncate('안녕하세요', 3);
107
107
 
108
108
  // Truncate the paragraph to the terminal width
109
109
  const paragraph = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.';
110
- cliTruncate(paragraph, process.stdout.columns);
110
+ cliTruncate(paragraph, process.stdout.columns ?? 80);
111
111
  //=> 'Lorem ipsum dolor sit amet, consectetuer adipiscing…'
112
112
  ```
113
113
  */
114
114
  export default function cliTruncate(
115
115
  text: string,
116
116
  columns: number,
117
- options?: Options
117
+ options?: Options,
118
118
  ): string;
@@ -1,6 +1,8 @@
1
1
  import sliceAnsi from 'slice-ansi';
2
2
  import stringWidth from 'string-width';
3
3
 
4
+ const validPositions = new Set(['start', 'middle', 'end']);
5
+
4
6
  function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight) {
5
7
  if (string.charAt(wantedIndex) === ' ') {
6
8
  return wantedIndex;
@@ -18,6 +20,28 @@ function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight) {
18
20
  return wantedIndex;
19
21
  }
20
22
 
23
+ function validateInput(text, columns, position, truncationCharacter) {
24
+ if (typeof text !== 'string') {
25
+ throw new TypeError(`Expected \`input\` to be a string, got ${typeof text}`);
26
+ }
27
+
28
+ if (typeof columns !== 'number') {
29
+ throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
30
+ }
31
+
32
+ if (!Number.isFinite(columns)) {
33
+ throw new TypeError(`Expected \`columns\` to be a finite number, got ${columns}`);
34
+ }
35
+
36
+ if (!validPositions.has(position)) {
37
+ throw new TypeError(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
38
+ }
39
+
40
+ if (typeof truncationCharacter !== 'string') {
41
+ throw new TypeError(`Expected \`options.truncationCharacter\` to be a string, got ${typeof truncationCharacter}`);
42
+ }
43
+ }
44
+
21
45
  export default function cliTruncate(text, columns, options = {}) {
22
46
  const {
23
47
  position = 'end',
@@ -27,13 +51,7 @@ export default function cliTruncate(text, columns, options = {}) {
27
51
 
28
52
  let {truncationCharacter = '…'} = options;
29
53
 
30
- if (typeof text !== 'string') {
31
- throw new TypeError(`Expected \`input\` to be a string, got ${typeof text}`);
32
- }
33
-
34
- if (typeof columns !== 'number') {
35
- throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
36
- }
54
+ validateInput(text, columns, position, truncationCharacter);
37
55
 
38
56
  if (columns < 1) {
39
57
  return '';
@@ -116,7 +134,7 @@ export default function cliTruncate(text, columns, options = {}) {
116
134
 
117
135
  if (position === 'start') {
118
136
  if (preferTruncationOnSpace) {
119
- const nearestSpace = getIndexOfNearestSpace(text, length - columns + 1, true);
137
+ const nearestSpace = getIndexOfNearestSpace(text, length - columns + stringWidth(truncationCharacter), true);
120
138
  const right = sliceAnsi(text, nearestSpace, length).trim();
121
139
  return prependWithInheritedStyleFromStart(truncationCharacter, right);
122
140
  }
@@ -132,26 +150,36 @@ export default function cliTruncate(text, columns, options = {}) {
132
150
  if (position === 'middle') {
133
151
  if (space) {
134
152
  truncationCharacter = ` ${truncationCharacter} `;
153
+
154
+ // Drop the padding spaces if the padded character does not fit, so the
155
+ // truncation character itself never exceeds the budget.
156
+ if (stringWidth(truncationCharacter) >= columns) {
157
+ truncationCharacter = truncationCharacter.trim();
158
+ }
135
159
  }
136
160
 
137
- const half = Math.floor(columns / 2);
161
+ const truncationWidth = stringWidth(truncationCharacter);
162
+ // Reserve room for the truncation character before splitting the budget
163
+ // between the two sides, otherwise small budgets overflow (e.g. a width of
164
+ // 4 was returned for `columns: 2`).
165
+ const half = Math.min(Math.floor(columns / 2), Math.max(0, columns - truncationWidth));
138
166
 
139
167
  if (preferTruncationOnSpace) {
140
168
  const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
141
- const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + 1, true);
169
+ const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + truncationWidth, true);
142
170
  return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, spaceNearSecondBreakPoint, length).trim();
143
171
  }
144
172
 
145
173
  return (
146
174
  sliceAnsi(text, 0, half)
147
175
  + truncationCharacter
148
- + sliceAnsi(text, length - (columns - half) + stringWidth(truncationCharacter), length)
176
+ + sliceAnsi(text, length - (columns - half) + truncationWidth, length)
149
177
  );
150
178
  }
151
179
 
152
180
  if (position === 'end') {
153
181
  if (preferTruncationOnSpace) {
154
- const nearestSpace = getIndexOfNearestSpace(text, columns - 1);
182
+ const nearestSpace = getIndexOfNearestSpace(text, columns - stringWidth(truncationCharacter));
155
183
  const left = sliceAnsi(text, 0, nearestSpace);
156
184
  return appendWithInheritedStyleFromEnd(left, truncationCharacter);
157
185
  }
@@ -163,6 +191,4 @@ export default function cliTruncate(text, columns, options = {}) {
163
191
  const left = sliceAnsi(text, 0, columns - stringWidth(truncationCharacter));
164
192
  return appendWithInheritedStyleFromEnd(left, truncationCharacter);
165
193
  }
166
-
167
- throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
168
194
  }