ink 6.8.0 → 7.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/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 +4 -1
- package/build/components/App.js +142 -22
- package/build/components/App.js.map +1 -1
- package/build/components/AppContext.d.ts +23 -3
- package/build/components/AppContext.js +7 -4
- 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 +20 -1
- package/build/dom.js.map +1 -1
- package/build/hooks/use-animation.d.ts +49 -0
- package/build/hooks/use-animation.js +87 -0
- package/build/hooks/use-animation.js.map +1 -0
- package/build/hooks/use-app.d.ts +1 -1
- 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 +8 -1
- package/build/index.js +4 -0
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +48 -3
- package/build/ink.js +325 -155
- package/build/ink.js.map +1 -1
- package/build/input-parser.d.ts +4 -1
- package/build/input-parser.js +70 -30
- package/build/input-parser.js.map +1 -1
- 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.js +25 -0
- 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 +46 -27
- 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.js +2 -1
- package/build/render-to-string.js.map +1 -1
- package/build/render.d.ts +57 -2
- package/build/render.js +18 -11
- package/build/render.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 -2
- package/build/utils.js +18 -3
- package/build/utils.js.map +1 -1
- 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 +34 -98
- package/readme.md +554 -48
- 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/components/Cursor.d.ts +0 -83
- package/build/components/Cursor.js +0 -53
- package/build/components/Cursor.js.map +0 -1
- 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/layout.d.ts +0 -7
- package/build/layout.js +0 -33
- package/build/layout.js.map +0 -1
- 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
package/build/hooks/use-input.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useEffectEvent } from 'react';
|
|
2
2
|
import parseKeypress, { nonAlphanumericKeys } from '../parse-keypress.js';
|
|
3
3
|
import reconciler from '../reconciler.js';
|
|
4
|
-
import
|
|
4
|
+
import { useStdinContext } from './use-stdin.js';
|
|
5
5
|
/**
|
|
6
|
-
|
|
6
|
+
A React hook that returns `void` and handles user input.
|
|
7
|
+
It's a more convenient alternative to using `StdinContext` and listening for `data` events. The callback you pass to `useInput` is called for each character when the user enters any input. However, if the user pastes text and it's more than one character, the callback will be called only once, and the whole string will be passed as `input`.
|
|
7
8
|
|
|
8
9
|
```
|
|
9
10
|
import {useInput} from 'ink';
|
|
@@ -25,7 +26,7 @@ const UserInput = () => {
|
|
|
25
26
|
*/
|
|
26
27
|
const useInput = (inputHandler, options = {}) => {
|
|
27
28
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
|
-
const {
|
|
29
|
+
const { setRawMode, internal_exitOnCtrlC, internal_eventEmitter } = useStdinContext();
|
|
29
30
|
useEffect(() => {
|
|
30
31
|
if (options.isActive === false) {
|
|
31
32
|
return;
|
|
@@ -35,90 +36,91 @@ const useInput = (inputHandler, options = {}) => {
|
|
|
35
36
|
setRawMode(false);
|
|
36
37
|
};
|
|
37
38
|
}, [options.isActive, setRawMode]);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
eventType: keypress.eventType,
|
|
71
|
-
};
|
|
72
|
-
let input;
|
|
73
|
-
if (keypress.isKittyProtocol) {
|
|
74
|
-
// Use text-as-codepoints field for printable keys (needed when
|
|
75
|
-
// reportAllKeysAsEscapeCodes flag is enabled), suppress non-printable
|
|
76
|
-
if (keypress.isPrintable) {
|
|
77
|
-
input = keypress.text ?? keypress.name;
|
|
78
|
-
}
|
|
79
|
-
else if (keypress.ctrl && keypress.name.length === 1) {
|
|
80
|
-
// Ctrl+letter via codepoint 1-26 form: not printable text, but
|
|
81
|
-
// the letter name must flow through so handlers (e.g. exitOnCtrlC
|
|
82
|
-
// checking `input === 'c' && key.ctrl`) still work.
|
|
83
|
-
input = keypress.name;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
input = '';
|
|
87
|
-
}
|
|
39
|
+
const handleData = useEffectEvent((data) => {
|
|
40
|
+
const keypress = parseKeypress(data);
|
|
41
|
+
const key = {
|
|
42
|
+
upArrow: keypress.name === 'up',
|
|
43
|
+
downArrow: keypress.name === 'down',
|
|
44
|
+
leftArrow: keypress.name === 'left',
|
|
45
|
+
rightArrow: keypress.name === 'right',
|
|
46
|
+
pageDown: keypress.name === 'pagedown',
|
|
47
|
+
pageUp: keypress.name === 'pageup',
|
|
48
|
+
home: keypress.name === 'home',
|
|
49
|
+
end: keypress.name === 'end',
|
|
50
|
+
return: keypress.name === 'return',
|
|
51
|
+
escape: keypress.name === 'escape',
|
|
52
|
+
ctrl: keypress.ctrl,
|
|
53
|
+
shift: keypress.shift,
|
|
54
|
+
tab: keypress.name === 'tab',
|
|
55
|
+
backspace: keypress.name === 'backspace',
|
|
56
|
+
delete: keypress.name === 'delete',
|
|
57
|
+
meta: keypress.meta,
|
|
58
|
+
// Kitty keyboard protocol modifiers
|
|
59
|
+
super: keypress.super ?? false,
|
|
60
|
+
hyper: keypress.hyper ?? false,
|
|
61
|
+
capsLock: keypress.capsLock ?? false,
|
|
62
|
+
numLock: keypress.numLock ?? false,
|
|
63
|
+
eventType: keypress.eventType,
|
|
64
|
+
};
|
|
65
|
+
let input;
|
|
66
|
+
if (keypress.isKittyProtocol) {
|
|
67
|
+
// Use text-as-codepoints field for printable keys (needed when
|
|
68
|
+
// reportAllKeysAsEscapeCodes flag is enabled), suppress non-printable
|
|
69
|
+
if (keypress.isPrintable) {
|
|
70
|
+
input = keypress.text ?? keypress.name;
|
|
88
71
|
}
|
|
89
|
-
else if (keypress.ctrl) {
|
|
72
|
+
else if (keypress.ctrl && keypress.name.length === 1) {
|
|
73
|
+
// Ctrl+letter via codepoint 1-26 form: not printable text, but
|
|
74
|
+
// the letter name must flow through so handlers (e.g. exitOnCtrlC
|
|
75
|
+
// checking `input === 'c' && key.ctrl`) still work.
|
|
90
76
|
input = keypress.name;
|
|
91
77
|
}
|
|
92
78
|
else {
|
|
93
|
-
input = keypress.sequence;
|
|
94
|
-
}
|
|
95
|
-
if (!keypress.isKittyProtocol &&
|
|
96
|
-
nonAlphanumericKeys.includes(keypress.name)) {
|
|
97
79
|
input = '';
|
|
98
80
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
81
|
+
}
|
|
82
|
+
else if (keypress.ctrl) {
|
|
83
|
+
// Keypress.name is guaranteed non-undefined by parseKeypress,
|
|
84
|
+
// but guard defensively since a TypeError here would crash the
|
|
85
|
+
// entire Ink app (see https://github.com/vadimdemedes/ink/issues/901).
|
|
86
|
+
input = keypress.name ?? '';
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
input = keypress.sequence;
|
|
90
|
+
}
|
|
91
|
+
if (!keypress.isKittyProtocol &&
|
|
92
|
+
nonAlphanumericKeys.includes(keypress.name)) {
|
|
93
|
+
input = '';
|
|
94
|
+
}
|
|
95
|
+
// Strip escape prefix from broken/incomplete sequences that
|
|
96
|
+
// parseKeypress did not fully resolve (e.g. a flushed "\u001B[").
|
|
97
|
+
if (input.startsWith('\u001B')) {
|
|
98
|
+
input = input.slice(1);
|
|
99
|
+
}
|
|
100
|
+
if (input.length === 1 && /[A-Z]/.test(input)) {
|
|
101
|
+
key.shift = true;
|
|
102
|
+
}
|
|
103
|
+
// If app is supposed to exit on Ctrl+C, skip input listeners.
|
|
104
|
+
if (input === 'c' && key.ctrl && internal_exitOnCtrlC) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// Use discreteUpdates to assign DiscreteEventPriority to state
|
|
108
|
+
// updates from keyboard input, ensuring they are processed at the
|
|
109
|
+
// highest priority in concurrent mode.
|
|
110
|
+
// @ts-expect-error Types require 5 arguments (fn, a, b, c, d) but only fn is needed at runtime.
|
|
111
|
+
reconciler.discreteUpdates(() => {
|
|
112
|
+
inputHandler(input, key);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (options.isActive === false) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
internal_eventEmitter.on('input', handleData);
|
|
118
120
|
return () => {
|
|
119
|
-
internal_eventEmitter
|
|
121
|
+
internal_eventEmitter.removeListener('input', handleData);
|
|
120
122
|
};
|
|
121
|
-
}, [options.isActive,
|
|
123
|
+
}, [options.isActive, internal_eventEmitter]);
|
|
122
124
|
};
|
|
123
125
|
export default useInput;
|
|
124
126
|
//# sourceMappingURL=use-input.js.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"use-input.js","sourceRoot":"","sources":["../../src/hooks/use-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,cAAc,EAAC,MAAM,OAAO,CAAC;AAChD,OAAO,aAAa,EAAE,EAAC,mBAAmB,EAAC,MAAM,sBAAsB,CAAC;AACxE,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAqI/C;;;;;;;;;;;;;;;;;;;;;EAqBE;AACF,MAAM,QAAQ,GAAG,CAAC,YAAqB,EAAE,UAAmB,EAAE,EAAE,EAAE;IACjE,gEAAgE;IAChE,MAAM,EAAC,UAAU,EAAE,oBAAoB,EAAE,qBAAqB,EAAC,GAC9D,eAAe,EAAE,CAAC;IAEnB,SAAS,CAAC,GAAG,EAAE;Q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ED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,CAAC;QAED,8DAA8D;QAC9D,IAAI,KAAK,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,IAAI,oBAAoB,EAAE,CAAC;YACvD,OAAO;QACR,CAAC;QAED,+DAA+D;QAC/D,kEAAkE;QAClE,uCAAuC;QACvC,gGAAgG;QAChG,UAAU,CAAC,eAAe,CAAC,GAAG,EAAE;YAC/B,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YAChC,OAAO;QACR,CAAC;QAED,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAE9C,OAAO,GAAG,EAAE;YACX,qBAAqB,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
2
|
+
A React hook that returns whether a screen reader is enabled.
|
|
3
|
+
This is useful when you want to render different output for screen readers.
|
|
3
4
|
*/
|
|
4
5
|
declare const useIsScreenReaderEnabled: () => boolean;
|
|
5
6
|
export default useIsScreenReaderEnabled;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import { accessibilityContext } from '../components/AccessibilityContext.js';
|
|
3
3
|
/**
|
|
4
|
-
|
|
4
|
+
A React hook that returns whether a screen reader is enabled.
|
|
5
|
+
This is useful when you want to render different output for screen readers.
|
|
5
6
|
*/
|
|
6
7
|
const useIsScreenReaderEnabled = () => {
|
|
7
8
|
const { isScreenReaderEnabled } = useContext(accessibilityContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-is-screen-reader-enabled.js","sourceRoot":"","sources":["../../src/hooks/use-is-screen-reader-enabled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,EAAC,oBAAoB,EAAC,MAAM,uCAAuC,CAAC;AAE3E
|
|
1
|
+
{"version":3,"file":"use-is-screen-reader-enabled.js","sourceRoot":"","sources":["../../src/hooks/use-is-screen-reader-enabled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,EAAC,oBAAoB,EAAC,MAAM,uCAAuC,CAAC;AAE3E;;;EAGE;AACF,MAAM,wBAAwB,GAAG,GAAY,EAAE;IAC9C,MAAM,EAAC,qBAAqB,EAAC,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACjE,OAAO,qBAAqB,CAAC;AAC9B,CAAC,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type Options = {
|
|
2
|
+
/**
|
|
3
|
+
Enable or disable the paste handler. Useful when multiple components use `usePaste` and only one should be active at a time.
|
|
4
|
+
|
|
5
|
+
@default true
|
|
6
|
+
*/
|
|
7
|
+
isActive?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
A React hook that calls `handler` whenever the user pastes text in the terminal. Bracketed paste mode (`\x1b[?2004h`) is automatically enabled while the hook is active, so pasted text arrives as a single string rather than being misinterpreted as individual key presses.
|
|
11
|
+
|
|
12
|
+
`usePaste` and `useInput` can be used together in the same component. They operate on separate event channels, so paste content is never forwarded to `useInput` handlers when `usePaste` is active.
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
import {useInput, usePaste} from 'ink';
|
|
16
|
+
|
|
17
|
+
const MyInput = () => {
|
|
18
|
+
useInput((input, key) => {
|
|
19
|
+
// Only receives typed characters and key events, not pasted text.
|
|
20
|
+
if (key.return) {
|
|
21
|
+
// Submit
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
usePaste((text) => {
|
|
26
|
+
// Receives the full pasted string, including newlines.
|
|
27
|
+
console.log('Pasted:', text);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return …
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
*/
|
|
34
|
+
declare const usePaste: (handler: (text: string) => void, options?: Options) => void;
|
|
35
|
+
export default usePaste;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useEffect, useEffectEvent } from 'react';
|
|
2
|
+
import reconciler from '../reconciler.js';
|
|
3
|
+
import { useStdinContext } from './use-stdin.js';
|
|
4
|
+
/**
|
|
5
|
+
A React hook that calls `handler` whenever the user pastes text in the terminal. Bracketed paste mode (`\x1b[?2004h`) is automatically enabled while the hook is active, so pasted text arrives as a single string rather than being misinterpreted as individual key presses.
|
|
6
|
+
|
|
7
|
+
`usePaste` and `useInput` can be used together in the same component. They operate on separate event channels, so paste content is never forwarded to `useInput` handlers when `usePaste` is active.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
import {useInput, usePaste} from 'ink';
|
|
11
|
+
|
|
12
|
+
const MyInput = () => {
|
|
13
|
+
useInput((input, key) => {
|
|
14
|
+
// Only receives typed characters and key events, not pasted text.
|
|
15
|
+
if (key.return) {
|
|
16
|
+
// Submit
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
usePaste((text) => {
|
|
21
|
+
// Receives the full pasted string, including newlines.
|
|
22
|
+
console.log('Pasted:', text);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return …
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
*/
|
|
29
|
+
const usePaste = (handler, options = {}) => {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
31
|
+
const { setRawMode, setBracketedPasteMode, internal_eventEmitter } = useStdinContext();
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (options.isActive === false) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
setRawMode(true);
|
|
37
|
+
setBracketedPasteMode(true);
|
|
38
|
+
return () => {
|
|
39
|
+
setRawMode(false);
|
|
40
|
+
setBracketedPasteMode(false);
|
|
41
|
+
};
|
|
42
|
+
}, [options.isActive, setRawMode, setBracketedPasteMode]);
|
|
43
|
+
const handlePaste = useEffectEvent((text) => {
|
|
44
|
+
// Use discreteUpdates to assign DiscreteEventPriority to state
|
|
45
|
+
// updates triggered by paste, matching the priority of useInput.
|
|
46
|
+
// @ts-expect-error Types require 5 arguments (fn, a, b, c, d) but only fn is needed at runtime.
|
|
47
|
+
reconciler.discreteUpdates(() => {
|
|
48
|
+
handler(text);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (options.isActive === false) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
internal_eventEmitter.on('paste', handlePaste);
|
|
56
|
+
return () => {
|
|
57
|
+
internal_eventEmitter.removeListener('paste', handlePaste);
|
|
58
|
+
};
|
|
59
|
+
}, [options.isActive, internal_eventEmitter]);
|
|
60
|
+
};
|
|
61
|
+
export default usePaste;
|
|
62
|
+
//# sourceMappingURL=use-paste.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-paste.js","sourceRoot":"","sources":["../../src/hooks/use-paste.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,cAAc,EAAC,MAAM,OAAO,CAAC;AAChD,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAW/C;;;;;;;;;;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
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import StderrContext from '../components/StderrContext.js';
|
|
3
3
|
/**
|
|
4
|
-
|
|
4
|
+
A React hook that returns the stderr stream.
|
|
5
5
|
*/
|
|
6
6
|
const useStderr = () => useContext(StderrContext);
|
|
7
7
|
export default useStderr;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { type PublicProps, type Props } from '../components/StdinContext.js';
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
+
A React hook that returns the stdin stream and stdin-related utilities.
|
|
3
4
|
*/
|
|
4
|
-
declare const useStdin: () =>
|
|
5
|
+
declare const useStdin: () => PublicProps;
|
|
6
|
+
export declare const useStdinContext: () => Props;
|
|
5
7
|
export default useStdin;
|
package/build/hooks/use-stdin.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import StdinContext from '../components/StdinContext.js';
|
|
3
3
|
/**
|
|
4
|
-
|
|
4
|
+
A React hook that returns the stdin stream and stdin-related utilities.
|
|
5
5
|
*/
|
|
6
6
|
const useStdin = () => useContext(StdinContext);
|
|
7
|
+
export const useStdinContext = () => useContext(StdinContext);
|
|
7
8
|
export default useStdin;
|
|
8
9
|
//# sourceMappingURL=use-stdin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-stdin.js","sourceRoot":"","sources":["../../src/hooks/use-stdin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"use-stdin.js","sourceRoot":"","sources":["../../src/hooks/use-stdin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,YAGN,MAAM,+BAA+B,CAAC;AAEvC;;EAEE;AACF,MAAM,QAAQ,GAAG,GAAgB,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AAE7D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAU,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AAErE,eAAe,QAAQ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
2
|
+
A React hook that returns the stdout stream where Ink renders your app.
|
|
3
3
|
*/
|
|
4
4
|
declare const useStdout: () => import("../components/StdoutContext.js").Props;
|
|
5
5
|
export default useStdout;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import StdoutContext from '../components/StdoutContext.js';
|
|
3
3
|
/**
|
|
4
|
-
|
|
4
|
+
A React hook that returns the stdout stream where Ink renders your app.
|
|
5
5
|
*/
|
|
6
6
|
const useStdout = () => useContext(StdoutContext);
|
|
7
7
|
export default useStdout;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Dimensions of the terminal window.
|
|
3
|
+
*/
|
|
4
|
+
export type WindowSize = {
|
|
5
|
+
/**
|
|
6
|
+
Number of columns (horizontal character cells).
|
|
7
|
+
*/
|
|
8
|
+
readonly columns: number;
|
|
9
|
+
/**
|
|
10
|
+
Number of rows (vertical character cells).
|
|
11
|
+
*/
|
|
12
|
+
readonly rows: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
A React hook that returns the current terminal window dimensions and re-renders the component whenever the terminal is resized.
|
|
16
|
+
*/
|
|
17
|
+
declare const useWindowSize: () => WindowSize;
|
|
18
|
+
export default useWindowSize;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { getWindowSize } from '../utils.js';
|
|
3
|
+
import useStdout from './use-stdout.js';
|
|
4
|
+
/**
|
|
5
|
+
A React hook that returns the current terminal window dimensions and re-renders the component whenever the terminal is resized.
|
|
6
|
+
*/
|
|
7
|
+
const useWindowSize = () => {
|
|
8
|
+
const { stdout } = useStdout();
|
|
9
|
+
const [size, setSize] = useState(() => getWindowSize(stdout));
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const onResize = () => {
|
|
12
|
+
setSize(getWindowSize(stdout));
|
|
13
|
+
};
|
|
14
|
+
stdout.on('resize', onResize);
|
|
15
|
+
return () => {
|
|
16
|
+
stdout.off('resize', onResize);
|
|
17
|
+
};
|
|
18
|
+
}, [stdout]);
|
|
19
|
+
return size;
|
|
20
|
+
};
|
|
21
|
+
export default useWindowSize;
|
|
22
|
+
//# sourceMappingURL=use-window-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-window-size.js","sourceRoot":"","sources":["../../src/hooks/use-window-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAiBxC;;EAEE;AACF,MAAM,aAAa,GAAG,GAAe,EAAE;IACtC,MAAM,EAAC,MAAM,EAAC,GAAG,SAAS,EAAE,CAAC;IAC7B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAa,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAE1E,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,QAAQ,GAAG,GAAG,EAAE;YACrB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QAChC,CAAC,CAAC;QAEF,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAE9B,OAAO,GAAG,EAAE;YACX,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
package/build/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { default as Box } from './components/Box.js';
|
|
|
7
7
|
export type { Props as TextProps } from './components/Text.js';
|
|
8
8
|
export { default as Text } from './components/Text.js';
|
|
9
9
|
export type { Props as AppProps } from './components/AppContext.js';
|
|
10
|
-
export type {
|
|
10
|
+
export type { PublicProps as StdinProps } from './components/StdinContext.js';
|
|
11
11
|
export type { Props as StdoutProps } from './components/StdoutContext.js';
|
|
12
12
|
export type { Props as StderrProps } from './components/StderrContext.js';
|
|
13
13
|
export type { Props as StaticProps } from './components/Static.js';
|
|
@@ -19,6 +19,7 @@ export { default as Newline } from './components/Newline.js';
|
|
|
19
19
|
export { default as Spacer } from './components/Spacer.js';
|
|
20
20
|
export type { Key } from './hooks/use-input.js';
|
|
21
21
|
export { default as useInput } from './hooks/use-input.js';
|
|
22
|
+
export { default as usePaste } from './hooks/use-paste.js';
|
|
22
23
|
export { default as useApp } from './hooks/use-app.js';
|
|
23
24
|
export { default as useStdin } from './hooks/use-stdin.js';
|
|
24
25
|
export { default as useStdout } from './hooks/use-stdout.js';
|
|
@@ -27,6 +28,12 @@ export { default as useFocus } from './hooks/use-focus.js';
|
|
|
27
28
|
export { default as useFocusManager } from './hooks/use-focus-manager.js';
|
|
28
29
|
export { default as useIsScreenReaderEnabled } from './hooks/use-is-screen-reader-enabled.js';
|
|
29
30
|
export { default as useCursor } from './hooks/use-cursor.js';
|
|
31
|
+
export type { AnimationResult } from './hooks/use-animation.js';
|
|
32
|
+
export { default as useAnimation } from './hooks/use-animation.js';
|
|
33
|
+
export type { WindowSize } from './hooks/use-window-size.js';
|
|
34
|
+
export { default as useWindowSize } from './hooks/use-window-size.js';
|
|
35
|
+
export type { BoxMetrics, UseBoxMetricsResult } from './hooks/use-box-metrics.js';
|
|
36
|
+
export { default as useBoxMetrics } from './hooks/use-box-metrics.js';
|
|
30
37
|
export type { CursorPosition } from './log-update.js';
|
|
31
38
|
export { default as measureElement } from './measure-element.js';
|
|
32
39
|
export type { DOMElement } from './dom.js';
|
package/build/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { default as Transform } from './components/Transform.js';
|
|
|
7
7
|
export { default as Newline } from './components/Newline.js';
|
|
8
8
|
export { default as Spacer } from './components/Spacer.js';
|
|
9
9
|
export { default as useInput } from './hooks/use-input.js';
|
|
10
|
+
export { default as usePaste } from './hooks/use-paste.js';
|
|
10
11
|
export { default as useApp } from './hooks/use-app.js';
|
|
11
12
|
export { default as useStdin } from './hooks/use-stdin.js';
|
|
12
13
|
export { default as useStdout } from './hooks/use-stdout.js';
|
|
@@ -15,6 +16,9 @@ export { default as useFocus } from './hooks/use-focus.js';
|
|
|
15
16
|
export { default as useFocusManager } from './hooks/use-focus-manager.js';
|
|
16
17
|
export { default as useIsScreenReaderEnabled } from './hooks/use-is-screen-reader-enabled.js';
|
|
17
18
|
export { default as useCursor } from './hooks/use-cursor.js';
|
|
19
|
+
export { default as useAnimation } from './hooks/use-animation.js';
|
|
20
|
+
export { default as useWindowSize } from './hooks/use-window-size.js';
|
|
21
|
+
export { default as useBoxMetrics } from './hooks/use-box-metrics.js';
|
|
18
22
|
export { default as measureElement } from './measure-element.js';
|
|
19
23
|
export { kittyFlags, kittyModifiers } from './kitty-keyboard.js';
|
|
20
24
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAAC,OAAO,IAAI,GAAG,EAAC,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAC,OAAO,IAAI,IAAI,EAAC,MAAM,sBAAsB,CAAC;AAMrD,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAEzD,O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 export type Options = {
|
|
|
30
30
|
- `useTransition` and `useDeferredValue` are fully functional
|
|
31
31
|
- Updates can be interrupted for higher priority work
|
|
32
32
|
|
|
33
|
-
Note: Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates.
|
|
33
|
+
Note: Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates. Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change the rendering mode or create a fresh instance.
|
|
34
34
|
|
|
35
35
|
@default false
|
|
36
36
|
@experimental
|
|
37
37
|
*/
|
|
38
38
|
concurrent?: boolean;
|
|
39
39
|
kittyKeyboard?: KittyKeyboardOptions;
|
|
40
|
+
/**
|
|
41
|
+
Override automatic interactive mode detection.
|
|
42
|
+
|
|
43
|
+
By default, Ink detects whether the environment is interactive based on CI detection (via [`is-in-ci`](https://github.com/sindresorhus/is-in-ci)) and `stdout.isTTY`. Most users should not need to set this.
|
|
44
|
+
|
|
45
|
+
When non-interactive, Ink disables ANSI erase sequences, cursor manipulation, synchronized output, resize handling, and kitty keyboard auto-detection, writing only the final frame at unmount.
|
|
46
|
+
|
|
47
|
+
Set to `false` to force non-interactive mode or `true` to force interactive mode when the automatic detection doesn't suit your use case.
|
|
48
|
+
|
|
49
|
+
Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
|
|
50
|
+
|
|
51
|
+
@default true (false if in CI or `stdout.isTTY` is falsy)
|
|
52
|
+
|
|
53
|
+
@see {@link RenderOptions.interactive}
|
|
54
|
+
*/
|
|
55
|
+
interactive?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
Render the app in the terminal's alternate screen buffer. When enabled, the app renders on a separate screen, and the original terminal content is restored when the app exits. This is the same mechanism used by programs like vim, htop, and less.
|
|
58
|
+
|
|
59
|
+
Note: The terminal's scrollback buffer is not available while in the alternate screen. This is standard terminal behavior; programs like vim use the alternate screen specifically to avoid polluting the user's scrollback history.
|
|
60
|
+
|
|
61
|
+
Note: Ink intentionally treats alternate-screen teardown output as disposable. It does not preserve or replay teardown-time frames, hook writes, or `console.*` output after restoring the primary screen.
|
|
62
|
+
|
|
63
|
+
Only works in interactive mode. Ignored when `interactive` is `false` or in a non-interactive environment (CI, piped stdout).
|
|
64
|
+
|
|
65
|
+
Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
|
|
66
|
+
|
|
67
|
+
@default false
|
|
68
|
+
|
|
69
|
+
@see {@link RenderOptions.alternateScreen}
|
|
70
|
+
*/
|
|
71
|
+
alternateScreen?: boolean;
|
|
40
72
|
};
|
|
41
73
|
export default class Ink {
|
|
42
74
|
/**
|
|
@@ -48,6 +80,9 @@ export default class Ink {
|
|
|
48
80
|
private cursorPosition;
|
|
49
81
|
private readonly throttledLog;
|
|
50
82
|
private readonly isScreenReaderEnabled;
|
|
83
|
+
private readonly interactive;
|
|
84
|
+
private readonly renderThrottleMs;
|
|
85
|
+
private alternateScreen;
|
|
51
86
|
private isUnmounted;
|
|
52
87
|
private isUnmounting;
|
|
53
88
|
private lastOutput;
|
|
@@ -57,7 +92,7 @@ export default class Ink {
|
|
|
57
92
|
private readonly container;
|
|
58
93
|
private readonly rootNode;
|
|
59
94
|
private fullStaticOutput;
|
|
60
|
-
private exitPromise
|
|
95
|
+
private readonly exitPromise;
|
|
61
96
|
private exitResult;
|
|
62
97
|
private beforeExitHandler?;
|
|
63
98
|
private restoreConsole?;
|
|
@@ -66,8 +101,8 @@ export default class Ink {
|
|
|
66
101
|
private hasPendingThrottledRender;
|
|
67
102
|
private kittyProtocolEnabled;
|
|
68
103
|
private cancelKittyDetection?;
|
|
104
|
+
private nextRenderCommit?;
|
|
69
105
|
constructor(options: Options);
|
|
70
|
-
getTerminalWidth: () => number;
|
|
71
106
|
resized: () => void;
|
|
72
107
|
resolveExitPromise: (result?: unknown) => void;
|
|
73
108
|
rejectExitPromise: (reason?: Error) => void;
|
|
@@ -82,8 +117,18 @@ export default class Ink {
|
|
|
82
117
|
writeToStderr(data: string): void;
|
|
83
118
|
unmount(error?: Error | number | null): void;
|
|
84
119
|
waitUntilExit(): Promise<unknown>;
|
|
120
|
+
waitUntilRenderFlush(): Promise<void>;
|
|
85
121
|
clear(): void;
|
|
86
122
|
patchConsole(): void;
|
|
123
|
+
private setAlternateScreen;
|
|
124
|
+
private resolveInteractiveOption;
|
|
125
|
+
private resolveAlternateScreenOption;
|
|
126
|
+
private shouldSync;
|
|
127
|
+
private writeBestEffort;
|
|
128
|
+
private awaitExit;
|
|
129
|
+
private hasPendingConcurrentWork;
|
|
130
|
+
private awaitNextRender;
|
|
131
|
+
private renderInteractiveFrame;
|
|
87
132
|
private initKittyKeyboard;
|
|
88
133
|
private confirmKittySupport;
|
|
89
134
|
private enableKittyProtocol;
|