ink 6.7.0 → 7.0.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/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 +5 -2
- package/build/components/App.js +192 -41
- 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 +16 -3
- package/build/components/ErrorBoundary.d.ts +2 -2
- 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/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 +25 -5
- 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 +1 -1
- package/build/hooks/use-cursor.js +1 -1
- 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 +2 -1
- package/build/hooks/use-input.js +82 -80
- 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 +10 -1
- package/build/index.js +5 -0
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +55 -6
- package/build/ink.js +433 -162
- 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/log-update.d.ts +1 -0
- package/build/log-update.js +13 -1
- 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/output.d.ts +1 -0
- package/build/output.js +63 -5
- package/build/output.js.map +1 -1
- package/build/parse-keypress.d.ts +1 -3
- package/build/parse-keypress.js +19 -17
- package/build/parse-keypress.js.map +1 -1
- package/build/reconciler.js +48 -19
- package/build/reconciler.js.map +1 -1
- package/build/render-border.js +29 -18
- package/build/render-border.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 +69 -3
- package/build/render.js +18 -11
- 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 +78 -16
- package/build/styles.js +102 -31
- package/build/styles.js.map +1 -1
- package/build/utils.d.ts +9 -0
- package/build/utils.js +19 -0
- package/build/utils.js.map +1 -0
- package/build/wrap-text.js +7 -0
- package/build/wrap-text.js.map +1 -1
- package/build/write-synchronized.d.ts +1 -1
- package/build/write-synchronized.js +4 -2
- package/build/write-synchronized.js.map +1 -1
- package/package.json +40 -101
- package/readme.md +674 -56
- package/build/apply-styles.js +0 -175
- package/build/build-layout.js +0 -77
- package/build/calculate-wrapped-text.js +0 -53
- package/build/components/Color.js +0 -62
- package/build/experimental/apply-style.js +0 -140
- package/build/experimental/dom.js +0 -123
- package/build/experimental/output.js +0 -91
- package/build/experimental/reconciler.js +0 -141
- package/build/experimental/renderer.js +0 -81
- package/build/hooks/useInput.js +0 -38
- package/build/instance.js +0 -205
- package/build/options.d.ts +0 -52
- package/build/options.js +0 -2
- package/build/options.js.map +0 -1
- package/build/screen-reader-update.d.ts +0 -13
- package/build/screen-reader-update.js +0 -38
- package/build/screen-reader-update.js.map +0 -1
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _stringLength = _interopRequireDefault(require("string-length"));
|
|
9
|
-
|
|
10
|
-
var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* "Virtual" output class
|
|
16
|
-
*
|
|
17
|
-
* Handles the positioning and saving of the output of each node in the tree.
|
|
18
|
-
* Also responsible for applying transformations to each character of the output.
|
|
19
|
-
*
|
|
20
|
-
* Used to generate the final output of all nodes before writing it to actual output stream (e.g. stdout)
|
|
21
|
-
*/
|
|
22
|
-
class Output {
|
|
23
|
-
constructor({
|
|
24
|
-
width,
|
|
25
|
-
height
|
|
26
|
-
}) {
|
|
27
|
-
this.width = width;
|
|
28
|
-
this.height = height;
|
|
29
|
-
this.writes = []; // Initialize output array with a specific set of rows, so that margin/padding at the bottom is preserved
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
write(x, y, text, {
|
|
33
|
-
transformers
|
|
34
|
-
}) {
|
|
35
|
-
if (!text) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.writes.push({
|
|
40
|
-
x,
|
|
41
|
-
y,
|
|
42
|
-
text,
|
|
43
|
-
transformers
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get() {
|
|
48
|
-
const output = [];
|
|
49
|
-
|
|
50
|
-
for (let y = 0; y < this.height; y++) {
|
|
51
|
-
output.push(' '.repeat(this.width));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
for (const write of this.writes) {
|
|
55
|
-
const {
|
|
56
|
-
x,
|
|
57
|
-
y,
|
|
58
|
-
text,
|
|
59
|
-
transformers
|
|
60
|
-
} = write;
|
|
61
|
-
const lines = text.split('\n');
|
|
62
|
-
let offsetY = 0;
|
|
63
|
-
|
|
64
|
-
for (let line of lines) {
|
|
65
|
-
const currentLine = output[y + offsetY]; // Line can be missing if `text` is taller than height of pre-initialized `this.output`
|
|
66
|
-
|
|
67
|
-
if (!currentLine) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const length = (0, _stringLength.default)(line);
|
|
72
|
-
|
|
73
|
-
for (const transformer of transformers) {
|
|
74
|
-
line = transformer(line);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
output[y + offsetY] = (0, _sliceAnsi.default)(currentLine, 0, x) + line + (0, _sliceAnsi.default)(currentLine, x + length);
|
|
78
|
-
offsetY++;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const generatedOutput = output.map(line => line.trimRight()).join('\n');
|
|
83
|
-
return {
|
|
84
|
-
output: generatedOutput,
|
|
85
|
-
height: output.length
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
exports.default = Output;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _scheduler = require("scheduler");
|
|
9
|
-
|
|
10
|
-
var _reactReconciler = _interopRequireDefault(require("react-reconciler"));
|
|
11
|
-
|
|
12
|
-
var _dom = require("./dom");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
const NO_CONTEXT = true;
|
|
17
|
-
const hostConfig = {
|
|
18
|
-
schedulePassiveEffects: _scheduler.unstable_scheduleCallback,
|
|
19
|
-
cancelPassiveEffects: _scheduler.unstable_cancelCallback,
|
|
20
|
-
now: Date.now,
|
|
21
|
-
getRootHostContext: () => NO_CONTEXT,
|
|
22
|
-
prepareForCommit: () => {},
|
|
23
|
-
resetAfterCommit: rootNode => {
|
|
24
|
-
// Since renders are throttled at the instance level and <Static> component children
|
|
25
|
-
// are rendered only once and then get deleted, we need an escape hatch to
|
|
26
|
-
// trigger an immediate render to ensure <Static> children are written to output before they get erased
|
|
27
|
-
if (rootNode.isStaticDirty) {
|
|
28
|
-
rootNode.isStaticDirty = false;
|
|
29
|
-
rootNode.onImmediateRender();
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
rootNode.onRender();
|
|
34
|
-
},
|
|
35
|
-
getChildHostContext: () => NO_CONTEXT,
|
|
36
|
-
shouldSetTextContent: (type, props) => {
|
|
37
|
-
return typeof props.children === 'string' || typeof props.children === 'number';
|
|
38
|
-
},
|
|
39
|
-
createInstance: (type, newProps) => {
|
|
40
|
-
const node = (0, _dom.createNode)(type);
|
|
41
|
-
|
|
42
|
-
for (const [key, value] of Object.entries(newProps)) {
|
|
43
|
-
if (key === 'children') {
|
|
44
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
45
|
-
if (type === 'div') {
|
|
46
|
-
// Text node must be wrapped in another node, so that text can be aligned within container
|
|
47
|
-
const textNode = (0, _dom.createNode)('div');
|
|
48
|
-
(0, _dom.setTextContent)(textNode, value);
|
|
49
|
-
(0, _dom.appendChildNode)(node, textNode);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (type === 'span') {
|
|
53
|
-
(0, _dom.setTextContent)(node, value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} else if (key === 'style') {
|
|
57
|
-
(0, _dom.setStyle)(node, value);
|
|
58
|
-
} else if (key === 'unstable__transformChildren') {
|
|
59
|
-
node.unstable__transformChildren = value; // eslint-disable-line camelcase
|
|
60
|
-
} else if (key === 'unstable__static') {
|
|
61
|
-
node.unstable__static = true; // eslint-disable-line camelcase
|
|
62
|
-
} else {
|
|
63
|
-
(0, _dom.setAttribute)(node, key, value);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return node;
|
|
68
|
-
},
|
|
69
|
-
createTextInstance: _dom.createTextNode,
|
|
70
|
-
resetTextContent: node => {
|
|
71
|
-
if (node.textContent) {
|
|
72
|
-
node.textContent = '';
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (node.childNodes.length > 0) {
|
|
76
|
-
for (const childNode of node.childNodes) {
|
|
77
|
-
(0, _dom.removeChildNode)(node, childNode);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
getPublicInstance: instance => instance,
|
|
82
|
-
appendInitialChild: _dom.appendChildNode,
|
|
83
|
-
appendChild: _dom.appendChildNode,
|
|
84
|
-
insertBefore: _dom.insertBeforeNode,
|
|
85
|
-
finalizeInitialChildren: (node, type, props, rootNode) => {
|
|
86
|
-
if (node.unstable__static) {
|
|
87
|
-
rootNode.isStaticDirty = true;
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
supportsMutation: true,
|
|
91
|
-
appendChildToContainer: _dom.appendChildNode,
|
|
92
|
-
insertInContainerBefore: _dom.insertBeforeNode,
|
|
93
|
-
removeChildFromContainer: _dom.removeChildNode,
|
|
94
|
-
prepareUpdate: (node, type, oldProps, newProps, rootNode) => {
|
|
95
|
-
if (node.unstable__static) {
|
|
96
|
-
rootNode.isStaticDirty = true;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return true;
|
|
100
|
-
},
|
|
101
|
-
commitUpdate: (node, updatePayload, type, oldProps, newProps) => {
|
|
102
|
-
for (const [key, value] of Object.entries(newProps)) {
|
|
103
|
-
if (key === 'children') {
|
|
104
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
105
|
-
if (type === 'div') {
|
|
106
|
-
// Text node must be wrapped in another node, so that text can be aligned within container
|
|
107
|
-
// If there's no such node, a new one must be created
|
|
108
|
-
if (node.childNodes.length === 0) {
|
|
109
|
-
const textNode = (0, _dom.createNode)('div');
|
|
110
|
-
(0, _dom.setTextContent)(textNode, value);
|
|
111
|
-
(0, _dom.appendChildNode)(node, textNode);
|
|
112
|
-
} else {
|
|
113
|
-
(0, _dom.setTextContent)(node.childNodes[0], value);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (type === 'span') {
|
|
118
|
-
(0, _dom.setTextContent)(node, value);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
} else if (key === 'style') {
|
|
122
|
-
(0, _dom.setStyle)(node, value);
|
|
123
|
-
} else if (key === 'unstable__transformChildren') {
|
|
124
|
-
node.unstable__transformChildren = value; // eslint-disable-line camelcase
|
|
125
|
-
} else if (key === 'unstable__static') {
|
|
126
|
-
node.unstable__static = true; // eslint-disable-line camelcase
|
|
127
|
-
} else {
|
|
128
|
-
(0, _dom.setAttribute)(node, key, value);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
commitTextUpdate: (node, oldText, newText) => {
|
|
133
|
-
(0, _dom.setTextContent)(node, newText);
|
|
134
|
-
},
|
|
135
|
-
removeChild: _dom.removeChildNode
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
var _default = (0, _reactReconciler.default)(hostConfig); // eslint-disable-line new-cap
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
exports.default = _default;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _yogaLayoutPrebuilt = _interopRequireDefault(require("yoga-layout-prebuilt"));
|
|
9
|
-
|
|
10
|
-
var _renderNodeToOutput = _interopRequireDefault(require("../render-node-to-output"));
|
|
11
|
-
|
|
12
|
-
var _calculateWrappedText = _interopRequireDefault(require("../calculate-wrapped-text"));
|
|
13
|
-
|
|
14
|
-
var _output = _interopRequireDefault(require("./output"));
|
|
15
|
-
|
|
16
|
-
var _dom = require("./dom");
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
// Since <Static> components can be placed anywhere in the tree, this helper finds and returns them
|
|
21
|
-
const findStaticNode = node => {
|
|
22
|
-
if (node.unstable__static) {
|
|
23
|
-
return node;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
for (const childNode of node.childNodes) {
|
|
27
|
-
if (childNode.unstable__static) {
|
|
28
|
-
return childNode;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (Array.isArray(childNode.childNodes) && childNode.childNodes.length > 0) {
|
|
32
|
-
return findStaticNode(childNode);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
var _default = ({
|
|
38
|
-
terminalWidth = 100
|
|
39
|
-
}) => {
|
|
40
|
-
return node => {
|
|
41
|
-
(0, _dom.setStyle)(node, {
|
|
42
|
-
width: terminalWidth
|
|
43
|
-
});
|
|
44
|
-
node.yogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR);
|
|
45
|
-
(0, _calculateWrappedText.default)(node);
|
|
46
|
-
node.yogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR);
|
|
47
|
-
const output = new _output.default({
|
|
48
|
-
width: node.yogaNode.getComputedWidth(),
|
|
49
|
-
height: node.yogaNode.getComputedHeight()
|
|
50
|
-
});
|
|
51
|
-
(0, _renderNodeToOutput.default)(node, output, {
|
|
52
|
-
skipStaticElements: true
|
|
53
|
-
});
|
|
54
|
-
const staticNode = findStaticNode(node);
|
|
55
|
-
let staticOutput;
|
|
56
|
-
|
|
57
|
-
if (staticNode) {
|
|
58
|
-
staticOutput = new _output.default({
|
|
59
|
-
width: staticNode.yogaNode.getComputedWidth(),
|
|
60
|
-
height: staticNode.yogaNode.getComputedHeight()
|
|
61
|
-
});
|
|
62
|
-
(0, _renderNodeToOutput.default)(staticNode, staticOutput, {
|
|
63
|
-
skipStaticElements: false
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const {
|
|
68
|
-
output: generatedOutput,
|
|
69
|
-
height: outputHeight
|
|
70
|
-
} = output.get();
|
|
71
|
-
return {
|
|
72
|
-
output: generatedOutput,
|
|
73
|
-
outputHeight,
|
|
74
|
-
// Newline at the end is needed, because static output doesn't have one, so
|
|
75
|
-
// interactive output will override last line of static output
|
|
76
|
-
staticOutput: staticOutput ? `${staticOutput.get().output}\n` : undefined
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
exports.default = _default;
|
package/build/hooks/useInput.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
|
|
10
|
-
var _ = require("..");
|
|
11
|
-
|
|
12
|
-
var _default = inputHandler => {
|
|
13
|
-
const {
|
|
14
|
-
stdin,
|
|
15
|
-
setRawMode
|
|
16
|
-
} = (0, _react.useContext)(_.StdinContext);
|
|
17
|
-
(0, _react.useLayoutEffect)(() => {
|
|
18
|
-
setRawMode(true);
|
|
19
|
-
return () => setRawMode(false);
|
|
20
|
-
}, [setRawMode]);
|
|
21
|
-
(0, _react.useLayoutEffect)(() => {
|
|
22
|
-
const handleData = data => {
|
|
23
|
-
const input = String(data);
|
|
24
|
-
const meta = {
|
|
25
|
-
up: input === '\u001B[A',
|
|
26
|
-
down: input === '\u001B[B',
|
|
27
|
-
left: input === '\u001B[D',
|
|
28
|
-
right: input === '\u001B[C'
|
|
29
|
-
};
|
|
30
|
-
inputHandler(input, meta);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
stdin.on('data', handleData);
|
|
34
|
-
return () => stdin.off('data', handleData);
|
|
35
|
-
}, [stdin, inputHandler]);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
exports.default = _default;
|
package/build/instance.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
11
|
-
|
|
12
|
-
var _autoBind = _interopRequireDefault(require("auto-bind"));
|
|
13
|
-
|
|
14
|
-
var _logUpdate = _interopRequireDefault(require("log-update"));
|
|
15
|
-
|
|
16
|
-
var _isCi = _interopRequireDefault(require("is-ci"));
|
|
17
|
-
|
|
18
|
-
var _signalExit = _interopRequireDefault(require("signal-exit"));
|
|
19
|
-
|
|
20
|
-
var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
|
|
21
|
-
|
|
22
|
-
var _reconciler = _interopRequireDefault(require("./reconciler"));
|
|
23
|
-
|
|
24
|
-
var _reconciler2 = _interopRequireDefault(require("./experimental/reconciler"));
|
|
25
|
-
|
|
26
|
-
var _renderer = _interopRequireDefault(require("./renderer"));
|
|
27
|
-
|
|
28
|
-
var _renderer2 = _interopRequireDefault(require("./experimental/renderer"));
|
|
29
|
-
|
|
30
|
-
var dom = _interopRequireWildcard(require("./dom"));
|
|
31
|
-
|
|
32
|
-
var experimentalDom = _interopRequireWildcard(require("./experimental/dom"));
|
|
33
|
-
|
|
34
|
-
var _instances = _interopRequireDefault(require("./instances"));
|
|
35
|
-
|
|
36
|
-
var _App = _interopRequireDefault(require("./components/App"));
|
|
37
|
-
|
|
38
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
39
|
-
|
|
40
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
41
|
-
|
|
42
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
43
|
-
|
|
44
|
-
class Instance {
|
|
45
|
-
constructor(options) {
|
|
46
|
-
(0, _autoBind.default)(this);
|
|
47
|
-
this.options = options;
|
|
48
|
-
|
|
49
|
-
if (options.experimental) {
|
|
50
|
-
this.rootNode = experimentalDom.createNode('root');
|
|
51
|
-
this.rootNode.onRender = options.debug ? this.onRender : (0, _lodash.default)(this.onRender, 16, {
|
|
52
|
-
leading: true,
|
|
53
|
-
trailing: true
|
|
54
|
-
});
|
|
55
|
-
this.rootNode.onImmediateRender = this.onRender;
|
|
56
|
-
this.renderer = (0, _renderer2.default)({
|
|
57
|
-
terminalWidth: options.stdout.columns
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
this.rootNode = dom.createNode('root');
|
|
61
|
-
this.rootNode.onRender = this.onRender;
|
|
62
|
-
this.renderer = (0, _renderer.default)({
|
|
63
|
-
terminalWidth: options.stdout.columns
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.log = _logUpdate.default.create(options.stdout);
|
|
68
|
-
this.throttledLog = options.debug ? this.log : (0, _lodash.default)(this.log, {
|
|
69
|
-
leading: true,
|
|
70
|
-
trailing: true
|
|
71
|
-
}); // Ignore last render after unmounting a tree to prevent empty output before exit
|
|
72
|
-
|
|
73
|
-
this.isUnmounted = false; // Store last output to only rerender when needed
|
|
74
|
-
|
|
75
|
-
this.lastOutput = ''; // This variable is used only in debug mode to store full static output
|
|
76
|
-
// so that it's rerendered every time, not just new static parts, like in non-debug mode
|
|
77
|
-
|
|
78
|
-
this.fullStaticOutput = '';
|
|
79
|
-
|
|
80
|
-
if (options.experimental) {
|
|
81
|
-
this.container = _reconciler2.default.createContainer(this.rootNode, false, false);
|
|
82
|
-
} else {
|
|
83
|
-
this.container = _reconciler.default.createContainer(this.rootNode, false, false);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
this.exitPromise = new Promise((resolve, reject) => {
|
|
87
|
-
this.resolveExitPromise = resolve;
|
|
88
|
-
this.rejectExitPromise = reject;
|
|
89
|
-
}); // Unmount when process exits
|
|
90
|
-
|
|
91
|
-
this.unsubscribeExit = (0, _signalExit.default)(this.unmount, {
|
|
92
|
-
alwaysLast: false
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
onRender() {
|
|
97
|
-
if (this.isUnmounted) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const {
|
|
102
|
-
output,
|
|
103
|
-
outputHeight,
|
|
104
|
-
staticOutput
|
|
105
|
-
} = this.renderer(this.rootNode); // If <Static> output isn't empty, it means new children have been added to it
|
|
106
|
-
|
|
107
|
-
const hasStaticOutput = staticOutput && staticOutput !== '\n';
|
|
108
|
-
|
|
109
|
-
if (this.options.debug) {
|
|
110
|
-
if (hasStaticOutput) {
|
|
111
|
-
this.fullStaticOutput += staticOutput;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
this.options.stdout.write(this.fullStaticOutput + output);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (_isCi.default) {
|
|
119
|
-
if (hasStaticOutput) {
|
|
120
|
-
this.options.stdout.write(staticOutput);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this.lastOutput = output;
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (hasStaticOutput) {
|
|
128
|
-
this.fullStaticOutput += staticOutput;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (this.options.experimental && outputHeight >= this.options.stdout.rows) {
|
|
132
|
-
this.options.stdout.write(_ansiEscapes.default.clearTerminal + this.fullStaticOutput + output);
|
|
133
|
-
this.lastOutput = output;
|
|
134
|
-
return;
|
|
135
|
-
} // To ensure static output is cleanly rendered before main output, clear main output first
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (hasStaticOutput) {
|
|
139
|
-
this.log.clear();
|
|
140
|
-
this.options.stdout.write(staticOutput);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (output !== this.lastOutput) {
|
|
144
|
-
if (this.options.experimental) {
|
|
145
|
-
this.throttledLog(output);
|
|
146
|
-
} else {
|
|
147
|
-
this.log(output);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
render(node) {
|
|
153
|
-
const tree = _react.default.createElement(_App.default, {
|
|
154
|
-
stdin: this.options.stdin,
|
|
155
|
-
stdout: this.options.stdout,
|
|
156
|
-
exitOnCtrlC: this.options.exitOnCtrlC,
|
|
157
|
-
onExit: this.unmount
|
|
158
|
-
}, node);
|
|
159
|
-
|
|
160
|
-
if (this.options.experimental) {
|
|
161
|
-
_reconciler2.default.updateContainer(tree, this.container);
|
|
162
|
-
} else {
|
|
163
|
-
_reconciler.default.updateContainer(tree, this.container);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
unmount(error) {
|
|
168
|
-
if (this.isUnmounted) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
this.onRender();
|
|
173
|
-
this.unsubscribeExit(); // CIs don't handle erasing ansi escapes well, so it's better to
|
|
174
|
-
// only render last frame of non-static output
|
|
175
|
-
|
|
176
|
-
if (_isCi.default) {
|
|
177
|
-
this.options.stdout.write(this.lastOutput + '\n');
|
|
178
|
-
} else if (!this.options.debug) {
|
|
179
|
-
this.log.done();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
this.isUnmounted = true;
|
|
183
|
-
|
|
184
|
-
if (this.options.experimental) {
|
|
185
|
-
_reconciler2.default.updateContainer(null, this.container);
|
|
186
|
-
} else {
|
|
187
|
-
_reconciler.default.updateContainer(null, this.container);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
_instances.default.delete(this.options.stdout);
|
|
191
|
-
|
|
192
|
-
if (error instanceof Error) {
|
|
193
|
-
this.rejectExitPromise(error);
|
|
194
|
-
} else {
|
|
195
|
-
this.resolveExitPromise();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
waitUntilExit() {
|
|
200
|
-
return this.exitPromise;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
exports.default = Instance;
|
package/build/options.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export type CommonOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* Output stream where app will be rendered.
|
|
4
|
-
*
|
|
5
|
-
* @default process.stdout
|
|
6
|
-
*/
|
|
7
|
-
stdout?: NodeJS.WriteStream;
|
|
8
|
-
/**
|
|
9
|
-
* Input stream where app will listen for input.
|
|
10
|
-
*
|
|
11
|
-
* @default process.stdin
|
|
12
|
-
*/
|
|
13
|
-
stdin?: NodeJS.ReadStream;
|
|
14
|
-
/**
|
|
15
|
-
* Error stream.
|
|
16
|
-
* @default process.stderr
|
|
17
|
-
*/
|
|
18
|
-
stderr?: NodeJS.WriteStream;
|
|
19
|
-
/**
|
|
20
|
-
* If true, each update will be rendered as a separate output, without replacing the previous one.
|
|
21
|
-
*
|
|
22
|
-
* @default false
|
|
23
|
-
*/
|
|
24
|
-
debug?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Configure whether Ink should listen to Ctrl+C keyboard input and exit the app. This is needed in case `process.stdin` is in raw mode, because then Ctrl+C is ignored by default and process is expected to handle it manually.
|
|
27
|
-
*
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
exitOnCtrlC?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Patch console methods to ensure console output doesn't mix with Ink output.
|
|
33
|
-
*
|
|
34
|
-
* @default true
|
|
35
|
-
*/
|
|
36
|
-
patchConsole?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Enable screen reader support.
|
|
39
|
-
* See https://github.com/vadimdemedes/ink/blob/master/readme.md#screen-reader-support
|
|
40
|
-
*
|
|
41
|
-
* @default process.env['INK_SCREEN_READER'] === 'true'
|
|
42
|
-
*/
|
|
43
|
-
isScreenReaderEnabled?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Maximum frames per second for render updates.
|
|
46
|
-
* This controls how frequently the UI can update to prevent excessive re-rendering.
|
|
47
|
-
* Higher values allow more frequent updates but may impact performance.
|
|
48
|
-
*
|
|
49
|
-
* @default 30
|
|
50
|
-
*/
|
|
51
|
-
maxFps?: number;
|
|
52
|
-
};
|
package/build/options.js
DELETED
package/build/options.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":""}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type WriteStream } from 'node:tty';
|
|
2
|
-
declare class ScreenReaderUpdate {
|
|
3
|
-
private readonly stdout;
|
|
4
|
-
private readonly stderr;
|
|
5
|
-
private previousOutput;
|
|
6
|
-
private previousLineCount;
|
|
7
|
-
constructor(stdout: WriteStream, stderr: WriteStream);
|
|
8
|
-
private wrap;
|
|
9
|
-
render(output: string): void;
|
|
10
|
-
writeStdout(data: string): void;
|
|
11
|
-
writeStderr(data: string): void;
|
|
12
|
-
}
|
|
13
|
-
export default ScreenReaderUpdate;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import ansiEscapes from 'ansi-escapes';
|
|
2
|
-
import wrapAnsi from 'wrap-ansi';
|
|
3
|
-
class ScreenReaderUpdate {
|
|
4
|
-
stdout;
|
|
5
|
-
stderr;
|
|
6
|
-
previousOutput = '';
|
|
7
|
-
previousLineCount = 0;
|
|
8
|
-
constructor(stdout, stderr) {
|
|
9
|
-
this.stdout = stdout;
|
|
10
|
-
this.stderr = stderr;
|
|
11
|
-
}
|
|
12
|
-
wrap(output) {
|
|
13
|
-
const width = this.stdout.columns || 80;
|
|
14
|
-
return wrapAnsi(output, width, { trim: false, hard: true });
|
|
15
|
-
}
|
|
16
|
-
render(output) {
|
|
17
|
-
const wrapped = this.wrap(output);
|
|
18
|
-
if (wrapped === this.previousOutput) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const erase = this.previousLineCount > 0 ? ansiEscapes.eraseLines(this.previousLineCount) : '';
|
|
22
|
-
this.stdout.write(erase + wrapped);
|
|
23
|
-
this.previousOutput = wrapped;
|
|
24
|
-
this.previousLineCount = wrapped === '' ? 0 : wrapped.split('\n').length;
|
|
25
|
-
}
|
|
26
|
-
writeStdout(data) {
|
|
27
|
-
const erase = this.previousLineCount > 0 ? ansiEscapes.eraseLines(this.previousLineCount) : '';
|
|
28
|
-
this.stdout.write(erase + data + this.previousOutput);
|
|
29
|
-
}
|
|
30
|
-
writeStderr(data) {
|
|
31
|
-
const erase = this.previousLineCount > 0 ? ansiEscapes.eraseLines(this.previousLineCount) : '';
|
|
32
|
-
this.stdout.write(erase);
|
|
33
|
-
this.stderr.write(data);
|
|
34
|
-
this.stdout.write(this.previousOutput);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export default ScreenReaderUpdate;
|
|
38
|
-
//# sourceMappingURL=screen-reader-update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"screen-reader-update.js","sourceRoot":"","sources":["../src/screen-reader-update.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,MAAM,kBAAkB;IAKH;IACA;IALX,cAAc,GAAG,EAAE,CAAC;IACpB,iBAAiB,GAAG,CAAC,CAAC;IAE9B,YACmB,MAAmB,EACnB,MAAmB;QADnB,WAAM,GAAN,MAAM,CAAa;QACnB,WAAM,GAAN,MAAM,CAAa;IACnC,CAAC;IAEI,IAAI,CAAC,MAAc;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;QACxC,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,MAAc;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,OAAO,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;YACpC,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC;QAEnC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;QAC9B,IAAI,CAAC,iBAAiB,GAAG,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAC3E,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;IACxD,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACzC,CAAC;CACF;AAED,eAAe,kBAAkB,CAAC"}
|