@nuvin/ink 6.6.7 → 7.0.1-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.d.ts.map +1 -0
- package/build/ansi-tokenizer.js +316 -0
- package/build/ansi-tokenizer.js.map +1 -0
- package/build/colorize.d.ts.map +1 -0
- package/build/components/AccessibilityContext.d.ts.map +1 -0
- package/build/components/AnimationContext.d.ts +9 -0
- package/build/components/AnimationContext.d.ts.map +1 -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.d.ts.map +1 -0
- 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.d.ts.map +1 -0
- package/build/components/AppContext.js +2 -1
- package/build/components/AppContext.js.map +1 -1
- package/build/components/BackgroundContext.d.ts.map +1 -0
- package/build/components/Box.d.ts +15 -8
- package/build/components/Box.d.ts.map +1 -0
- 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.d.ts.map +1 -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.d.ts.map +1 -0
- package/build/components/ErrorBoundary.js +23 -0
- package/build/components/ErrorBoundary.js.map +1 -0
- package/build/components/ErrorOverview.d.ts.map +1 -0
- package/build/components/ErrorOverview.js +6 -6
- package/build/components/ErrorOverview.js.map +1 -1
- package/build/components/FocusContext.d.ts.map +1 -0
- package/build/components/Newline.d.ts.map +1 -0
- package/build/components/Spacer.d.ts.map +1 -0
- package/build/components/Static.d.ts.map +1 -0
- package/build/components/Static.js.map +1 -1
- package/build/components/StderrContext.d.ts.map +1 -0
- package/build/components/StdinContext.d.ts +7 -1
- package/build/components/StdinContext.d.ts.map +1 -0
- package/build/components/StdinContext.js +1 -0
- package/build/components/StdinContext.js.map +1 -1
- package/build/components/StdoutContext.d.ts.map +1 -0
- package/build/components/Text.d.ts +1 -1
- package/build/components/Text.d.ts.map +1 -0
- 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/components/Transform.d.ts.map +1 -0
- package/build/cursor-helpers.d.ts +38 -0
- package/build/cursor-helpers.d.ts.map +1 -0
- package/build/cursor-helpers.js +56 -0
- package/build/cursor-helpers.js.map +1 -0
- package/build/devtools-window-polyfill.d.ts.map +1 -0
- package/build/devtools-window-polyfill.js +7 -4
- package/build/devtools-window-polyfill.js.map +1 -1
- package/build/devtools.d.ts.map +1 -0
- package/build/devtools.js +31 -6
- package/build/devtools.js.map +1 -1
- package/build/diagnostics.d.ts +5 -0
- package/build/diagnostics.d.ts.map +1 -0
- package/build/diagnostics.js +7 -0
- package/build/diagnostics.js.map +1 -0
- package/build/dom.d.ts +5 -1
- package/build/dom.d.ts.map +1 -0
- package/build/dom.js +20 -1
- package/build/dom.js.map +1 -1
- package/build/get-max-width.d.ts.map +1 -0
- package/build/hooks/use-animation.d.ts +49 -0
- package/build/hooks/use-animation.d.ts.map +1 -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.d.ts.map +1 -0
- package/build/hooks/use-app.js +1 -1
- package/build/hooks/use-box-metrics.d.ts +59 -0
- package/build/hooks/use-box-metrics.d.ts.map +1 -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.d.ts.map +1 -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.d.ts.map +1 -0
- 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.d.ts.map +1 -0
- 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.d.ts.map +1 -0
- package/build/hooks/use-input.js +65 -25
- 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.d.ts.map +1 -0
- 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.d.ts.map +1 -0
- package/build/hooks/use-paste.js +66 -0
- package/build/hooks/use-paste.js.map +1 -0
- package/build/hooks/use-stderr.d.ts +1 -1
- package/build/hooks/use-stderr.d.ts.map +1 -0
- package/build/hooks/use-stderr.js +1 -1
- package/build/hooks/use-stdin.d.ts +4 -2
- package/build/hooks/use-stdin.d.ts.map +1 -0
- 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.d.ts.map +1 -0
- package/build/hooks/use-stdout.js +1 -1
- package/build/hooks/use-window-size.d.ts +18 -0
- package/build/hooks/use-window-size.d.ts.map +1 -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 +16 -1
- package/build/index.d.ts.map +1 -0
- package/build/index.js +8 -0
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +94 -5
- package/build/ink.d.ts.map +1 -0
- package/build/ink.js +586 -81
- package/build/ink.js.map +1 -1
- package/build/input-parser.d.ts +10 -0
- package/build/input-parser.d.ts.map +1 -0
- package/build/input-parser.js +194 -0
- package/build/input-parser.js.map +1 -0
- package/build/instances.d.ts.map +1 -0
- package/build/kitty-keyboard.d.ts +23 -0
- package/build/kitty-keyboard.d.ts.map +1 -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.d.ts.map +1 -0
- package/build/log-update.js +181 -56
- package/build/log-update.js.map +1 -1
- package/build/measure-element.d.ts +15 -3
- package/build/measure-element.d.ts.map +1 -0
- package/build/measure-element.js +31 -5
- package/build/measure-element.js.map +1 -1
- package/build/measure-text.d.ts +2 -0
- package/build/measure-text.d.ts.map +1 -0
- package/build/measure-text.js +13 -11
- package/build/measure-text.js.map +1 -1
- package/build/output.d.ts +2 -1
- package/build/output.d.ts.map +1 -0
- 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.d.ts.map +1 -0
- package/build/parse-keypress.js +283 -13
- package/build/parse-keypress.js.map +1 -1
- package/build/reconciler.d.ts.map +1 -0
- package/build/reconciler.js +57 -37
- package/build/reconciler.js.map +1 -1
- package/build/render-background.d.ts.map +1 -0
- 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.d.ts.map +1 -0
- 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.d.ts.map +1 -0
- 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.d.ts.map +1 -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.d.ts.map +1 -0
- package/build/render.js +17 -5
- package/build/render.js.map +1 -1
- package/build/renderer.d.ts.map +1 -0
- package/build/sanitize-ansi.d.ts +2 -0
- package/build/sanitize-ansi.d.ts.map +1 -0
- package/build/sanitize-ansi.js +27 -0
- package/build/sanitize-ansi.js.map +1 -0
- package/build/squash-text-nodes.d.ts.map +1 -0
- package/build/squash-text-nodes.js +18 -1
- package/build/squash-text-nodes.js.map +1 -1
- package/build/styles.d.ts +75 -37
- package/build/styles.d.ts.map +1 -0
- package/build/styles.js +87 -44
- package/build/styles.js.map +1 -1
- package/build/utils.d.ts +9 -2
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +18 -3
- package/build/utils.js.map +1 -1
- package/build/wrap-text.d.ts +2 -0
- package/build/wrap-text.d.ts.map +1 -0
- package/build/wrap-text.js +21 -18
- package/build/wrap-text.js.map +1 -1
- package/build/write-synchronized.d.ts +4 -0
- package/build/write-synchronized.d.ts.map +1 -0
- package/build/write-synchronized.js +9 -0
- package/build/write-synchronized.js.map +1 -0
- package/package.json +46 -106
- 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,MA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AC1B,WAAW,GAAG,IAAI,CAAC;IACpB,CAAC,CAAC;IAEF,MAAM,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC;IACzC,MAAM,CAAC,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,CAAC;IAExE,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CACd,MAAgB,EAChB,EAAC,UAAU,GAAG,KAAK,EAAE,WAAW,GAAG,KAAK,EAAC,GAAG,EAAE,EAClC,EAAE;IACd,IAAI,WAAW,EAAE,CAAC;QACjB,OAAO,iBAAiB,CAAC,MAAM,EAAE,EAAC,UAAU,EAAC,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,cAAc,CAAC,MAAM,EAAE,EAAC,UAAU,EAAC,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,EAAC,MAAM,EAAC,CAAC;AAC3B,eAAe,SAAS,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DOMElement } from './dom.js';
|
|
2
|
-
type
|
|
2
|
+
type ElementMeasurement = {
|
|
3
3
|
/**
|
|
4
4
|
Element width.
|
|
5
5
|
*/
|
|
@@ -8,9 +8,21 @@ type Output = {
|
|
|
8
8
|
Element height.
|
|
9
9
|
*/
|
|
10
10
|
height: number;
|
|
11
|
+
/**
|
|
12
|
+
Element absolute horizontal position (column) on screen.
|
|
13
|
+
*/
|
|
14
|
+
x: number;
|
|
15
|
+
/**
|
|
16
|
+
Element absolute vertical position (row) on screen.
|
|
17
|
+
*/
|
|
18
|
+
y: number;
|
|
11
19
|
};
|
|
12
20
|
/**
|
|
13
|
-
Measure the dimensions of a particular `<Box>` element.
|
|
21
|
+
Measure the dimensions and absolute position of a particular `<Box>` element.
|
|
22
|
+
Returns an object with `width`, `height`, `x`, and `y` properties.
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
Note: `measureElement()` returns `{width: 0, height: 0, x: 0, y: 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
26
|
*/
|
|
15
|
-
declare const measureElement: (node: DOMElement) =>
|
|
27
|
+
declare const measureElement: (node: DOMElement) => ElementMeasurement;
|
|
16
28
|
export default measureElement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measure-element.d.ts","sourceRoot":"","sources":["../src/measure-element.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,UAAU,EAAC,MAAM,UAAU,CAAC;AAEzC,KAAK,kBAAkB,GAAG;IACzB;;MAEE;IACF,KAAK,EAAE,MAAM,CAAC;IAEd;;MAEE;IACF,MAAM,EAAE,MAAM,CAAC;IAEf;;MAEE;IACF,CAAC,EAAE,MAAM,CAAC;IAEV;;MAEE;IACF,CAAC,EAAE,MAAM,CAAC;CACV,CAAC;AAEF;;;;;;EAME;AACF,QAAA,MAAM,cAAc,GAAI,MAAM,UAAU,KAAG,kBA2B1C,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/build/measure-element.js
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
|
+
import Yoga from 'yoga-layout';
|
|
1
2
|
/**
|
|
2
|
-
Measure the dimensions of a particular `<Box>` element.
|
|
3
|
+
Measure the dimensions and absolute position of a particular `<Box>` element.
|
|
4
|
+
Returns an object with `width`, `height`, `x`, and `y` properties.
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
Note: `measureElement()` returns `{width: 0, height: 0, x: 0, y: 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
8
|
*/
|
|
4
|
-
const measureElement = (node) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
9
|
+
const measureElement = (node) => {
|
|
10
|
+
const { yogaNode } = node;
|
|
11
|
+
if (!yogaNode) {
|
|
12
|
+
return { width: 0, height: 0, x: 0, y: 0 };
|
|
13
|
+
}
|
|
14
|
+
let x = yogaNode.getComputedLeft();
|
|
15
|
+
let y = yogaNode.getComputedTop();
|
|
16
|
+
let current = node.parentNode;
|
|
17
|
+
while (current?.yogaNode) {
|
|
18
|
+
const parentYoga = current.yogaNode;
|
|
19
|
+
x +=
|
|
20
|
+
parentYoga.getComputedLeft() +
|
|
21
|
+
parentYoga.getComputedPadding(Yoga.EDGE_LEFT);
|
|
22
|
+
y +=
|
|
23
|
+
parentYoga.getComputedTop() +
|
|
24
|
+
parentYoga.getComputedPadding(Yoga.EDGE_TOP);
|
|
25
|
+
current = current.parentNode;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
width: yogaNode.getComputedWidth(),
|
|
29
|
+
height: yogaNode.getComputedHeight(),
|
|
30
|
+
x,
|
|
31
|
+
y,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
8
34
|
export default measureElement;
|
|
9
35
|
//# sourceMappingURL=measure-element.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure-element.js","sourceRoot":"","sources":["../src/measure-element.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"measure-element.js","sourceRoot":"","sources":["../src/measure-element.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAyB/B;;;;;;EAME;AACF,MAAM,cAAc,GAAG,CAAC,IAAgB,EAAsB,EAAE;IAC/D,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,OAAO,EAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC;IACnC,IAAI,CAAC,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC;IAClC,IAAI,OAAO,GAA2B,IAAI,CAAC,UAAU,CAAC;IAEtD,OAAO,OAAO,EAAE,QAAQ,EAAE,CAAC;QAC1B,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;QACpC,CAAC;YACA,UAAU,CAAC,eAAe,EAAE;gBAC5B,UAAU,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/C,CAAC;YACA,UAAU,CAAC,cAAc,EAAE;gBAC3B,UAAU,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAC9B,CAAC;IAED,OAAO;QACN,KAAK,EAAE,QAAQ,CAAC,gBAAgB,EAAE;QAClC,MAAM,EAAE,QAAQ,CAAC,iBAAiB,EAAE;QACpC,CAAC;QACD,CAAC;KACD,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/build/measure-text.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measure-text.d.ts","sourceRoot":"","sources":["../src/measure-text.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAI1C,KAAK,MAAM,GAAG;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MA4BnC,CAAC;AAEF,eAAO,MAAM,uBAAuB,QAAO,MAAoB,CAAC;AAEhE,eAAe,WAAW,CAAC"}
|
package/build/measure-text.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import widestLine from 'widest-line';
|
|
2
|
+
export const MEASURE_TEXT_CACHE_MAX = 256;
|
|
2
3
|
const cache = new Map();
|
|
3
|
-
const TAB_SPACES = ' '; // 2 spaces per tab
|
|
4
4
|
const measureText = (text) => {
|
|
5
5
|
if (text.length === 0) {
|
|
6
6
|
return {
|
|
@@ -10,20 +10,22 @@ const measureText = (text) => {
|
|
|
10
10
|
}
|
|
11
11
|
const cachedDimensions = cache.get(text);
|
|
12
12
|
if (cachedDimensions) {
|
|
13
|
+
cache.delete(text);
|
|
14
|
+
cache.set(text, cachedDimensions);
|
|
13
15
|
return cachedDimensions;
|
|
14
16
|
}
|
|
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;
|
|
17
|
+
const width = widestLine(text);
|
|
18
|
+
const height = text.split('\n').length;
|
|
24
19
|
const dimensions = { width, height };
|
|
25
20
|
cache.set(text, dimensions);
|
|
21
|
+
if (cache.size > MEASURE_TEXT_CACHE_MAX) {
|
|
22
|
+
const oldestKey = cache.keys().next().value;
|
|
23
|
+
if (oldestKey !== undefined) {
|
|
24
|
+
cache.delete(oldestKey);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
26
27
|
return dimensions;
|
|
27
28
|
};
|
|
29
|
+
export const getMeasureTextCacheSize = () => cache.size;
|
|
28
30
|
export default measureText;
|
|
29
31
|
//# sourceMappingURL=measure-text.js.map
|
|
@@ -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":"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
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[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,KAAK,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAElE;;;;;;EAME;AAEF,KAAK,OAAO,GAAG;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAiBF,KAAK,IAAI,GAAG;IACX,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;CACvB,CAAC;AA+CF,MAAM,CAAC,OAAO,OAAO,MAAM;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;gBAE/C,OAAO,EAAE,OAAO;IAO5B,KAAK,CACJ,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QAAC,YAAY,EAAE,iBAAiB,EAAE,CAAA;KAAC,GAC1C,IAAI;IAgBP,IAAI,CAAC,IAAI,EAAE,IAAI;IAOf,MAAM;IAMN,GAAG,IAAI;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC;CAoLvC"}
|