@elench/testkit 0.1.114 → 0.1.115

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 (184) hide show
  1. package/lib/cli/assistant/app.mjs +4 -2
  2. package/lib/cli/assistant/session.mjs +5 -1
  3. package/lib/cli/assistant/state.mjs +1 -2
  4. package/lib/cli/components/blocks/run-tree.mjs +7 -2
  5. package/lib/cli/components/hooks/use-element-layout.mjs +63 -0
  6. package/lib/cli/components/hooks/use-spinner-frame.mjs +26 -0
  7. package/node_modules/@alcalzone/ansi-tokenize/README.md +0 -5
  8. package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.d.ts +8 -0
  9. package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.js +10 -8
  10. package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.js.map +1 -1
  11. package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.d.ts +1 -5
  12. package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.js +9 -45
  13. package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.js.map +1 -1
  14. package/node_modules/@alcalzone/ansi-tokenize/package.json +1 -1
  15. package/node_modules/@elench/next-analysis/package.json +1 -1
  16. package/node_modules/@elench/testkit-bridge/package.json +2 -2
  17. package/node_modules/@elench/testkit-protocol/package.json +1 -1
  18. package/node_modules/@elench/ts-analysis/package.json +1 -1
  19. package/node_modules/cli-boxes/index.d.ts +95 -90
  20. package/node_modules/cli-boxes/index.js +5 -2
  21. package/node_modules/cli-boxes/package.json +6 -13
  22. package/node_modules/cli-boxes/readme.md +15 -3
  23. package/node_modules/cli-truncate/index.d.ts +1 -1
  24. package/node_modules/cli-truncate/package.json +4 -4
  25. package/node_modules/cli-truncate/readme.md +1 -0
  26. package/node_modules/ink/build/apply-styles.js +175 -0
  27. package/node_modules/ink/build/build-layout.js +77 -0
  28. package/node_modules/ink/build/calculate-wrapped-text.js +53 -0
  29. package/node_modules/ink/build/components/App.d.ts +1 -4
  30. package/node_modules/ink/build/components/App.js +22 -142
  31. package/node_modules/ink/build/components/App.js.map +1 -1
  32. package/node_modules/ink/build/components/AppContext.d.ts +3 -23
  33. package/node_modules/ink/build/components/AppContext.js +4 -7
  34. package/node_modules/ink/build/components/AppContext.js.map +1 -1
  35. package/node_modules/ink/build/components/Box.d.ts +3 -16
  36. package/node_modules/ink/build/components/Color.js +62 -0
  37. package/node_modules/ink/build/components/Cursor.d.ts +83 -0
  38. package/node_modules/ink/build/components/Cursor.js +53 -0
  39. package/node_modules/ink/build/components/Cursor.js.map +1 -0
  40. package/node_modules/ink/build/components/ErrorBoundary.d.ts +2 -2
  41. package/node_modules/ink/build/components/ErrorOverview.js +6 -6
  42. package/node_modules/ink/build/components/ErrorOverview.js.map +1 -1
  43. package/node_modules/ink/build/components/Static.js.map +1 -1
  44. package/node_modules/ink/build/components/StdinContext.d.ts +1 -7
  45. package/node_modules/ink/build/components/StdinContext.js +0 -1
  46. package/node_modules/ink/build/components/StdinContext.js.map +1 -1
  47. package/node_modules/ink/build/components/Text.d.ts +1 -1
  48. package/node_modules/ink/build/components/Text.js +1 -1
  49. package/node_modules/ink/build/components/Text.js.map +1 -1
  50. package/node_modules/ink/build/components/Transform.d.ts +1 -1
  51. package/node_modules/ink/build/devtools-window-polyfill.js +4 -7
  52. package/node_modules/ink/build/devtools-window-polyfill.js.map +1 -1
  53. package/node_modules/ink/build/devtools.js +6 -31
  54. package/node_modules/ink/build/devtools.js.map +1 -1
  55. package/node_modules/ink/build/dom.d.ts +1 -5
  56. package/node_modules/ink/build/dom.js +1 -20
  57. package/node_modules/ink/build/dom.js.map +1 -1
  58. package/node_modules/ink/build/experimental/apply-style.js +140 -0
  59. package/node_modules/ink/build/experimental/dom.js +123 -0
  60. package/node_modules/ink/build/experimental/output.js +91 -0
  61. package/node_modules/ink/build/experimental/reconciler.js +141 -0
  62. package/node_modules/ink/build/experimental/renderer.js +81 -0
  63. package/node_modules/ink/build/hooks/use-app.d.ts +1 -1
  64. package/node_modules/ink/build/hooks/use-app.js +1 -1
  65. package/node_modules/ink/build/hooks/use-cursor.d.ts +1 -1
  66. package/node_modules/ink/build/hooks/use-cursor.js +1 -1
  67. package/node_modules/ink/build/hooks/use-focus-manager.d.ts +2 -17
  68. package/node_modules/ink/build/hooks/use-focus-manager.js +1 -2
  69. package/node_modules/ink/build/hooks/use-focus-manager.js.map +1 -1
  70. package/node_modules/ink/build/hooks/use-focus.d.ts +1 -2
  71. package/node_modules/ink/build/hooks/use-focus.js +4 -5
  72. package/node_modules/ink/build/hooks/use-focus.js.map +1 -1
  73. package/node_modules/ink/build/hooks/use-input.d.ts +1 -2
  74. package/node_modules/ink/build/hooks/use-input.js +80 -82
  75. package/node_modules/ink/build/hooks/use-input.js.map +1 -1
  76. package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.d.ts +1 -2
  77. package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.js +1 -2
  78. package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.js.map +1 -1
  79. package/node_modules/ink/build/hooks/use-stderr.d.ts +1 -1
  80. package/node_modules/ink/build/hooks/use-stderr.js +1 -1
  81. package/node_modules/ink/build/hooks/use-stdin.d.ts +2 -4
  82. package/node_modules/ink/build/hooks/use-stdin.js +1 -2
  83. package/node_modules/ink/build/hooks/use-stdin.js.map +1 -1
  84. package/node_modules/ink/build/hooks/use-stdout.d.ts +1 -1
  85. package/node_modules/ink/build/hooks/use-stdout.js +1 -1
  86. package/node_modules/ink/build/hooks/useInput.js +38 -0
  87. package/node_modules/ink/build/index.d.ts +1 -8
  88. package/node_modules/ink/build/index.js +0 -4
  89. package/node_modules/ink/build/index.js.map +1 -1
  90. package/node_modules/ink/build/ink.d.ts +3 -48
  91. package/node_modules/ink/build/ink.js +155 -325
  92. package/node_modules/ink/build/ink.js.map +1 -1
  93. package/node_modules/ink/build/input-parser.d.ts +1 -4
  94. package/node_modules/ink/build/input-parser.js +30 -70
  95. package/node_modules/ink/build/input-parser.js.map +1 -1
  96. package/node_modules/ink/build/instance.js +205 -0
  97. package/node_modules/ink/build/layout.d.ts +7 -0
  98. package/node_modules/ink/build/layout.js +33 -0
  99. package/node_modules/ink/build/layout.js.map +1 -0
  100. package/node_modules/ink/build/log-update.d.ts +0 -1
  101. package/node_modules/ink/build/log-update.js +1 -13
  102. package/node_modules/ink/build/log-update.js.map +1 -1
  103. package/node_modules/ink/build/measure-element.d.ts +0 -4
  104. package/node_modules/ink/build/measure-element.js +0 -4
  105. package/node_modules/ink/build/measure-element.js.map +1 -1
  106. package/node_modules/ink/build/options.d.ts +52 -0
  107. package/node_modules/ink/build/options.js +2 -0
  108. package/node_modules/ink/build/options.js.map +1 -0
  109. package/node_modules/ink/build/output.js +0 -25
  110. package/node_modules/ink/build/output.js.map +1 -1
  111. package/node_modules/ink/build/parse-keypress.d.ts +3 -1
  112. package/node_modules/ink/build/parse-keypress.js +17 -19
  113. package/node_modules/ink/build/parse-keypress.js.map +1 -1
  114. package/node_modules/ink/build/reconciler.js +27 -46
  115. package/node_modules/ink/build/reconciler.js.map +1 -1
  116. package/node_modules/ink/build/render-border.js +18 -29
  117. package/node_modules/ink/build/render-border.js.map +1 -1
  118. package/node_modules/ink/build/render-to-string.js +1 -2
  119. package/node_modules/ink/build/render-to-string.js.map +1 -1
  120. package/node_modules/ink/build/render.d.ts +2 -57
  121. package/node_modules/ink/build/render.js +11 -18
  122. package/node_modules/ink/build/render.js.map +1 -1
  123. package/node_modules/ink/build/screen-reader-update.d.ts +13 -0
  124. package/node_modules/ink/build/screen-reader-update.js +38 -0
  125. package/node_modules/ink/build/screen-reader-update.js.map +1 -0
  126. package/node_modules/ink/build/styles.d.ts +16 -78
  127. package/node_modules/ink/build/styles.js +31 -102
  128. package/node_modules/ink/build/styles.js.map +1 -1
  129. package/node_modules/ink/build/utils.d.ts +2 -9
  130. package/node_modules/ink/build/utils.js +3 -18
  131. package/node_modules/ink/build/utils.js.map +1 -1
  132. package/node_modules/ink/build/wrap-text.js +0 -7
  133. package/node_modules/ink/build/wrap-text.js.map +1 -1
  134. package/node_modules/ink/build/write-synchronized.d.ts +1 -1
  135. package/node_modules/ink/build/write-synchronized.js +2 -4
  136. package/node_modules/ink/build/write-synchronized.js.map +1 -1
  137. package/node_modules/ink/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
  138. package/node_modules/ink/node_modules/emoji-regex/README.md +107 -0
  139. package/node_modules/ink/node_modules/emoji-regex/index.d.ts +3 -0
  140. package/node_modules/ink/node_modules/emoji-regex/index.js +4 -0
  141. package/node_modules/ink/node_modules/emoji-regex/index.mjs +4 -0
  142. package/node_modules/ink/node_modules/emoji-regex/package.json +45 -0
  143. package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/index.d.ts +1 -1
  144. package/node_modules/ink/node_modules/wrap-ansi/index.js +222 -0
  145. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/index.d.ts +39 -0
  146. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/index.js +82 -0
  147. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/license +9 -0
  148. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/package.json +64 -0
  149. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/readme.md +66 -0
  150. package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/package.json +11 -11
  151. package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/readme.md +0 -2
  152. package/node_modules/ink/package.json +98 -34
  153. package/node_modules/ink/readme.md +48 -554
  154. package/node_modules/slice-ansi/index.d.ts +1 -1
  155. package/node_modules/slice-ansi/index.js +89 -146
  156. package/node_modules/slice-ansi/package.json +5 -5
  157. package/node_modules/slice-ansi/readme.md +0 -1
  158. package/node_modules/slice-ansi/tokenize-ansi.js +1 -1
  159. package/package.json +11 -10
  160. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.d.ts +188 -0
  161. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.d.ts.map +1 -0
  162. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.js +293 -0
  163. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.js.map +1 -0
  164. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/package.json +25 -0
  165. package/node_modules/@alcalzone/ansi-tokenize/build/consts.d.ts +0 -17
  166. package/node_modules/@alcalzone/ansi-tokenize/build/consts.js +0 -28
  167. package/node_modules/@alcalzone/ansi-tokenize/build/consts.js.map +0 -1
  168. package/node_modules/ink/build/components/AnimationContext.d.ts +0 -9
  169. package/node_modules/ink/build/components/AnimationContext.js +0 -13
  170. package/node_modules/ink/build/components/AnimationContext.js.map +0 -1
  171. package/node_modules/ink/build/hooks/use-animation.d.ts +0 -49
  172. package/node_modules/ink/build/hooks/use-animation.js +0 -87
  173. package/node_modules/ink/build/hooks/use-animation.js.map +0 -1
  174. package/node_modules/ink/build/hooks/use-box-metrics.d.ts +0 -59
  175. package/node_modules/ink/build/hooks/use-box-metrics.js +0 -88
  176. package/node_modules/ink/build/hooks/use-box-metrics.js.map +0 -1
  177. package/node_modules/ink/build/hooks/use-paste.d.ts +0 -35
  178. package/node_modules/ink/build/hooks/use-paste.js +0 -62
  179. package/node_modules/ink/build/hooks/use-paste.js.map +0 -1
  180. package/node_modules/ink/build/hooks/use-window-size.d.ts +0 -18
  181. package/node_modules/ink/build/hooks/use-window-size.js +0 -22
  182. package/node_modules/ink/build/hooks/use-window-size.js.map +0 -1
  183. package/node_modules/wrap-ansi/index.js +0 -468
  184. /package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/license +0 -0
@@ -0,0 +1,222 @@
1
+ import stringWidth from 'string-width';
2
+ import stripAnsi from 'strip-ansi';
3
+ import ansiStyles from 'ansi-styles';
4
+
5
+ const ESCAPES = new Set([
6
+ '\u001B',
7
+ '\u009B',
8
+ ]);
9
+
10
+ const END_CODE = 39;
11
+ const ANSI_ESCAPE_BELL = '\u0007';
12
+ const ANSI_CSI = '[';
13
+ const ANSI_OSC = ']';
14
+ const ANSI_SGR_TERMINATOR = 'm';
15
+ const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
16
+
17
+ const wrapAnsiCode = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
18
+ const wrapAnsiHyperlink = url => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
19
+
20
+ // Calculate the length of words split on ' ', ignoring
21
+ // the extra characters added by ansi escape codes
22
+ const wordLengths = string => string.split(' ').map(character => stringWidth(character));
23
+
24
+ // Wrap a long word across multiple rows
25
+ // Ansi escape codes do not count towards length
26
+ const wrapWord = (rows, word, columns) => {
27
+ const characters = [...word];
28
+
29
+ let isInsideEscape = false;
30
+ let isInsideLinkEscape = false;
31
+ let visible = stringWidth(stripAnsi(rows.at(-1)));
32
+
33
+ for (const [index, character] of characters.entries()) {
34
+ const characterLength = stringWidth(character);
35
+
36
+ if (visible + characterLength <= columns) {
37
+ rows[rows.length - 1] += character;
38
+ } else {
39
+ rows.push(character);
40
+ visible = 0;
41
+ }
42
+
43
+ if (ESCAPES.has(character)) {
44
+ isInsideEscape = true;
45
+
46
+ const ansiEscapeLinkCandidate = characters.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join('');
47
+ isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
48
+ }
49
+
50
+ if (isInsideEscape) {
51
+ if (isInsideLinkEscape) {
52
+ if (character === ANSI_ESCAPE_BELL) {
53
+ isInsideEscape = false;
54
+ isInsideLinkEscape = false;
55
+ }
56
+ } else if (character === ANSI_SGR_TERMINATOR) {
57
+ isInsideEscape = false;
58
+ }
59
+
60
+ continue;
61
+ }
62
+
63
+ visible += characterLength;
64
+
65
+ if (visible === columns && index < characters.length - 1) {
66
+ rows.push('');
67
+ visible = 0;
68
+ }
69
+ }
70
+
71
+ // It's possible that the last row we copy over is only
72
+ // ansi escape characters, handle this edge-case
73
+ if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
74
+ rows[rows.length - 2] += rows.pop();
75
+ }
76
+ };
77
+
78
+ // Trims spaces from a string ignoring invisible sequences
79
+ const stringVisibleTrimSpacesRight = string => {
80
+ const words = string.split(' ');
81
+ let last = words.length;
82
+
83
+ while (last > 0) {
84
+ if (stringWidth(words[last - 1]) > 0) {
85
+ break;
86
+ }
87
+
88
+ last--;
89
+ }
90
+
91
+ if (last === words.length) {
92
+ return string;
93
+ }
94
+
95
+ return words.slice(0, last).join(' ') + words.slice(last).join('');
96
+ };
97
+
98
+ // The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode.
99
+ //
100
+ // 'hard' will never allow a string to take up more than columns characters.
101
+ //
102
+ // 'soft' allows long words to expand past the column length.
103
+ const exec = (string, columns, options = {}) => {
104
+ if (options.trim !== false && string.trim() === '') {
105
+ return '';
106
+ }
107
+
108
+ let returnValue = '';
109
+ let escapeCode;
110
+ let escapeUrl;
111
+
112
+ const lengths = wordLengths(string);
113
+ let rows = [''];
114
+
115
+ for (const [index, word] of string.split(' ').entries()) {
116
+ if (options.trim !== false) {
117
+ rows[rows.length - 1] = rows.at(-1).trimStart();
118
+ }
119
+
120
+ let rowLength = stringWidth(rows.at(-1));
121
+
122
+ if (index !== 0) {
123
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
124
+ // If we start with a new word but the current row length equals the length of the columns, add a new row
125
+ rows.push('');
126
+ rowLength = 0;
127
+ }
128
+
129
+ if (rowLength > 0 || options.trim === false) {
130
+ rows[rows.length - 1] += ' ';
131
+ rowLength++;
132
+ }
133
+ }
134
+
135
+ // In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
136
+ if (options.hard && lengths[index] > columns) {
137
+ const remainingColumns = (columns - rowLength);
138
+ const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
139
+ const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
140
+ if (breaksStartingNextLine < breaksStartingThisLine) {
141
+ rows.push('');
142
+ }
143
+
144
+ wrapWord(rows, word, columns);
145
+ continue;
146
+ }
147
+
148
+ if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
149
+ if (options.wordWrap === false && rowLength < columns) {
150
+ wrapWord(rows, word, columns);
151
+ continue;
152
+ }
153
+
154
+ rows.push('');
155
+ }
156
+
157
+ if (rowLength + lengths[index] > columns && options.wordWrap === false) {
158
+ wrapWord(rows, word, columns);
159
+ continue;
160
+ }
161
+
162
+ rows[rows.length - 1] += word;
163
+ }
164
+
165
+ if (options.trim !== false) {
166
+ rows = rows.map(row => stringVisibleTrimSpacesRight(row));
167
+ }
168
+
169
+ const preString = rows.join('\n');
170
+ const pre = [...preString];
171
+
172
+ // We need to keep a separate index as `String#slice()` works on Unicode code units, while `pre` is an array of codepoints.
173
+ let preStringIndex = 0;
174
+
175
+ for (const [index, character] of pre.entries()) {
176
+ returnValue += character;
177
+
178
+ if (ESCAPES.has(character)) {
179
+ const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(preString.slice(preStringIndex)) || {groups: {}};
180
+ if (groups.code !== undefined) {
181
+ const code = Number.parseFloat(groups.code);
182
+ escapeCode = code === END_CODE ? undefined : code;
183
+ } else if (groups.uri !== undefined) {
184
+ escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
185
+ }
186
+ }
187
+
188
+ const code = ansiStyles.codes.get(Number(escapeCode));
189
+
190
+ if (pre[index + 1] === '\n') {
191
+ if (escapeUrl) {
192
+ returnValue += wrapAnsiHyperlink('');
193
+ }
194
+
195
+ if (escapeCode && code) {
196
+ returnValue += wrapAnsiCode(code);
197
+ }
198
+ } else if (character === '\n') {
199
+ if (escapeCode && code) {
200
+ returnValue += wrapAnsiCode(escapeCode);
201
+ }
202
+
203
+ if (escapeUrl) {
204
+ returnValue += wrapAnsiHyperlink(escapeUrl);
205
+ }
206
+ }
207
+
208
+ preStringIndex += character.length;
209
+ }
210
+
211
+ return returnValue;
212
+ };
213
+
214
+ // For each newline, invoke the method separately
215
+ export default function wrapAnsi(string, columns, options) {
216
+ return String(string)
217
+ .normalize()
218
+ .replaceAll('\r\n', '\n')
219
+ .split('\n')
220
+ .map(line => exec(line, columns, options))
221
+ .join('\n');
222
+ }
@@ -0,0 +1,39 @@
1
+ export type Options = {
2
+ /**
3
+ Count [ambiguous width characters](https://www.unicode.org/reports/tr11/#Ambiguous) as having narrow width (count of 1) instead of wide width (count of 2).
4
+
5
+ @default true
6
+
7
+ > Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
8
+ > - http://www.unicode.org/reports/tr11/
9
+ */
10
+ readonly ambiguousIsNarrow?: boolean;
11
+
12
+ /**
13
+ Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted.
14
+
15
+ @default false
16
+ */
17
+ readonly countAnsiEscapeCodes?: boolean;
18
+ };
19
+
20
+ /**
21
+ Get the visual width of a string - the number of columns required to display it.
22
+
23
+ Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
24
+
25
+ @example
26
+ ```
27
+ import stringWidth from 'string-width';
28
+
29
+ stringWidth('a');
30
+ //=> 1
31
+
32
+ stringWidth('古');
33
+ //=> 2
34
+
35
+ stringWidth('\u001B[1m古\u001B[22m');
36
+ //=> 2
37
+ ```
38
+ */
39
+ export default function stringWidth(string: string, options?: Options): number;
@@ -0,0 +1,82 @@
1
+ import stripAnsi from 'strip-ansi';
2
+ import {eastAsianWidth} from 'get-east-asian-width';
3
+ import emojiRegex from 'emoji-regex';
4
+
5
+ const segmenter = new Intl.Segmenter();
6
+
7
+ const defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
8
+
9
+ export default function stringWidth(string, options = {}) {
10
+ if (typeof string !== 'string' || string.length === 0) {
11
+ return 0;
12
+ }
13
+
14
+ const {
15
+ ambiguousIsNarrow = true,
16
+ countAnsiEscapeCodes = false,
17
+ } = options;
18
+
19
+ if (!countAnsiEscapeCodes) {
20
+ string = stripAnsi(string);
21
+ }
22
+
23
+ if (string.length === 0) {
24
+ return 0;
25
+ }
26
+
27
+ let width = 0;
28
+ const eastAsianWidthOptions = {ambiguousAsWide: !ambiguousIsNarrow};
29
+
30
+ for (const {segment: character} of segmenter.segment(string)) {
31
+ const codePoint = character.codePointAt(0);
32
+
33
+ // Ignore control characters
34
+ if (codePoint <= 0x1F || (codePoint >= 0x7F && codePoint <= 0x9F)) {
35
+ continue;
36
+ }
37
+
38
+ // Ignore zero-width characters
39
+ if (
40
+ (codePoint >= 0x20_0B && codePoint <= 0x20_0F) // Zero-width space, non-joiner, joiner, left-to-right mark, right-to-left mark
41
+ || codePoint === 0xFE_FF // Zero-width no-break space
42
+ ) {
43
+ continue;
44
+ }
45
+
46
+ // Ignore combining characters
47
+ if (
48
+ (codePoint >= 0x3_00 && codePoint <= 0x3_6F) // Combining diacritical marks
49
+ || (codePoint >= 0x1A_B0 && codePoint <= 0x1A_FF) // Combining diacritical marks extended
50
+ || (codePoint >= 0x1D_C0 && codePoint <= 0x1D_FF) // Combining diacritical marks supplement
51
+ || (codePoint >= 0x20_D0 && codePoint <= 0x20_FF) // Combining diacritical marks for symbols
52
+ || (codePoint >= 0xFE_20 && codePoint <= 0xFE_2F) // Combining half marks
53
+ ) {
54
+ continue;
55
+ }
56
+
57
+ // Ignore surrogate pairs
58
+ if (codePoint >= 0xD8_00 && codePoint <= 0xDF_FF) {
59
+ continue;
60
+ }
61
+
62
+ // Ignore variation selectors
63
+ if (codePoint >= 0xFE_00 && codePoint <= 0xFE_0F) {
64
+ continue;
65
+ }
66
+
67
+ // This covers some of the above cases, but we still keep them for performance reasons.
68
+ if (defaultIgnorableCodePointRegex.test(character)) {
69
+ continue;
70
+ }
71
+
72
+ // TODO: Use `/\p{RGI_Emoji}/v` when targeting Node.js 20.
73
+ if (emojiRegex().test(character)) {
74
+ width += 2;
75
+ continue;
76
+ }
77
+
78
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
79
+ }
80
+
81
+ return width;
82
+ }
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "string-width",
3
+ "version": "7.2.0",
4
+ "description": "Get the visual width of a string - the number of columns required to display it",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/string-width",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "author": {
9
+ "name": "Sindre Sorhus",
10
+ "email": "sindresorhus@gmail.com",
11
+ "url": "https://sindresorhus.com"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.js"
17
+ },
18
+ "sideEffects": false,
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "scripts": {
23
+ "test": "xo && ava && tsd"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "index.d.ts"
28
+ ],
29
+ "keywords": [
30
+ "string",
31
+ "character",
32
+ "unicode",
33
+ "width",
34
+ "visual",
35
+ "column",
36
+ "columns",
37
+ "fullwidth",
38
+ "full-width",
39
+ "full",
40
+ "ansi",
41
+ "escape",
42
+ "codes",
43
+ "cli",
44
+ "command-line",
45
+ "terminal",
46
+ "console",
47
+ "cjk",
48
+ "chinese",
49
+ "japanese",
50
+ "korean",
51
+ "fixed-width",
52
+ "east-asian-width"
53
+ ],
54
+ "dependencies": {
55
+ "emoji-regex": "^10.3.0",
56
+ "get-east-asian-width": "^1.0.0",
57
+ "strip-ansi": "^7.1.0"
58
+ },
59
+ "devDependencies": {
60
+ "ava": "^5.3.1",
61
+ "tsd": "^0.29.0",
62
+ "xo": "^0.56.0"
63
+ }
64
+ }
@@ -0,0 +1,66 @@
1
+ # string-width
2
+
3
+ > Get the visual width of a string - the number of columns required to display it
4
+
5
+ Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
6
+
7
+ Useful to be able to measure the actual width of command-line output.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install string-width
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import stringWidth from 'string-width';
19
+
20
+ stringWidth('a');
21
+ //=> 1
22
+
23
+ stringWidth('古');
24
+ //=> 2
25
+
26
+ stringWidth('\u001B[1m古\u001B[22m');
27
+ //=> 2
28
+ ```
29
+
30
+ ## API
31
+
32
+ ### stringWidth(string, options?)
33
+
34
+ #### string
35
+
36
+ Type: `string`
37
+
38
+ The string to be counted.
39
+
40
+ #### options
41
+
42
+ Type: `object`
43
+
44
+ ##### ambiguousIsNarrow
45
+
46
+ Type: `boolean`\
47
+ Default: `true`
48
+
49
+ Count [ambiguous width characters](https://www.unicode.org/reports/tr11/#Ambiguous) as having narrow width (count of 1) instead of wide width (count of 2).
50
+
51
+ > Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). **If the context cannot be established reliably, they should be treated as narrow characters by default.**
52
+ > - http://www.unicode.org/reports/tr11/
53
+
54
+ ##### countAnsiEscapeCodes
55
+
56
+ Type: `boolean`\
57
+ Default: `false`
58
+
59
+ Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted.
60
+
61
+ ## Related
62
+
63
+ - [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
64
+ - [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
65
+ - [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
66
+ - [get-east-asian-width](https://github.com/sindresorhus/get-east-asian-width) - Determine the East Asian Width of a Unicode character
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrap-ansi",
3
- "version": "10.0.0",
3
+ "version": "9.0.2",
4
4
  "description": "Wordwrap a string with ANSI escape codes",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/wrap-ansi",
@@ -16,7 +16,7 @@
16
16
  "default": "./index.js"
17
17
  },
18
18
  "engines": {
19
- "node": ">=20"
19
+ "node": ">=18"
20
20
  },
21
21
  "scripts": {
22
22
  "test": "xo && nyc ava && tsd"
@@ -53,17 +53,17 @@
53
53
  "text"
54
54
  ],
55
55
  "dependencies": {
56
- "ansi-styles": "^6.2.3",
57
- "string-width": "^8.2.0",
58
- "strip-ansi": "^7.1.2"
56
+ "ansi-styles": "^6.2.1",
57
+ "string-width": "^7.0.0",
58
+ "strip-ansi": "^7.1.0"
59
59
  },
60
60
  "devDependencies": {
61
- "ava": "^6.4.1",
62
- "chalk": "^5.6.2",
61
+ "ava": "^5.3.1",
62
+ "chalk": "^5.3.0",
63
63
  "coveralls": "^3.1.1",
64
- "has-ansi": "^6.0.2",
65
- "nyc": "^17.1.0",
66
- "tsd": "^0.33.0",
67
- "xo": "^1.2.3"
64
+ "has-ansi": "^5.0.1",
65
+ "nyc": "^15.1.0",
66
+ "tsd": "^0.29.0",
67
+ "xo": "^0.56.0"
68
68
  }
69
69
  }
@@ -36,8 +36,6 @@ A string with ANSI escape codes, like one styled by [`chalk`](https://github.com
36
36
 
37
37
  Newline characters will be normalized to `\n`.
38
38
 
39
- Tab characters are expanded to spaces using 8-column tab stops before wrapping.
40
-
41
39
  #### columns
42
40
 
43
41
  Type: `number`