ink 3.2.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/colorize.d.ts +3 -3
- package/build/colorize.js +30 -35
- package/build/colorize.js.map +1 -1
- package/build/components/App.d.ts +12 -12
- package/build/components/App.js +287 -208
- package/build/components/App.js.map +1 -1
- package/build/components/AppContext.d.ts +2 -2
- package/build/components/AppContext.js +5 -6
- package/build/components/AppContext.js.map +1 -1
- package/build/components/Box.d.ts +77 -5
- package/build/components/Box.js +20 -38
- package/build/components/Box.js.map +1 -1
- package/build/components/ErrorOverview.d.ts +5 -5
- package/build/components/ErrorOverview.js +40 -58
- package/build/components/ErrorOverview.js.map +1 -1
- package/build/components/FocusContext.d.ts +2 -2
- package/build/components/FocusContext.js +13 -14
- package/build/components/FocusContext.js.map +1 -1
- package/build/components/Newline.d.ts +4 -5
- package/build/components/Newline.js +4 -9
- package/build/components/Newline.js.map +1 -1
- package/build/components/Spacer.d.ts +2 -3
- package/build/components/Spacer.js +5 -10
- package/build/components/Spacer.js.map +1 -1
- package/build/components/Static.d.ts +5 -9
- package/build/components/Static.js +12 -33
- package/build/components/Static.js.map +1 -1
- package/build/components/StderrContext.d.ts +4 -4
- package/build/components/StderrContext.js +7 -7
- package/build/components/StderrContext.js.map +1 -1
- package/build/components/StdinContext.d.ts +4 -4
- package/build/components/StdinContext.js +8 -7
- package/build/components/StdinContext.js.map +1 -1
- package/build/components/StdoutContext.d.ts +4 -4
- package/build/components/StdoutContext.js +7 -7
- package/build/components/StdoutContext.js.map +1 -1
- package/build/components/Text.d.ts +9 -10
- package/build/components/Text.js +14 -29
- package/build/components/Text.js.map +1 -1
- package/build/components/Transform.d.ts +4 -5
- package/build/components/Transform.js +4 -11
- package/build/components/Transform.js.map +1 -1
- package/build/devtools-window-polyfill.js +3 -8
- package/build/devtools-window-polyfill.js.map +1 -1
- package/build/devtools.d.ts +1 -1
- package/build/devtools.js +6 -6
- package/build/devtools.js.map +1 -1
- package/build/dom.d.ts +17 -20
- package/build/dom.js +35 -47
- package/build/dom.js.map +1 -1
- package/build/get-max-width.d.ts +3 -3
- package/build/get-max-width.js +8 -11
- package/build/get-max-width.js.map +1 -1
- package/build/hooks/use-app.d.ts +1 -1
- package/build/hooks/use-app.js +4 -9
- package/build/hooks/use-app.js.map +1 -1
- package/build/hooks/use-focus-manager.d.ts +3 -3
- package/build/hooks/use-focus-manager.js +4 -9
- package/build/hooks/use-focus-manager.js.map +1 -1
- package/build/hooks/use-focus.d.ts +4 -4
- package/build/hooks/use-focus.js +11 -16
- package/build/hooks/use-focus.js.map +1 -1
- package/build/hooks/use-input.d.ts +5 -5
- package/build/hooks/use-input.js +13 -14
- package/build/hooks/use-input.js.map +1 -1
- package/build/hooks/use-stderr.d.ts +1 -1
- package/build/hooks/use-stderr.js +4 -9
- package/build/hooks/use-stderr.js.map +1 -1
- package/build/hooks/use-stdin.d.ts +1 -1
- package/build/hooks/use-stdin.js +4 -9
- package/build/hooks/use-stdin.js.map +1 -1
- package/build/hooks/use-stdout.d.ts +1 -1
- package/build/hooks/use-stdout.js +4 -9
- package/build/hooks/use-stdout.js.map +1 -1
- package/build/index.d.ts +27 -20
- package/build/index.js +15 -32
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +6 -4
- package/build/ink.js +188 -99
- package/build/ink.js.map +1 -1
- package/build/instances.d.ts +4 -2
- package/build/instances.js +2 -3
- package/build/instances.js.map +1 -1
- package/build/log-update.d.ts +5 -6
- package/build/log-update.js +8 -12
- package/build/log-update.js.map +1 -1
- package/build/measure-element.d.ts +5 -5
- package/build/measure-element.js +5 -9
- package/build/measure-element.js.map +1 -1
- package/build/measure-text.d.ts +4 -4
- package/build/measure-text.js +7 -10
- package/build/measure-text.js.map +1 -1
- package/build/output.d.ts +12 -4
- package/build/output.js +108 -31
- package/build/output.js.map +1 -1
- package/build/reconciler.d.ts +1 -1
- package/build/reconciler.js +104 -76
- package/build/reconciler.js.map +1 -1
- package/build/render-border.d.ts +4 -4
- package/build/render-border.js +8 -12
- package/build/render-border.js.map +1 -1
- package/build/render-node-to-output.d.ts +3 -3
- package/build/render-node-to-output.js +44 -24
- package/build/render-node-to-output.js.map +1 -1
- package/build/render.d.ts +8 -8
- package/build/render.js +23 -20
- package/build/render.js.map +1 -1
- package/build/renderer.d.ts +5 -5
- package/build/renderer.js +9 -17
- package/build/renderer.js.map +1 -1
- package/build/squash-text-nodes.d.ts +1 -1
- package/build/squash-text-nodes.js +1 -3
- package/build/squash-text-nodes.js.map +1 -1
- package/build/styles.d.ts +30 -9
- package/build/styles.js +60 -46
- package/build/styles.js.map +1 -1
- package/build/wrap-text.d.ts +3 -3
- package/build/wrap-text.js +9 -12
- package/build/wrap-text.js.map +1 -1
- package/license +1 -1
- package/package.json +87 -67
- package/readme.md +202 -57
package/build/ink.js
CHANGED
|
@@ -1,104 +1,191 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const react_1 = __importDefault(require("react"));
|
|
26
|
-
const lodash_1 = require("lodash");
|
|
27
|
-
const log_update_1 = __importDefault(require("./log-update"));
|
|
28
|
-
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
29
|
-
const is_ci_1 = __importDefault(require("is-ci"));
|
|
30
|
-
const auto_bind_1 = __importDefault(require("auto-bind"));
|
|
31
|
-
const reconciler_1 = __importDefault(require("./reconciler"));
|
|
32
|
-
const renderer_1 = __importDefault(require("./renderer"));
|
|
33
|
-
const signal_exit_1 = __importDefault(require("signal-exit"));
|
|
34
|
-
const patch_console_1 = __importDefault(require("patch-console"));
|
|
35
|
-
const dom = __importStar(require("./dom"));
|
|
36
|
-
const instances_1 = __importDefault(require("./instances"));
|
|
37
|
-
const App_1 = __importDefault(require("./components/App"));
|
|
38
|
-
const isCI = process.env.CI === 'false' ? false : is_ci_1.default;
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import throttle from 'lodash/throttle.js';
|
|
4
|
+
import ansiEscapes from 'ansi-escapes';
|
|
5
|
+
import originalIsCi from 'is-ci';
|
|
6
|
+
import autoBind from 'auto-bind';
|
|
7
|
+
import signalExit from 'signal-exit';
|
|
8
|
+
import patchConsole from 'patch-console';
|
|
9
|
+
// eslint-disable-next-line n/file-extension-in-import
|
|
10
|
+
import Yoga from 'yoga-wasm-web/auto';
|
|
11
|
+
import reconciler from './reconciler.js';
|
|
12
|
+
import render from './renderer.js';
|
|
13
|
+
import * as dom from './dom.js';
|
|
14
|
+
import logUpdate from './log-update.js';
|
|
15
|
+
import instances from './instances.js';
|
|
16
|
+
import App from './components/App.js';
|
|
17
|
+
const isCi = process.env['CI'] === 'false' ? false : originalIsCi;
|
|
39
18
|
const noop = () => { };
|
|
40
|
-
class Ink {
|
|
19
|
+
export default class Ink {
|
|
41
20
|
constructor(options) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
Object.defineProperty(this, "options", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "log", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "throttledLog", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
// Ignore last render after unmounting a tree to prevent empty output before exit
|
|
40
|
+
Object.defineProperty(this, "isUnmounted", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "lastOutput", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "container", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(this, "rootNode", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: void 0
|
|
63
|
+
});
|
|
64
|
+
// This variable is used only in debug mode to store full static output
|
|
65
|
+
// so that it's rerendered every time, not just new static parts, like in non-debug mode
|
|
66
|
+
Object.defineProperty(this, "fullStaticOutput", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(this, "exitPromise", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(this, "restoreConsole", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: void 0
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(this, "unsubscribeResize", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: void 0
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(this, "resized", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: () => {
|
|
95
|
+
this.calculateLayout();
|
|
96
|
+
this.onRender();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(this, "resolveExitPromise", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
value: () => { }
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(this, "rejectExitPromise", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
configurable: true,
|
|
108
|
+
writable: true,
|
|
109
|
+
value: () => { }
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(this, "unsubscribeExit", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
configurable: true,
|
|
114
|
+
writable: true,
|
|
115
|
+
value: () => { }
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(this, "calculateLayout", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
configurable: true,
|
|
120
|
+
writable: true,
|
|
121
|
+
value: () => {
|
|
122
|
+
// The 'columns' property can be undefined or 0 when not using a TTY.
|
|
123
|
+
// In that case we fall back to 80.
|
|
124
|
+
const terminalWidth = this.options.stdout.columns || 80;
|
|
125
|
+
this.rootNode.yogaNode.setWidth(terminalWidth);
|
|
126
|
+
this.rootNode.yogaNode.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
|
48
127
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(this, "onRender", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
configurable: true,
|
|
132
|
+
writable: true,
|
|
133
|
+
value: () => {
|
|
134
|
+
if (this.isUnmounted) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const { output, outputHeight, staticOutput } = render(this.rootNode);
|
|
138
|
+
// If <Static> output isn't empty, it means new children have been added to it
|
|
139
|
+
const hasStaticOutput = staticOutput && staticOutput !== '\n';
|
|
140
|
+
if (this.options.debug) {
|
|
141
|
+
if (hasStaticOutput) {
|
|
142
|
+
this.fullStaticOutput += staticOutput;
|
|
143
|
+
}
|
|
144
|
+
this.options.stdout.write(this.fullStaticOutput + output);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (isCi) {
|
|
148
|
+
if (hasStaticOutput) {
|
|
149
|
+
this.options.stdout.write(staticOutput);
|
|
150
|
+
}
|
|
151
|
+
this.lastOutput = output;
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
56
154
|
if (hasStaticOutput) {
|
|
57
155
|
this.fullStaticOutput += staticOutput;
|
|
58
156
|
}
|
|
59
|
-
this.options.stdout.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
157
|
+
if (outputHeight >= this.options.stdout.rows) {
|
|
158
|
+
this.options.stdout.write(ansiEscapes.clearTerminal + this.fullStaticOutput + output);
|
|
159
|
+
this.lastOutput = output;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
// To ensure static output is cleanly rendered before main output, clear main output first
|
|
63
163
|
if (hasStaticOutput) {
|
|
164
|
+
this.log.clear();
|
|
64
165
|
this.options.stdout.write(staticOutput);
|
|
166
|
+
this.log(output);
|
|
167
|
+
}
|
|
168
|
+
if (!hasStaticOutput && output !== this.lastOutput) {
|
|
169
|
+
this.throttledLog(output);
|
|
65
170
|
}
|
|
66
171
|
this.lastOutput = output;
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (hasStaticOutput) {
|
|
70
|
-
this.fullStaticOutput += staticOutput;
|
|
71
|
-
}
|
|
72
|
-
if (outputHeight >= this.options.stdout.rows) {
|
|
73
|
-
this.options.stdout.write(ansi_escapes_1.default.clearTerminal + this.fullStaticOutput + output);
|
|
74
|
-
this.lastOutput = output;
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// To ensure static output is cleanly rendered before main output, clear main output first
|
|
78
|
-
if (hasStaticOutput) {
|
|
79
|
-
this.log.clear();
|
|
80
|
-
this.options.stdout.write(staticOutput);
|
|
81
|
-
this.log(output);
|
|
82
172
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
this.lastOutput = output;
|
|
87
|
-
};
|
|
88
|
-
auto_bind_1.default(this);
|
|
173
|
+
});
|
|
174
|
+
autoBind(this);
|
|
89
175
|
this.options = options;
|
|
90
176
|
this.rootNode = dom.createNode('ink-root');
|
|
177
|
+
this.rootNode.onComputeLayout = this.calculateLayout;
|
|
91
178
|
this.rootNode.onRender = options.debug
|
|
92
179
|
? this.onRender
|
|
93
|
-
:
|
|
180
|
+
: throttle(this.onRender, 32, {
|
|
94
181
|
leading: true,
|
|
95
182
|
trailing: true
|
|
96
183
|
});
|
|
97
184
|
this.rootNode.onImmediateRender = this.onRender;
|
|
98
|
-
this.log =
|
|
185
|
+
this.log = logUpdate.create(options.stdout);
|
|
99
186
|
this.throttledLog = options.debug
|
|
100
187
|
? this.log
|
|
101
|
-
:
|
|
188
|
+
: throttle(this.log, undefined, {
|
|
102
189
|
leading: true,
|
|
103
190
|
trailing: true
|
|
104
191
|
});
|
|
@@ -109,13 +196,14 @@ class Ink {
|
|
|
109
196
|
// This variable is used only in debug mode to store full static output
|
|
110
197
|
// so that it's rerendered every time, not just new static parts, like in non-debug mode
|
|
111
198
|
this.fullStaticOutput = '';
|
|
112
|
-
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
200
|
+
this.container = reconciler.createContainer(this.rootNode,
|
|
113
201
|
// Legacy mode
|
|
114
|
-
0, false, null);
|
|
202
|
+
0, null, false, null, 'id', () => { }, null);
|
|
115
203
|
// Unmount when process exits
|
|
116
|
-
this.unsubscribeExit =
|
|
117
|
-
if (process.env
|
|
118
|
-
|
|
204
|
+
this.unsubscribeExit = signalExit(this.unmount, { alwaysLast: false });
|
|
205
|
+
if (process.env['DEV'] === 'true') {
|
|
206
|
+
reconciler.injectIntoDevTools({
|
|
119
207
|
bundleType: 0,
|
|
120
208
|
// Reporting React DOM's version, not Ink's
|
|
121
209
|
// See https://github.com/facebook/react/issues/16666#issuecomment-532639905
|
|
@@ -126,16 +214,16 @@ class Ink {
|
|
|
126
214
|
if (options.patchConsole) {
|
|
127
215
|
this.patchConsole();
|
|
128
216
|
}
|
|
129
|
-
if (!
|
|
130
|
-
options.stdout.on('resize', this.
|
|
217
|
+
if (!isCi) {
|
|
218
|
+
options.stdout.on('resize', this.resized);
|
|
131
219
|
this.unsubscribeResize = () => {
|
|
132
|
-
options.stdout.off('resize', this.
|
|
220
|
+
options.stdout.off('resize', this.resized);
|
|
133
221
|
};
|
|
134
222
|
}
|
|
135
223
|
}
|
|
136
224
|
render(node) {
|
|
137
|
-
const tree = (
|
|
138
|
-
|
|
225
|
+
const tree = (React.createElement(App, { stdin: this.options.stdin, stdout: this.options.stdout, stderr: this.options.stderr, writeToStdout: this.writeToStdout, writeToStderr: this.writeToStderr, exitOnCtrlC: this.options.exitOnCtrlC, onExit: this.unmount }, node));
|
|
226
|
+
reconciler.updateContainer(tree, this.container, null, noop);
|
|
139
227
|
}
|
|
140
228
|
writeToStdout(data) {
|
|
141
229
|
if (this.isUnmounted) {
|
|
@@ -145,7 +233,7 @@ class Ink {
|
|
|
145
233
|
this.options.stdout.write(data + this.fullStaticOutput + this.lastOutput);
|
|
146
234
|
return;
|
|
147
235
|
}
|
|
148
|
-
if (
|
|
236
|
+
if (isCi) {
|
|
149
237
|
this.options.stdout.write(data);
|
|
150
238
|
return;
|
|
151
239
|
}
|
|
@@ -162,7 +250,7 @@ class Ink {
|
|
|
162
250
|
this.options.stdout.write(this.fullStaticOutput + this.lastOutput);
|
|
163
251
|
return;
|
|
164
252
|
}
|
|
165
|
-
if (
|
|
253
|
+
if (isCi) {
|
|
166
254
|
this.options.stderr.write(data);
|
|
167
255
|
return;
|
|
168
256
|
}
|
|
@@ -170,10 +258,12 @@ class Ink {
|
|
|
170
258
|
this.options.stderr.write(data);
|
|
171
259
|
this.log(this.lastOutput);
|
|
172
260
|
}
|
|
261
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
173
262
|
unmount(error) {
|
|
174
263
|
if (this.isUnmounted) {
|
|
175
264
|
return;
|
|
176
265
|
}
|
|
266
|
+
this.calculateLayout();
|
|
177
267
|
this.onRender();
|
|
178
268
|
this.unsubscribeExit();
|
|
179
269
|
if (typeof this.restoreConsole === 'function') {
|
|
@@ -184,15 +274,15 @@ class Ink {
|
|
|
184
274
|
}
|
|
185
275
|
// CIs don't handle erasing ansi escapes well, so it's better to
|
|
186
276
|
// only render last frame of non-static output
|
|
187
|
-
if (
|
|
277
|
+
if (isCi) {
|
|
188
278
|
this.options.stdout.write(this.lastOutput + '\n');
|
|
189
279
|
}
|
|
190
280
|
else if (!this.options.debug) {
|
|
191
281
|
this.log.done();
|
|
192
282
|
}
|
|
193
283
|
this.isUnmounted = true;
|
|
194
|
-
|
|
195
|
-
|
|
284
|
+
reconciler.updateContainer(null, this.container, null, noop);
|
|
285
|
+
instances.delete(this.options.stdout);
|
|
196
286
|
if (error instanceof Error) {
|
|
197
287
|
this.rejectExitPromise(error);
|
|
198
288
|
}
|
|
@@ -200,7 +290,7 @@ class Ink {
|
|
|
200
290
|
this.resolveExitPromise();
|
|
201
291
|
}
|
|
202
292
|
}
|
|
203
|
-
waitUntilExit() {
|
|
293
|
+
async waitUntilExit() {
|
|
204
294
|
if (!this.exitPromise) {
|
|
205
295
|
this.exitPromise = new Promise((resolve, reject) => {
|
|
206
296
|
this.resolveExitPromise = resolve;
|
|
@@ -210,7 +300,7 @@ class Ink {
|
|
|
210
300
|
return this.exitPromise;
|
|
211
301
|
}
|
|
212
302
|
clear() {
|
|
213
|
-
if (!
|
|
303
|
+
if (!isCi && !this.options.debug) {
|
|
214
304
|
this.log.clear();
|
|
215
305
|
}
|
|
216
306
|
}
|
|
@@ -218,7 +308,7 @@ class Ink {
|
|
|
218
308
|
if (this.options.debug) {
|
|
219
309
|
return;
|
|
220
310
|
}
|
|
221
|
-
this.restoreConsole =
|
|
311
|
+
this.restoreConsole = patchConsole((stream, data) => {
|
|
222
312
|
if (stream === 'stdout') {
|
|
223
313
|
this.writeToStdout(data);
|
|
224
314
|
}
|
|
@@ -231,5 +321,4 @@ class Ink {
|
|
|
231
321
|
});
|
|
232
322
|
}
|
|
233
323
|
}
|
|
234
|
-
exports.default = Ink;
|
|
235
324
|
//# sourceMappingURL=ink.js.map
|
package/build/ink.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ink.js","sourceRoot":"","sources":["../src/ink.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ink.js","sourceRoot":"","sources":["../src/ink.tsx"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,KAAuB,MAAM,OAAO,CAAC;AAC5C,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAE1C,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,OAAO,CAAC;AACjC,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,sDAAsD;AACtD,OAAO,IAAI,MAAM,oBAAoB,CAAC;AACtC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,SAA2B,MAAM,iBAAiB,CAAC;AAC1D,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,GAAG,MAAM,qBAAqB,CAAC;AAEtC,MA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AAC,kBAAkB,GAAG,OAAO,CAAC;gBAClC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC;YACjC,CAAC,CAAC,CAAC;SACH;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YACjC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;SACjB;IACF,CAAC;IAED,YAAY;QACX,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YACvB,OAAO;SACP;QAED,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;YACnD,IAAI,MAAM,KAAK,QAAQ,EAAE;gBACxB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;aACzB;YAED,IAAI,MAAM,KAAK,QAAQ,EAAE;gBACxB,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC;gBAEnE,IAAI,CAAC,cAAc,EAAE;oBACpB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;iBACzB;aACD;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
package/build/instances.d.ts
CHANGED
package/build/instances.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
// Store all instances of Ink (instance.js) to ensure that consecutive render() calls
|
|
4
2
|
// use the same instance of Ink and don't create a new one
|
|
5
3
|
//
|
|
6
4
|
// This map has to be stored in a separate file, because render.js creates instances,
|
|
7
5
|
// but instance.js should delete itself from the map on unmount
|
|
8
|
-
|
|
6
|
+
const instances = new WeakMap();
|
|
7
|
+
export default instances;
|
|
9
8
|
//# sourceMappingURL=instances.js.map
|
package/build/instances.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instances.js","sourceRoot":"","sources":["../src/instances.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instances.js","sourceRoot":"","sources":["../src/instances.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,0DAA0D;AAC1D,EAAE;AACF,qFAAqF;AACrF,+DAA+D;AAI/D,MAAM,SAAS,GAAG,IAAI,OAAO,EAA2B,CAAC;AACzD,eAAe,SAAS,CAAC"}
|
package/build/log-update.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface LogUpdate {
|
|
1
|
+
import { type Writable } from 'node:stream';
|
|
2
|
+
export type LogUpdate = {
|
|
4
3
|
clear: () => void;
|
|
5
4
|
done: () => void;
|
|
6
5
|
(str: string): void;
|
|
7
|
-
}
|
|
8
|
-
declare const
|
|
6
|
+
};
|
|
7
|
+
declare const logUpdate: {
|
|
9
8
|
create: (stream: Writable, { showCursor }?: {
|
|
10
9
|
showCursor?: boolean | undefined;
|
|
11
10
|
}) => LogUpdate;
|
|
12
11
|
};
|
|
13
|
-
export default
|
|
12
|
+
export default logUpdate;
|
package/build/log-update.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
7
|
-
const cli_cursor_1 = __importDefault(require("cli-cursor"));
|
|
1
|
+
import ansiEscapes from 'ansi-escapes';
|
|
2
|
+
import cliCursor from 'cli-cursor';
|
|
8
3
|
const create = (stream, { showCursor = false } = {}) => {
|
|
9
4
|
let previousLineCount = 0;
|
|
10
5
|
let previousOutput = '';
|
|
11
6
|
let hasHiddenCursor = false;
|
|
12
7
|
const render = (str) => {
|
|
13
8
|
if (!showCursor && !hasHiddenCursor) {
|
|
14
|
-
|
|
9
|
+
cliCursor.hide();
|
|
15
10
|
hasHiddenCursor = true;
|
|
16
11
|
}
|
|
17
12
|
const output = str + '\n';
|
|
@@ -19,11 +14,11 @@ const create = (stream, { showCursor = false } = {}) => {
|
|
|
19
14
|
return;
|
|
20
15
|
}
|
|
21
16
|
previousOutput = output;
|
|
22
|
-
stream.write(
|
|
17
|
+
stream.write(ansiEscapes.eraseLines(previousLineCount) + output);
|
|
23
18
|
previousLineCount = output.split('\n').length;
|
|
24
19
|
};
|
|
25
20
|
render.clear = () => {
|
|
26
|
-
stream.write(
|
|
21
|
+
stream.write(ansiEscapes.eraseLines(previousLineCount));
|
|
27
22
|
previousOutput = '';
|
|
28
23
|
previousLineCount = 0;
|
|
29
24
|
};
|
|
@@ -31,11 +26,12 @@ const create = (stream, { showCursor = false } = {}) => {
|
|
|
31
26
|
previousOutput = '';
|
|
32
27
|
previousLineCount = 0;
|
|
33
28
|
if (!showCursor) {
|
|
34
|
-
|
|
29
|
+
cliCursor.show();
|
|
35
30
|
hasHiddenCursor = false;
|
|
36
31
|
}
|
|
37
32
|
};
|
|
38
33
|
return render;
|
|
39
34
|
};
|
|
40
|
-
|
|
35
|
+
const logUpdate = { create };
|
|
36
|
+
export default logUpdate;
|
|
41
37
|
//# sourceMappingURL=log-update.js.map
|
package/build/log-update.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-update.js","sourceRoot":"","sources":["../src/log-update.ts"],"names":[],"mappings":"
|
|
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;AAQnC,MAAM,MAAM,GAAG,CAAC,MAAgB,EAAE,EAAC,UAAU,GAAG,KAAK,EAAC,GAAG,EAAE,EAAa,EAAE;IACzE,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,IAAI,cAAc,GAAG,EAAE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
|
5
5
|
*/
|
|
@@ -8,9 +8,9 @@ interface Output {
|
|
|
8
8
|
* Element height.
|
|
9
9
|
*/
|
|
10
10
|
height: number;
|
|
11
|
-
}
|
|
12
|
-
declare const _default: (node: DOMElement) => Output;
|
|
11
|
+
};
|
|
13
12
|
/**
|
|
14
13
|
* Measure the dimensions of a particular `<Box>` element.
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
declare const measureElement: (node: DOMElement) => Output;
|
|
16
|
+
export default measureElement;
|
package/build/measure-element.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Measure the dimensions of a particular `<Box>` element.
|
|
5
3
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
};
|
|
4
|
+
const measureElement = (node) => ({
|
|
5
|
+
width: node.yogaNode?.getComputedWidth() ?? 0,
|
|
6
|
+
height: node.yogaNode?.getComputedHeight() ?? 0
|
|
7
|
+
});
|
|
8
|
+
export default measureElement;
|
|
13
9
|
//# 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":"AAcA;;GAEG;AACH,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.d.ts
CHANGED
package/build/measure-text.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const widest_line_1 = __importDefault(require("widest-line"));
|
|
1
|
+
import widestLine from 'widest-line';
|
|
7
2
|
const cache = {};
|
|
8
|
-
|
|
3
|
+
const measureText = (text) => {
|
|
9
4
|
if (text.length === 0) {
|
|
10
5
|
return {
|
|
11
6
|
width: 0,
|
|
12
7
|
height: 0
|
|
13
8
|
};
|
|
14
9
|
}
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const cachedDimensions = cache[text];
|
|
11
|
+
if (cachedDimensions) {
|
|
12
|
+
return cachedDimensions;
|
|
17
13
|
}
|
|
18
|
-
const width =
|
|
14
|
+
const width = widestLine(text);
|
|
19
15
|
const height = text.split('\n').length;
|
|
20
16
|
cache[text] = { width, height };
|
|
21
17
|
return { width, height };
|
|
22
18
|
};
|
|
19
|
+
export default measureText;
|
|
23
20
|
//# sourceMappingURL=measure-text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measure-text.js","sourceRoot":"","sources":["../src/measure-text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"measure-text.js","sourceRoot":"","sources":["../src/measure-text.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,MAAM,KAAK,GAA2B,EAAE,CAAC;AAOzC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE;IAC5C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,OAAO;YACN,KAAK,EAAE,CAAC;YACR,MAAM,EAAE,CAAC;SACT,CAAC;KACF;IAED,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAErC,IAAI,gBAAgB,EAAE;QACrB,OAAO,gBAAgB,CAAC;KACxB;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IACvC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAC,KAAK,EAAE,MAAM,EAAC,CAAC;IAE9B,OAAO,EAAC,KAAK,EAAE,MAAM,EAAC,CAAC;AACxB,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|