ink 4.4.1 → 5.0.1
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/apply-styles.js +175 -0
- package/build/build-layout.js +77 -0
- package/build/calculate-wrapped-text.js +53 -0
- package/build/colorize.js.map +1 -1
- package/build/components/App.d.ts +1 -1
- package/build/components/App.js +198 -296
- package/build/components/App.js.map +1 -1
- package/build/components/AppContext.js +1 -1
- package/build/components/Box.d.ts +51 -1
- package/build/components/Box.js +2 -2
- package/build/components/Color.js +62 -0
- package/build/components/ErrorOverview.js +1 -1
- package/build/components/ErrorOverview.js.map +1 -1
- package/build/components/FocusContext.js +1 -1
- package/build/components/Static.js +1 -1
- package/build/components/StderrContext.js +1 -1
- package/build/components/StdinContext.js +1 -1
- package/build/components/StdoutContext.js +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.js.map +1 -1
- package/build/devtools-window-polyfill.js +11 -17
- package/build/devtools-window-polyfill.js.map +1 -1
- package/build/dom.js +2 -3
- package/build/dom.js.map +1 -1
- package/build/experimental/apply-style.js +140 -0
- package/build/experimental/dom.js +123 -0
- package/build/experimental/output.js +91 -0
- package/build/experimental/reconciler.js +141 -0
- package/build/experimental/renderer.js +81 -0
- package/build/get-max-width.js +0 -1
- package/build/get-max-width.js.map +1 -1
- package/build/hooks/use-focus-manager.js +1 -1
- package/build/hooks/use-focus.d.ts +1 -1
- package/build/hooks/use-focus.js +2 -2
- package/build/hooks/use-focus.js.map +1 -1
- package/build/hooks/use-input.js +2 -3
- package/build/hooks/use-input.js.map +1 -1
- package/build/hooks/useInput.js +38 -0
- package/build/ink.js +81 -170
- package/build/ink.js.map +1 -1
- package/build/instance.js +205 -0
- package/build/log-update.d.ts +1 -0
- package/build/log-update.js.map +1 -1
- package/build/measure-element.js +1 -1
- package/build/measure-text.js +1 -1
- package/build/measure-text.js.map +1 -1
- package/build/output.js +11 -26
- package/build/output.js.map +1 -1
- package/build/parse-keypress.d.ts +1 -0
- package/build/parse-keypress.js +4 -4
- package/build/parse-keypress.js.map +1 -1
- package/build/reconciler.js +9 -7
- package/build/reconciler.js.map +1 -1
- package/build/render-border.js +1 -1
- package/build/render-border.js.map +1 -1
- package/build/render-node-to-output.js +2 -3
- package/build/render-node-to-output.js.map +1 -1
- package/build/render.d.ts +4 -0
- package/build/render.js +3 -3
- package/build/render.js.map +1 -1
- package/build/renderer.js +5 -5
- package/build/renderer.js.map +1 -1
- package/build/squash-text-nodes.js.map +1 -1
- package/build/styles.d.ts +1 -1
- package/build/styles.js +0 -1
- package/build/styles.js.map +1 -1
- package/build/wrap-text.js +1 -1
- package/build/wrap-text.js.map +1 -1
- package/package.json +35 -39
- package/readme.md +5 -18
|
@@ -0,0 +1,141 @@
|
|
|
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;
|
|
@@ -0,0 +1,81 @@
|
|
|
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/get-max-width.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-max-width.js","sourceRoot":"","sources":["../src/get-max-width.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"get-max-width.js","sourceRoot":"","sources":["../src/get-max-width.ts"],"names":[],"mappings":"AAAA,OAAO,IAA6B,MAAM,oBAAoB,CAAC;AAE/D,MAAM,WAAW,GAAG,CAAC,QAAkB,EAAE,EAAE;IAC1C,OAAO,CACN,QAAQ,CAAC,gBAAgB,EAAE;QAC3B,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC;QAC3C,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC;QAC5C,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC;QAC1C,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAC3C,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -11,7 +11,7 @@ const useFocusManager = () => {
|
|
|
11
11
|
disableFocus: focusContext.disableFocus,
|
|
12
12
|
focusNext: focusContext.focusNext,
|
|
13
13
|
focusPrevious: focusContext.focusPrevious,
|
|
14
|
-
focus: focusContext.focus
|
|
14
|
+
focus: focusContext.focus,
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
export default useFocusManager;
|
|
@@ -30,5 +30,5 @@ type Output = {
|
|
|
30
30
|
* This hook returns an object with `isFocused` boolean property, which
|
|
31
31
|
* determines if this component is focused or not.
|
|
32
32
|
*/
|
|
33
|
-
declare const useFocus: ({ isActive, autoFocus, id: customId }?: Input) => Output;
|
|
33
|
+
declare const useFocus: ({ isActive, autoFocus, id: customId, }?: Input) => Output;
|
|
34
34
|
export default useFocus;
|
package/build/hooks/use-focus.js
CHANGED
|
@@ -9,7 +9,7 @@ import useStdin from './use-stdin.js';
|
|
|
9
9
|
* This hook returns an object with `isFocused` boolean property, which
|
|
10
10
|
* determines if this component is focused or not.
|
|
11
11
|
*/
|
|
12
|
-
const useFocus = ({ isActive = true, autoFocus = false, id: customId } = {}) => {
|
|
12
|
+
const useFocus = ({ isActive = true, autoFocus = false, id: customId, } = {}) => {
|
|
13
13
|
const { isRawModeSupported, setRawMode } = useStdin();
|
|
14
14
|
const { activeId, add, remove, activate, deactivate, focus } = useContext(FocusContext);
|
|
15
15
|
const id = useMemo(() => {
|
|
@@ -40,7 +40,7 @@ const useFocus = ({ isActive = true, autoFocus = false, id: customId } = {}) =>
|
|
|
40
40
|
}, [isActive]);
|
|
41
41
|
return {
|
|
42
42
|
isFocused: Boolean(id) && activeId === id,
|
|
43
|
-
focus
|
|
43
|
+
focus,
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
46
|
export default useFocus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-focus.js","sourceRoot":"","sources":["../../src/hooks/use-focus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AACrD,OAAO,YAAY,MAAM,+BAA+B,CAAC;AACzD,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AA+BtC;;;;;;;GAOG;AACH,MAAM,QAAQ,GAAG,CAAC,EACjB,QAAQ,GAA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QAChB,CAAC;IACF,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IAEnB,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,kBAAkB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACtC,OAAO;QACR,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,CAAC;QAEjB,OAAO,GAAG,EAAE;YACX,UAAU,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO;QACN,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,QAAQ,KAAK,EAAE;QACzC,KAAK;KACL,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/build/hooks/use-input.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import { isUpperCase } from 'is-upper-case';
|
|
3
2
|
import parseKeypress, { nonAlphanumericKeys } from '../parse-keypress.js';
|
|
4
3
|
import reconciler from '../reconciler.js';
|
|
5
4
|
import useStdin from './use-stdin.js';
|
|
@@ -63,7 +62,7 @@ const useInput = (inputHandler, options = {}) => {
|
|
|
63
62
|
// but with option = true, so we need to take this into account here
|
|
64
63
|
// to avoid breaking changes in Ink.
|
|
65
64
|
// TODO(vadimdemedes): consider removing this in the next major version.
|
|
66
|
-
meta: keypress.meta || keypress.name === 'escape' || keypress.option
|
|
65
|
+
meta: keypress.meta || keypress.name === 'escape' || keypress.option,
|
|
67
66
|
};
|
|
68
67
|
let input = keypress.ctrl ? keypress.name : keypress.sequence;
|
|
69
68
|
if (nonAlphanumericKeys.includes(keypress.name)) {
|
|
@@ -76,7 +75,7 @@ const useInput = (inputHandler, options = {}) => {
|
|
|
76
75
|
}
|
|
77
76
|
if (input.length === 1 &&
|
|
78
77
|
typeof input[0] === 'string' &&
|
|
79
|
-
|
|
78
|
+
input[0].toUpperCase() === input[0]) {
|
|
80
79
|
key.shift = true;
|
|
81
80
|
}
|
|
82
81
|
// If app is not supposed to exit on Ctrl+C, then let input listener handle it
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-input.js","sourceRoot":"","sources":["../../src/hooks/use-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,
|
|
1
|
+
{"version":3,"file":"use-input.js","sourceRoot":"","sources":["../../src/hooks/use-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,aAAa,EAAE,EAAC,mBAAmB,EAAC,MAAM,sBAAsB,CAAC;AACxE,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAyFtC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,QAAQ,GAAG,CAAC,YAAqB,EAAE,UAAmB,EAAE,EAAE,EAAE;IACjE,gEAAgE;IAChE,MAAM,EAAC,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,qBAAqB,EAAC,GACrE,QAAQ,EAAE,CAAC;IAEZ,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YAChC,OAAO;QACR,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,CAAC;QAEjB,OAAO,GAAG,EAAE;YACX,UAAU,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YAChC,OAAO;QACR,CAAC;QAED,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;YACnC,MAAM,QAAQ,GAAG,aAAa,CAAC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AAK,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC;YAED,IACC,KAAK,CAAC,MAAM,KAAK,CAAC;gBAClB,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAC5B,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,EAClC,CAAC;gBACF,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,CAAC;YAED,8EAA8E;YAC9E,IAAI,CAAC,CAAC,KAAK,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;gBAC3D,4JAA4J;gBAC5J,UAAU,CAAC,cAAc,CAAC,GAAG,EAAE;oBAC9B,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBAC1B,CAAC,CAAC,CAAC;YACJ,CAAC;QACF,CAAC,CAAC;QAEF,qBAAqB,EAAE,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAE/C,OAAO,GAAG,EAAE;YACX,qBAAqB,EAAE,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,oBAAoB,EAAE,YAAY,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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;
|