@nuvin/ink 6.6.7 → 7.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ansi-tokenizer.d.ts +38 -0
- package/build/ansi-tokenizer.js +316 -0
- package/build/ansi-tokenizer.js.map +1 -0
- package/build/components/AnimationContext.d.ts +9 -0
- package/build/components/AnimationContext.js +13 -0
- package/build/components/AnimationContext.js.map +1 -0
- package/build/components/App.d.ts +11 -49
- package/build/components/App.js +412 -227
- package/build/components/App.js.map +1 -1
- package/build/components/AppContext.d.ts +33 -3
- package/build/components/AppContext.js +2 -1
- package/build/components/AppContext.js.map +1 -1
- package/build/components/Box.d.ts +15 -8
- package/build/components/Box.js +12 -10
- package/build/components/Box.js.map +1 -1
- package/build/components/CursorContext.d.ts +11 -0
- package/build/components/CursorContext.js +8 -0
- package/build/components/CursorContext.js.map +1 -0
- package/build/components/ErrorBoundary.d.ts +18 -0
- package/build/components/ErrorBoundary.js +23 -0
- package/build/components/ErrorBoundary.js.map +1 -0
- package/build/components/ErrorOverview.js +6 -6
- package/build/components/ErrorOverview.js.map +1 -1
- package/build/components/Static.js.map +1 -1
- package/build/components/StdinContext.d.ts +7 -1
- package/build/components/StdinContext.js +1 -0
- package/build/components/StdinContext.js.map +1 -1
- package/build/components/Text.d.ts +1 -1
- package/build/components/Text.js +1 -1
- package/build/components/Text.js.map +1 -1
- package/build/components/Transform.d.ts +1 -1
- package/build/cursor-helpers.d.ts +38 -0
- package/build/cursor-helpers.js +56 -0
- package/build/cursor-helpers.js.map +1 -0
- package/build/devtools-window-polyfill.js +7 -4
- package/build/devtools-window-polyfill.js.map +1 -1
- package/build/devtools.js +31 -6
- package/build/devtools.js.map +1 -1
- package/build/dom.d.ts +5 -1
- package/build/dom.js +20 -1
- package/build/dom.js.map +1 -1
- package/build/hooks/use-animation.d.ts +49 -0
- package/build/hooks/use-animation.js +87 -0
- package/build/hooks/use-animation.js.map +1 -0
- package/build/hooks/use-app.d.ts +5 -2
- package/build/hooks/use-app.js +1 -1
- package/build/hooks/use-box-metrics.d.ts +59 -0
- package/build/hooks/use-box-metrics.js +88 -0
- package/build/hooks/use-box-metrics.js.map +1 -0
- package/build/hooks/use-cursor.d.ts +12 -0
- package/build/hooks/use-cursor.js +29 -0
- package/build/hooks/use-cursor.js.map +1 -0
- package/build/hooks/use-focus-manager.d.ts +17 -2
- package/build/hooks/use-focus-manager.js +2 -1
- package/build/hooks/use-focus-manager.js.map +1 -1
- package/build/hooks/use-focus.d.ts +2 -1
- package/build/hooks/use-focus.js +5 -4
- package/build/hooks/use-focus.js.map +1 -1
- package/build/hooks/use-input.d.ts +40 -1
- package/build/hooks/use-input.js +84 -51
- package/build/hooks/use-input.js.map +1 -1
- package/build/hooks/use-is-screen-reader-enabled.d.ts +2 -1
- package/build/hooks/use-is-screen-reader-enabled.js +2 -1
- package/build/hooks/use-is-screen-reader-enabled.js.map +1 -1
- package/build/hooks/use-paste.d.ts +35 -0
- package/build/hooks/use-paste.js +62 -0
- package/build/hooks/use-paste.js.map +1 -0
- package/build/hooks/use-stderr.d.ts +1 -1
- package/build/hooks/use-stderr.js +1 -1
- package/build/hooks/use-stdin.d.ts +4 -2
- package/build/hooks/use-stdin.js +2 -1
- package/build/hooks/use-stdin.js.map +1 -1
- package/build/hooks/use-stdout.d.ts +1 -1
- package/build/hooks/use-stdout.js +1 -1
- package/build/hooks/use-window-size.d.ts +18 -0
- package/build/hooks/use-window-size.js +22 -0
- package/build/hooks/use-window-size.js.map +1 -0
- package/build/index.d.ts +14 -1
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +86 -5
- package/build/ink.js +581 -80
- package/build/ink.js.map +1 -1
- package/build/input-parser.d.ts +10 -0
- package/build/input-parser.js +194 -0
- package/build/input-parser.js.map +1 -0
- package/build/kitty-keyboard.d.ts +23 -0
- package/build/kitty-keyboard.js +32 -0
- package/build/kitty-keyboard.js.map +1 -0
- package/build/log-update.d.ts +7 -1
- package/build/log-update.js +181 -56
- package/build/log-update.js.map +1 -1
- package/build/measure-element.d.ts +4 -0
- package/build/measure-element.js +4 -0
- package/build/measure-element.js.map +1 -1
- package/build/measure-text.js +3 -11
- package/build/measure-text.js.map +1 -1
- package/build/output.d.ts +2 -1
- package/build/output.js +62 -58
- package/build/output.js.map +1 -1
- package/build/parse-keypress.d.ts +9 -3
- package/build/parse-keypress.js +283 -13
- package/build/parse-keypress.js.map +1 -1
- package/build/reconciler.js +57 -37
- package/build/reconciler.js.map +1 -1
- package/build/render-background.js +2 -0
- package/build/render-background.js.map +1 -1
- package/build/render-border.d.ts +1 -1
- package/build/render-border.js +35 -24
- package/build/render-border.js.map +1 -1
- package/build/render-node-to-output.d.ts +1 -1
- package/build/render-node-to-output.js +35 -18
- package/build/render-node-to-output.js.map +1 -1
- package/build/render-to-string.d.ts +38 -0
- package/build/render-to-string.js +116 -0
- package/build/render-to-string.js.map +1 -0
- package/build/render.d.ts +91 -3
- package/build/render.js +17 -5
- package/build/render.js.map +1 -1
- package/build/sanitize-ansi.d.ts +2 -0
- package/build/sanitize-ansi.js +27 -0
- package/build/sanitize-ansi.js.map +1 -0
- package/build/squash-text-nodes.js +2 -1
- package/build/squash-text-nodes.js.map +1 -1
- package/build/styles.d.ts +75 -37
- package/build/styles.js +87 -44
- package/build/styles.js.map +1 -1
- package/build/utils.d.ts +9 -2
- package/build/utils.js +18 -3
- package/build/utils.js.map +1 -1
- package/build/wrap-text.js +7 -14
- package/build/wrap-text.js.map +1 -1
- package/build/write-synchronized.d.ts +4 -0
- package/build/write-synchronized.js +9 -0
- package/build/write-synchronized.js.map +1 -0
- package/package.json +45 -105
- package/readme.md +850 -64
- package/build/components/FixedLayout.d.ts +0 -12
- package/build/components/FixedLayout.js +0 -19
- package/build/components/FixedLayout.js.map +0 -1
- package/build/components/VirtualizedList.d.ts +0 -21
- package/build/components/VirtualizedList.js +0 -55
- package/build/components/VirtualizedList.js.map +0 -1
- package/build/hooks/use-mouse.d.ts +0 -15
- package/build/hooks/use-mouse.js +0 -121
- package/build/hooks/use-mouse.js.map +0 -1
- package/build/hooks/use-virtualization.d.ts +0 -19
- package/build/hooks/use-virtualization.js +0 -56
- package/build/hooks/use-virtualization.js.map +0 -1
package/build/log-update.js
CHANGED
|
@@ -1,121 +1,246 @@
|
|
|
1
1
|
import ansiEscapes from 'ansi-escapes';
|
|
2
2
|
import cliCursor from 'cli-cursor';
|
|
3
|
+
import { cursorPositionChanged, buildCursorSuffix, buildCursorOnlySequence, buildReturnToBottomPrefix, hideCursorEscape, } from './cursor-helpers.js';
|
|
4
|
+
// Count visible lines in a string, ignoring the trailing empty element
|
|
5
|
+
// that `split('\n')` produces when the string ends with '\n'.
|
|
6
|
+
const visibleLineCount = (lines, str) => str.endsWith('\n') ? lines.length - 1 : lines.length;
|
|
3
7
|
const createStandard = (stream, { showCursor = false } = {}) => {
|
|
4
8
|
let previousLineCount = 0;
|
|
5
9
|
let previousOutput = '';
|
|
6
10
|
let hasHiddenCursor = false;
|
|
11
|
+
let cursorPosition;
|
|
12
|
+
let cursorDirty = false;
|
|
13
|
+
let previousCursorPosition;
|
|
14
|
+
let cursorWasShown = false;
|
|
15
|
+
const getActiveCursor = () => (cursorDirty ? cursorPosition : undefined);
|
|
16
|
+
const hasChanges = (str, activeCursor) => {
|
|
17
|
+
const cursorChanged = cursorPositionChanged(activeCursor, previousCursorPosition);
|
|
18
|
+
return str !== previousOutput || cursorChanged;
|
|
19
|
+
};
|
|
7
20
|
const render = (str) => {
|
|
8
21
|
if (!showCursor && !hasHiddenCursor) {
|
|
9
|
-
cliCursor.hide();
|
|
22
|
+
cliCursor.hide(stream);
|
|
10
23
|
hasHiddenCursor = true;
|
|
11
24
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
25
|
+
// Only use cursor if setCursorPosition was called since last render.
|
|
26
|
+
// This ensures stale positions don't persist after component unmount.
|
|
27
|
+
const activeCursor = getActiveCursor();
|
|
28
|
+
cursorDirty = false;
|
|
29
|
+
const cursorChanged = cursorPositionChanged(activeCursor, previousCursorPosition);
|
|
30
|
+
if (!hasChanges(str, activeCursor)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const lines = str.split('\n');
|
|
34
|
+
const visibleCount = visibleLineCount(lines, str);
|
|
35
|
+
const cursorSuffix = buildCursorSuffix(visibleCount, activeCursor);
|
|
36
|
+
if (str === previousOutput && cursorChanged) {
|
|
37
|
+
stream.write(buildCursorOnlySequence({
|
|
38
|
+
cursorWasShown,
|
|
39
|
+
previousLineCount,
|
|
40
|
+
previousCursorPosition,
|
|
41
|
+
visibleLineCount: visibleCount,
|
|
42
|
+
cursorPosition: activeCursor,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
previousOutput = str;
|
|
47
|
+
const returnPrefix = buildReturnToBottomPrefix(cursorWasShown, previousLineCount, previousCursorPosition);
|
|
48
|
+
stream.write(returnPrefix +
|
|
49
|
+
ansiEscapes.eraseLines(previousLineCount) +
|
|
50
|
+
str +
|
|
51
|
+
cursorSuffix);
|
|
52
|
+
previousLineCount = lines.length;
|
|
15
53
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
54
|
+
previousCursorPosition = activeCursor ? { ...activeCursor } : undefined;
|
|
55
|
+
cursorWasShown = activeCursor !== undefined;
|
|
56
|
+
return true;
|
|
19
57
|
};
|
|
20
58
|
render.clear = () => {
|
|
21
|
-
|
|
59
|
+
const prefix = buildReturnToBottomPrefix(cursorWasShown, previousLineCount, previousCursorPosition);
|
|
60
|
+
stream.write(prefix + ansiEscapes.eraseLines(previousLineCount));
|
|
22
61
|
previousOutput = '';
|
|
23
62
|
previousLineCount = 0;
|
|
63
|
+
previousCursorPosition = undefined;
|
|
64
|
+
cursorWasShown = false;
|
|
24
65
|
};
|
|
25
66
|
render.done = () => {
|
|
26
|
-
// On exit, we write a finally newline to restore the terminal prompt properly,
|
|
27
|
-
// unless the output was empty.
|
|
28
|
-
if (previousOutput.length > 0) {
|
|
29
|
-
stream.write('\n');
|
|
30
|
-
}
|
|
31
67
|
previousOutput = '';
|
|
32
68
|
previousLineCount = 0;
|
|
69
|
+
previousCursorPosition = undefined;
|
|
70
|
+
cursorWasShown = false;
|
|
33
71
|
if (!showCursor) {
|
|
34
|
-
cliCursor.show();
|
|
72
|
+
cliCursor.show(stream);
|
|
35
73
|
hasHiddenCursor = false;
|
|
36
74
|
}
|
|
37
75
|
};
|
|
76
|
+
render.reset = () => {
|
|
77
|
+
previousOutput = '';
|
|
78
|
+
previousLineCount = 0;
|
|
79
|
+
previousCursorPosition = undefined;
|
|
80
|
+
cursorWasShown = false;
|
|
81
|
+
};
|
|
38
82
|
render.sync = (str) => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
83
|
+
const activeCursor = cursorDirty ? cursorPosition : undefined;
|
|
84
|
+
cursorDirty = false;
|
|
85
|
+
const lines = str.split('\n');
|
|
86
|
+
previousOutput = str;
|
|
87
|
+
previousLineCount = lines.length;
|
|
88
|
+
if (!activeCursor && cursorWasShown) {
|
|
89
|
+
stream.write(hideCursorEscape);
|
|
90
|
+
}
|
|
91
|
+
if (activeCursor) {
|
|
92
|
+
stream.write(buildCursorSuffix(visibleLineCount(lines, str), activeCursor));
|
|
93
|
+
}
|
|
94
|
+
previousCursorPosition = activeCursor ? { ...activeCursor } : undefined;
|
|
95
|
+
cursorWasShown = activeCursor !== undefined;
|
|
96
|
+
};
|
|
97
|
+
render.setCursorPosition = (position) => {
|
|
98
|
+
cursorPosition = position;
|
|
99
|
+
cursorDirty = true;
|
|
42
100
|
};
|
|
101
|
+
render.isCursorDirty = () => cursorDirty;
|
|
102
|
+
render.willRender = (str) => hasChanges(str, getActiveCursor());
|
|
43
103
|
return render;
|
|
44
104
|
};
|
|
45
105
|
const createIncremental = (stream, { showCursor = false } = {}) => {
|
|
46
106
|
let previousLines = [];
|
|
47
107
|
let previousOutput = '';
|
|
48
108
|
let hasHiddenCursor = false;
|
|
109
|
+
let cursorPosition;
|
|
110
|
+
let cursorDirty = false;
|
|
111
|
+
let previousCursorPosition;
|
|
112
|
+
let cursorWasShown = false;
|
|
113
|
+
const getActiveCursor = () => (cursorDirty ? cursorPosition : undefined);
|
|
114
|
+
const hasChanges = (str, activeCursor) => {
|
|
115
|
+
const cursorChanged = cursorPositionChanged(activeCursor, previousCursorPosition);
|
|
116
|
+
return str !== previousOutput || cursorChanged;
|
|
117
|
+
};
|
|
49
118
|
const render = (str) => {
|
|
50
119
|
if (!showCursor && !hasHiddenCursor) {
|
|
51
|
-
cliCursor.hide();
|
|
120
|
+
cliCursor.hide(stream);
|
|
52
121
|
hasHiddenCursor = true;
|
|
53
122
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
123
|
+
// Only use cursor if setCursorPosition was called since last render.
|
|
124
|
+
// This ensures stale positions don't persist after component unmount.
|
|
125
|
+
const activeCursor = getActiveCursor();
|
|
126
|
+
cursorDirty = false;
|
|
127
|
+
const cursorChanged = cursorPositionChanged(activeCursor, previousCursorPosition);
|
|
128
|
+
if (!hasChanges(str, activeCursor)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const nextLines = str.split('\n');
|
|
132
|
+
const visibleCount = visibleLineCount(nextLines, str);
|
|
133
|
+
const previousVisible = visibleLineCount(previousLines, previousOutput);
|
|
134
|
+
if (str === previousOutput && cursorChanged) {
|
|
135
|
+
stream.write(buildCursorOnlySequence({
|
|
136
|
+
cursorWasShown,
|
|
137
|
+
previousLineCount: previousLines.length,
|
|
138
|
+
previousCursorPosition,
|
|
139
|
+
visibleLineCount: visibleCount,
|
|
140
|
+
cursorPosition: activeCursor,
|
|
141
|
+
}));
|
|
142
|
+
previousCursorPosition = activeCursor ? { ...activeCursor } : undefined;
|
|
143
|
+
cursorWasShown = activeCursor !== undefined;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
const returnPrefix = buildReturnToBottomPrefix(cursorWasShown, previousLines.length, previousCursorPosition);
|
|
147
|
+
if (str === '\n' || previousOutput.length === 0) {
|
|
148
|
+
const cursorSuffix = buildCursorSuffix(visibleCount, activeCursor);
|
|
149
|
+
stream.write(returnPrefix +
|
|
150
|
+
ansiEscapes.eraseLines(previousLines.length) +
|
|
151
|
+
str +
|
|
152
|
+
cursorSuffix);
|
|
153
|
+
cursorWasShown = activeCursor !== undefined;
|
|
154
|
+
previousCursorPosition = activeCursor ? { ...activeCursor } : undefined;
|
|
155
|
+
previousOutput = str;
|
|
65
156
|
previousLines = nextLines;
|
|
66
|
-
return;
|
|
157
|
+
return true;
|
|
67
158
|
}
|
|
159
|
+
const hasTrailingNewline = str.endsWith('\n');
|
|
68
160
|
// We aggregate all chunks for incremental rendering into a buffer, and then write them to stdout at the end.
|
|
69
161
|
const buffer = [];
|
|
162
|
+
buffer.push(returnPrefix);
|
|
70
163
|
// Clear extra lines if the current content's line count is lower than the previous.
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
ansiEscapes.eraseLines(
|
|
75
|
-
// Positions cursor to the top of the rendered output.
|
|
76
|
-
ansiEscapes.cursorUp(nextCount));
|
|
164
|
+
if (visibleCount < previousVisible) {
|
|
165
|
+
const previousHadTrailingNewline = previousOutput.endsWith('\n');
|
|
166
|
+
const extraSlot = previousHadTrailingNewline ? 1 : 0;
|
|
167
|
+
buffer.push(ansiEscapes.eraseLines(previousVisible - visibleCount + extraSlot), ansiEscapes.cursorUp(visibleCount));
|
|
77
168
|
}
|
|
78
169
|
else {
|
|
79
|
-
buffer.push(ansiEscapes.cursorUp(
|
|
170
|
+
buffer.push(ansiEscapes.cursorUp(previousLines.length - 1));
|
|
80
171
|
}
|
|
81
172
|
for (let i = 0; i < visibleCount; i++) {
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
buffer.push(contentChanged ? '\n' : ansiEscapes.cursorNextLine);
|
|
173
|
+
const isLastLine = i === visibleCount - 1;
|
|
174
|
+
// We do not write lines if the contents are the same. This prevents flickering during renders.
|
|
175
|
+
if (nextLines[i] === previousLines[i]) {
|
|
176
|
+
// Don't move past the last line when there's no trailing newline,
|
|
177
|
+
// otherwise the cursor overshoots the rendered block.
|
|
178
|
+
if (!isLastLine || hasTrailingNewline) {
|
|
179
|
+
buffer.push(ansiEscapes.cursorNextLine);
|
|
180
|
+
}
|
|
181
|
+
continue;
|
|
92
182
|
}
|
|
183
|
+
buffer.push(ansiEscapes.cursorTo(0) +
|
|
184
|
+
nextLines[i] +
|
|
185
|
+
ansiEscapes.eraseEndLine +
|
|
186
|
+
// Don't append newline after the last line when the input
|
|
187
|
+
// has no trailing newline (fullscreen mode).
|
|
188
|
+
(isLastLine && !hasTrailingNewline ? '' : '\n'));
|
|
93
189
|
}
|
|
190
|
+
const cursorSuffix = buildCursorSuffix(visibleCount, activeCursor);
|
|
191
|
+
buffer.push(cursorSuffix);
|
|
94
192
|
stream.write(buffer.join(''));
|
|
95
|
-
|
|
193
|
+
cursorWasShown = activeCursor !== undefined;
|
|
194
|
+
previousCursorPosition = activeCursor ? { ...activeCursor } : undefined;
|
|
195
|
+
previousOutput = str;
|
|
96
196
|
previousLines = nextLines;
|
|
197
|
+
return true;
|
|
97
198
|
};
|
|
98
199
|
render.clear = () => {
|
|
99
|
-
|
|
200
|
+
const prefix = buildReturnToBottomPrefix(cursorWasShown, previousLines.length, previousCursorPosition);
|
|
201
|
+
stream.write(prefix + ansiEscapes.eraseLines(previousLines.length));
|
|
100
202
|
previousOutput = '';
|
|
101
203
|
previousLines = [];
|
|
204
|
+
previousCursorPosition = undefined;
|
|
205
|
+
cursorWasShown = false;
|
|
102
206
|
};
|
|
103
207
|
render.done = () => {
|
|
104
|
-
if (previousOutput.length > 0) {
|
|
105
|
-
stream.write('\n');
|
|
106
|
-
}
|
|
107
208
|
previousOutput = '';
|
|
108
209
|
previousLines = [];
|
|
210
|
+
previousCursorPosition = undefined;
|
|
211
|
+
cursorWasShown = false;
|
|
109
212
|
if (!showCursor) {
|
|
110
|
-
cliCursor.show();
|
|
213
|
+
cliCursor.show(stream);
|
|
111
214
|
hasHiddenCursor = false;
|
|
112
215
|
}
|
|
113
216
|
};
|
|
217
|
+
render.reset = () => {
|
|
218
|
+
previousOutput = '';
|
|
219
|
+
previousLines = [];
|
|
220
|
+
previousCursorPosition = undefined;
|
|
221
|
+
cursorWasShown = false;
|
|
222
|
+
};
|
|
114
223
|
render.sync = (str) => {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
224
|
+
const activeCursor = cursorDirty ? cursorPosition : undefined;
|
|
225
|
+
cursorDirty = false;
|
|
226
|
+
const lines = str.split('\n');
|
|
227
|
+
previousOutput = str;
|
|
228
|
+
previousLines = lines;
|
|
229
|
+
if (!activeCursor && cursorWasShown) {
|
|
230
|
+
stream.write(hideCursorEscape);
|
|
231
|
+
}
|
|
232
|
+
if (activeCursor) {
|
|
233
|
+
stream.write(buildCursorSuffix(visibleLineCount(lines, str), activeCursor));
|
|
234
|
+
}
|
|
235
|
+
previousCursorPosition = activeCursor ? { ...activeCursor } : undefined;
|
|
236
|
+
cursorWasShown = activeCursor !== undefined;
|
|
237
|
+
};
|
|
238
|
+
render.setCursorPosition = (position) => {
|
|
239
|
+
cursorPosition = position;
|
|
240
|
+
cursorDirty = true;
|
|
118
241
|
};
|
|
242
|
+
render.isCursorDirty = () => cursorDirty;
|
|
243
|
+
render.willRender = (str) => hasChanges(str, getActiveCursor());
|
|
119
244
|
return render;
|
|
120
245
|
};
|
|
121
246
|
const create = (stream, { showCursor = false, incremental = false } = {}) => {
|
package/build/log-update.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-update.js","sourceRoot":"","sources":["../src/log-update.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,SAAS,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"log-update.js","sourceRoot":"","sources":["../src/log-update.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAEN,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,EACzB,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAe7B,uEAAuE;AACvE,8DAA8D;AAC9D,MAAM,gBAAgB,GAAG,CAAC,KAAe,EAAE,GAAW,EAAU,EAAE,CACjE,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;AAEtD,MAAM,cAAc,GAAG,CACtB,MAAgB,EAChB,EAAC,UAAU,GAAG,KAAK,EAAC,GAAG,EAAE,EACb,EAAE;IACd,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,IAAI,cAAc,GAAG,EAAE,CAAC;IACxB,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,IAAI,cAA0C,CAAC;IAC/C,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,sBAAkD,CAAC;IACvD,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACzE,MAAM,UAAU,GAAG,CAClB,GAAW,EACX,YAAwC,EAC9B,EAAE;QACZ,MAAM,aAAa,GAAG,qBAAqB,CAC1C,YAAY,EACZ,sBAAsB,CACtB,CAAC;QACF,OAAO,GAAG,KAAK,cAAc,IAAI,aAAa,CA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
11
11
|
};
|
|
12
12
|
/**
|
|
13
13
|
Measure the dimensions of a particular `<Box>` element.
|
|
14
|
+
Returns an object with `width` and `height` properties.
|
|
15
|
+
This function is useful when your component needs to know the amount of available space it has. You can use it when you need to change the layout based on the length of its content.
|
|
16
|
+
|
|
17
|
+
Note: `measureElement()` returns `{width: 0, height: 0}` when called during render (before layout is calculated). Call it from post-render code, such as `useEffect`, `useLayoutEffect`, input handlers, or timer callbacks. When content changes, pass the relevant dependency to your effect so it re-measures after each update.
|
|
14
18
|
*/
|
|
15
19
|
declare const measureElement: (node: DOMElement) => Output;
|
|
16
20
|
export default measureElement;
|
package/build/measure-element.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Measure the dimensions of a particular `<Box>` element.
|
|
3
|
+
Returns an object with `width` and `height` properties.
|
|
4
|
+
This function is useful when your component needs to know the amount of available space it has. You can use it when you need to change the layout based on the length of its content.
|
|
5
|
+
|
|
6
|
+
Note: `measureElement()` returns `{width: 0, height: 0}` when called during render (before layout is calculated). Call it from post-render code, such as `useEffect`, `useLayoutEffect`, input handlers, or timer callbacks. When content changes, pass the relevant dependency to your effect so it re-measures after each update.
|
|
3
7
|
*/
|
|
4
8
|
const measureElement = (node) => ({
|
|
5
9
|
width: node.yogaNode?.getComputedWidth() ?? 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure-element.js","sourceRoot":"","sources":["../src/measure-element.ts"],"names":[],"mappings":"AAcA
|
|
1
|
+
{"version":3,"file":"measure-element.js","sourceRoot":"","sources":["../src/measure-element.ts"],"names":[],"mappings":"AAcA;;;;;;EAME;AACF,MAAM,cAAc,GAAG,CAAC,IAAgB,EAAU,EAAE,CAAC,CAAC;IACrD,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC;IAC7C,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,CAAC;CAC/C,CAAC,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
package/build/measure-text.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import widestLine from 'widest-line';
|
|
2
2
|
const cache = new Map();
|
|
3
|
-
const TAB_SPACES = ' '; // 2 spaces per tab
|
|
4
3
|
const measureText = (text) => {
|
|
5
4
|
if (text.length === 0) {
|
|
6
5
|
return {
|
|
@@ -12,15 +11,8 @@ const measureText = (text) => {
|
|
|
12
11
|
if (cachedDimensions) {
|
|
13
12
|
return cachedDimensions;
|
|
14
13
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
// If width is > 0, add a tiny epsilon to prevent Yoga from wrapping
|
|
18
|
-
// items with exact integer width (like 1) in some flexbox configurations.
|
|
19
|
-
// This fixes a layout regression where items would wrap unexpectedly.
|
|
20
|
-
if (width > 0) {
|
|
21
|
-
width += 0.01;
|
|
22
|
-
}
|
|
23
|
-
const height = lines.length;
|
|
14
|
+
const width = widestLine(text);
|
|
15
|
+
const height = text.split('\n').length;
|
|
24
16
|
const dimensions = { width, height };
|
|
25
17
|
cache.set(text, dimensions);
|
|
26
18
|
return dimensions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure-text.js","sourceRoot":"","sources":["../src/measure-text.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"measure-text.js","sourceRoot":"","sources":["../src/measure-text.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;AAOxC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE;IAC5C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO;YACN,KAAK,EAAE,CAAC;YACR,MAAM,EAAE,CAAC;SACT,CAAC;IACH,CAAC;IAED,MAAM,gBAAgB,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEzC,IAAI,gBAAgB,EAAE,CAAC;QACtB,OAAO,gBAAgB,CAAC;IACzB,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IACvC,MAAM,UAAU,GAAG,EAAC,KAAK,EAAE,MAAM,EAAC,CAAC;IACnC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAE5B,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/build/output.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type OutputTransformer } from './render-node-to-output.js';
|
|
2
2
|
/**
|
|
3
3
|
"Virtual" output class
|
|
4
4
|
|
|
@@ -20,6 +20,7 @@ export default class Output {
|
|
|
20
20
|
width: number;
|
|
21
21
|
height: number;
|
|
22
22
|
private readonly operations;
|
|
23
|
+
private readonly caches;
|
|
23
24
|
constructor(options: Options);
|
|
24
25
|
write(x: number, y: number, text: string, options: {
|
|
25
26
|
transformers: OutputTransformer[];
|
package/build/output.js
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
1
|
import sliceAnsi from 'slice-ansi';
|
|
2
2
|
import stringWidth from 'string-width';
|
|
3
3
|
import { styledCharsFromTokens, styledCharsToString, tokenize, } from '@alcalzone/ansi-tokenize';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let y2;
|
|
14
|
-
for (const c of clips) {
|
|
15
|
-
if (c.x1 !== undefined) {
|
|
16
|
-
x1 = x1 === undefined ? c.x1 : Math.max(x1, c.x1);
|
|
17
|
-
}
|
|
18
|
-
if (c.x2 !== undefined) {
|
|
19
|
-
x2 = x2 === undefined ? c.x2 : Math.min(x2, c.x2);
|
|
4
|
+
class OutputCaches {
|
|
5
|
+
widths = new Map();
|
|
6
|
+
blockWidths = new Map();
|
|
7
|
+
styledChars = new Map();
|
|
8
|
+
getStyledChars(line) {
|
|
9
|
+
let cached = this.styledChars.get(line);
|
|
10
|
+
if (cached === undefined) {
|
|
11
|
+
cached = styledCharsFromTokens(tokenize(line));
|
|
12
|
+
this.styledChars.set(line, cached);
|
|
20
13
|
}
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
return cached;
|
|
15
|
+
}
|
|
16
|
+
getStringWidth(text) {
|
|
17
|
+
let cached = this.widths.get(text);
|
|
18
|
+
if (cached === undefined) {
|
|
19
|
+
cached = stringWidth(text);
|
|
20
|
+
this.widths.set(text, cached);
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
return cached;
|
|
23
|
+
}
|
|
24
|
+
getWidestLine(text) {
|
|
25
|
+
let cached = this.blockWidths.get(text);
|
|
26
|
+
if (cached === undefined) {
|
|
27
|
+
let lineWidth = 0;
|
|
28
|
+
for (const line of text.split('\n')) {
|
|
29
|
+
lineWidth = Math.max(lineWidth, this.getStringWidth(line));
|
|
30
|
+
}
|
|
31
|
+
cached = lineWidth;
|
|
32
|
+
this.blockWidths.set(text, cached);
|
|
26
33
|
}
|
|
34
|
+
return cached;
|
|
27
35
|
}
|
|
28
|
-
|
|
29
|
-
};
|
|
36
|
+
}
|
|
30
37
|
export default class Output {
|
|
31
38
|
width;
|
|
32
39
|
height;
|
|
33
40
|
operations = [];
|
|
41
|
+
caches = new OutputCaches();
|
|
34
42
|
constructor(options) {
|
|
35
43
|
const { width, height } = options;
|
|
36
44
|
this.width = width;
|
|
@@ -45,7 +53,7 @@ export default class Output {
|
|
|
45
53
|
type: 'write',
|
|
46
54
|
x,
|
|
47
55
|
y,
|
|
48
|
-
text
|
|
56
|
+
text,
|
|
49
57
|
transformers,
|
|
50
58
|
});
|
|
51
59
|
}
|
|
@@ -87,14 +95,14 @@ export default class Output {
|
|
|
87
95
|
const { text, transformers } = operation;
|
|
88
96
|
let { x, y } = operation;
|
|
89
97
|
let lines = text.split('\n');
|
|
90
|
-
const clip =
|
|
98
|
+
const clip = clips.at(-1);
|
|
91
99
|
if (clip) {
|
|
92
100
|
const clipHorizontally = typeof clip?.x1 === 'number' && typeof clip?.x2 === 'number';
|
|
93
101
|
const clipVertically = typeof clip?.y1 === 'number' && typeof clip?.y2 === 'number';
|
|
94
102
|
// If text is positioned outside of clipping area altogether,
|
|
95
103
|
// skip to the next operation to avoid unnecessary calculations
|
|
96
104
|
if (clipHorizontally) {
|
|
97
|
-
const width =
|
|
105
|
+
const width = this.caches.getWidestLine(text);
|
|
98
106
|
if (x + width < clip.x1 || x > clip.x2) {
|
|
99
107
|
continue;
|
|
100
108
|
}
|
|
@@ -108,7 +116,7 @@ export default class Output {
|
|
|
108
116
|
if (clipHorizontally) {
|
|
109
117
|
lines = lines.map(line => {
|
|
110
118
|
const from = x < clip.x1 ? clip.x1 - x : 0;
|
|
111
|
-
const width =
|
|
119
|
+
const width = this.caches.getStringWidth(line);
|
|
112
120
|
const to = x + width > clip.x2 ? clip.x2 - x : width;
|
|
113
121
|
return sliceAnsi(line, from, to);
|
|
114
122
|
});
|
|
@@ -136,41 +144,34 @@ export default class Output {
|
|
|
136
144
|
for (const transformer of transformers) {
|
|
137
145
|
line = transformer(line, index);
|
|
138
146
|
}
|
|
139
|
-
const characters =
|
|
147
|
+
const characters = this.caches.getStyledChars(line);
|
|
140
148
|
let offsetX = x;
|
|
149
|
+
// Nothing to write (e.g. line was clipped away).
|
|
150
|
+
if (characters.length === 0) {
|
|
151
|
+
offsetY++;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const spaceCell = {
|
|
155
|
+
type: 'char',
|
|
156
|
+
value: ' ',
|
|
157
|
+
fullWidth: false,
|
|
158
|
+
styles: [],
|
|
159
|
+
};
|
|
160
|
+
// Wide characters (e.g. CJK) occupy two cells: a leading
|
|
161
|
+
// cell with the character and a trailing placeholder with
|
|
162
|
+
// value ''. When an overlapping write lands in the middle
|
|
163
|
+
// of a wide character, the boundary cells need cleanup so
|
|
164
|
+
// the terminal never renders a half-visible wide character.
|
|
165
|
+
if (currentLine[offsetX]?.value === '' &&
|
|
166
|
+
offsetX > 0 &&
|
|
167
|
+
this.caches.getStringWidth(currentLine[offsetX - 1]?.value ?? '') >
|
|
168
|
+
1) {
|
|
169
|
+
currentLine[offsetX - 1] = spaceCell;
|
|
170
|
+
}
|
|
141
171
|
for (const character of characters) {
|
|
142
|
-
// Check if this is a zero-width character (like U+FE0F emoji variation selector)
|
|
143
|
-
const rawWidth = stringWidth(character.value);
|
|
144
|
-
if (rawWidth === 0) {
|
|
145
|
-
// Zero-width characters (like variation selectors) should be appended
|
|
146
|
-
// to the previous cell rather than taking up their own space
|
|
147
|
-
const previousCell = currentLine[offsetX - 1];
|
|
148
|
-
if (previousCell?.value) {
|
|
149
|
-
// Measure width before and after appending to detect width changes
|
|
150
|
-
// This handles cases like ⏭ (width 1) + ️ (VS16) = ⏭️ (width 2)
|
|
151
|
-
const prevWidth = stringWidth(previousCell.value);
|
|
152
|
-
previousCell.value += character.value;
|
|
153
|
-
const newWidth = stringWidth(previousCell.value);
|
|
154
|
-
// If combining increased the display width, add placeholder cells
|
|
155
|
-
const extraWidth = newWidth - prevWidth;
|
|
156
|
-
if (extraWidth > 0) {
|
|
157
|
-
for (let i = 0; i < extraWidth; i++) {
|
|
158
|
-
currentLine[offsetX + i] = {
|
|
159
|
-
type: 'char',
|
|
160
|
-
value: '',
|
|
161
|
-
fullWidth: false,
|
|
162
|
-
styles: previousCell.styles,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
offsetX += extraWidth;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
// Don't advance offsetX for zero-width characters (already handled above if width changed)
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
172
|
currentLine[offsetX] = character;
|
|
172
|
-
// Determine printed width using string-width
|
|
173
|
-
const characterWidth = Math.max(1,
|
|
173
|
+
// Determine printed width using string-width to align with measurement
|
|
174
|
+
const characterWidth = Math.max(1, this.caches.getStringWidth(character.value));
|
|
174
175
|
// For multi-column characters, clear following cells to avoid stray spaces/artifacts
|
|
175
176
|
if (characterWidth > 1) {
|
|
176
177
|
for (let index = 1; index < characterWidth; index++) {
|
|
@@ -184,6 +185,9 @@ export default class Output {
|
|
|
184
185
|
}
|
|
185
186
|
offsetX += characterWidth;
|
|
186
187
|
}
|
|
188
|
+
if (currentLine[offsetX]?.value === '') {
|
|
189
|
+
currentLine[offsetX] = spaceCell;
|
|
190
|
+
}
|
|
187
191
|
offsetY++;
|
|
188
192
|
}
|
|
189
193
|
}
|