@nuvin/ink 6.6.7 → 7.0.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ansi-tokenizer.d.ts +38 -0
- package/build/ansi-tokenizer.d.ts.map +1 -0
- package/build/ansi-tokenizer.js +316 -0
- package/build/ansi-tokenizer.js.map +1 -0
- package/build/colorize.d.ts.map +1 -0
- package/build/components/AccessibilityContext.d.ts.map +1 -0
- package/build/components/AnimationContext.d.ts +9 -0
- package/build/components/AnimationContext.d.ts.map +1 -0
- package/build/components/AnimationContext.js +13 -0
- package/build/components/AnimationContext.js.map +1 -0
- package/build/components/App.d.ts +11 -49
- package/build/components/App.d.ts.map +1 -0
- package/build/components/App.js +412 -227
- package/build/components/App.js.map +1 -1
- package/build/components/AppContext.d.ts +33 -3
- package/build/components/AppContext.d.ts.map +1 -0
- package/build/components/AppContext.js +2 -1
- package/build/components/AppContext.js.map +1 -1
- package/build/components/BackgroundContext.d.ts.map +1 -0
- package/build/components/Box.d.ts +15 -8
- package/build/components/Box.d.ts.map +1 -0
- package/build/components/Box.js +12 -10
- package/build/components/Box.js.map +1 -1
- package/build/components/CursorContext.d.ts +11 -0
- package/build/components/CursorContext.d.ts.map +1 -0
- package/build/components/CursorContext.js +8 -0
- package/build/components/CursorContext.js.map +1 -0
- package/build/components/ErrorBoundary.d.ts +18 -0
- package/build/components/ErrorBoundary.d.ts.map +1 -0
- package/build/components/ErrorBoundary.js +23 -0
- package/build/components/ErrorBoundary.js.map +1 -0
- package/build/components/ErrorOverview.d.ts.map +1 -0
- package/build/components/ErrorOverview.js +6 -6
- package/build/components/ErrorOverview.js.map +1 -1
- package/build/components/FocusContext.d.ts.map +1 -0
- package/build/components/Newline.d.ts.map +1 -0
- package/build/components/Spacer.d.ts.map +1 -0
- package/build/components/Static.d.ts.map +1 -0
- package/build/components/Static.js.map +1 -1
- package/build/components/StderrContext.d.ts.map +1 -0
- package/build/components/StdinContext.d.ts +7 -1
- package/build/components/StdinContext.d.ts.map +1 -0
- package/build/components/StdinContext.js +1 -0
- package/build/components/StdinContext.js.map +1 -1
- package/build/components/StdoutContext.d.ts.map +1 -0
- package/build/components/Text.d.ts +1 -1
- package/build/components/Text.d.ts.map +1 -0
- package/build/components/Text.js +1 -1
- package/build/components/Text.js.map +1 -1
- package/build/components/Transform.d.ts +1 -1
- package/build/components/Transform.d.ts.map +1 -0
- package/build/cursor-helpers.d.ts +38 -0
- package/build/cursor-helpers.d.ts.map +1 -0
- package/build/cursor-helpers.js +56 -0
- package/build/cursor-helpers.js.map +1 -0
- package/build/devtools-window-polyfill.d.ts.map +1 -0
- package/build/devtools-window-polyfill.js +7 -4
- package/build/devtools-window-polyfill.js.map +1 -1
- package/build/devtools.d.ts.map +1 -0
- package/build/devtools.js +31 -6
- package/build/devtools.js.map +1 -1
- package/build/diagnostics.d.ts +5 -0
- package/build/diagnostics.d.ts.map +1 -0
- package/build/diagnostics.js +7 -0
- package/build/diagnostics.js.map +1 -0
- package/build/dom.d.ts +5 -1
- package/build/dom.d.ts.map +1 -0
- package/build/dom.js +20 -1
- package/build/dom.js.map +1 -1
- package/build/get-max-width.d.ts.map +1 -0
- package/build/hooks/use-animation.d.ts +49 -0
- package/build/hooks/use-animation.d.ts.map +1 -0
- package/build/hooks/use-animation.js +87 -0
- package/build/hooks/use-animation.js.map +1 -0
- package/build/hooks/use-app.d.ts +5 -2
- package/build/hooks/use-app.d.ts.map +1 -0
- package/build/hooks/use-app.js +1 -1
- package/build/hooks/use-box-metrics.d.ts +59 -0
- package/build/hooks/use-box-metrics.d.ts.map +1 -0
- package/build/hooks/use-box-metrics.js +88 -0
- package/build/hooks/use-box-metrics.js.map +1 -0
- package/build/hooks/use-cursor.d.ts +12 -0
- package/build/hooks/use-cursor.d.ts.map +1 -0
- package/build/hooks/use-cursor.js +29 -0
- package/build/hooks/use-cursor.js.map +1 -0
- package/build/hooks/use-focus-manager.d.ts +17 -2
- package/build/hooks/use-focus-manager.d.ts.map +1 -0
- package/build/hooks/use-focus-manager.js +2 -1
- package/build/hooks/use-focus-manager.js.map +1 -1
- package/build/hooks/use-focus.d.ts +2 -1
- package/build/hooks/use-focus.d.ts.map +1 -0
- package/build/hooks/use-focus.js +5 -4
- package/build/hooks/use-focus.js.map +1 -1
- package/build/hooks/use-input.d.ts +40 -1
- package/build/hooks/use-input.d.ts.map +1 -0
- package/build/hooks/use-input.js +65 -25
- package/build/hooks/use-input.js.map +1 -1
- package/build/hooks/use-is-screen-reader-enabled.d.ts +2 -1
- package/build/hooks/use-is-screen-reader-enabled.d.ts.map +1 -0
- package/build/hooks/use-is-screen-reader-enabled.js +2 -1
- package/build/hooks/use-is-screen-reader-enabled.js.map +1 -1
- package/build/hooks/use-paste.d.ts +35 -0
- package/build/hooks/use-paste.d.ts.map +1 -0
- package/build/hooks/use-paste.js +66 -0
- package/build/hooks/use-paste.js.map +1 -0
- package/build/hooks/use-stderr.d.ts +1 -1
- package/build/hooks/use-stderr.d.ts.map +1 -0
- package/build/hooks/use-stderr.js +1 -1
- package/build/hooks/use-stdin.d.ts +4 -2
- package/build/hooks/use-stdin.d.ts.map +1 -0
- package/build/hooks/use-stdin.js +2 -1
- package/build/hooks/use-stdin.js.map +1 -1
- package/build/hooks/use-stdout.d.ts +1 -1
- package/build/hooks/use-stdout.d.ts.map +1 -0
- package/build/hooks/use-stdout.js +1 -1
- package/build/hooks/use-window-size.d.ts +18 -0
- package/build/hooks/use-window-size.d.ts.map +1 -0
- package/build/hooks/use-window-size.js +22 -0
- package/build/hooks/use-window-size.js.map +1 -0
- package/build/index.d.ts +16 -1
- package/build/index.d.ts.map +1 -0
- package/build/index.js +8 -0
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +94 -5
- package/build/ink.d.ts.map +1 -0
- package/build/ink.js +586 -81
- package/build/ink.js.map +1 -1
- package/build/input-parser.d.ts +10 -0
- package/build/input-parser.d.ts.map +1 -0
- package/build/input-parser.js +194 -0
- package/build/input-parser.js.map +1 -0
- package/build/instances.d.ts.map +1 -0
- package/build/kitty-keyboard.d.ts +23 -0
- package/build/kitty-keyboard.d.ts.map +1 -0
- package/build/kitty-keyboard.js +32 -0
- package/build/kitty-keyboard.js.map +1 -0
- package/build/log-update.d.ts +7 -1
- package/build/log-update.d.ts.map +1 -0
- package/build/log-update.js +181 -56
- package/build/log-update.js.map +1 -1
- package/build/measure-element.d.ts +15 -3
- package/build/measure-element.d.ts.map +1 -0
- package/build/measure-element.js +31 -5
- package/build/measure-element.js.map +1 -1
- package/build/measure-text.d.ts +2 -0
- package/build/measure-text.d.ts.map +1 -0
- package/build/measure-text.js +13 -11
- package/build/measure-text.js.map +1 -1
- package/build/output.d.ts +2 -1
- package/build/output.d.ts.map +1 -0
- package/build/output.js +62 -58
- package/build/output.js.map +1 -1
- package/build/parse-keypress.d.ts +9 -3
- package/build/parse-keypress.d.ts.map +1 -0
- package/build/parse-keypress.js +283 -13
- package/build/parse-keypress.js.map +1 -1
- package/build/reconciler.d.ts.map +1 -0
- package/build/reconciler.js +57 -37
- package/build/reconciler.js.map +1 -1
- package/build/render-background.d.ts.map +1 -0
- package/build/render-background.js +2 -0
- package/build/render-background.js.map +1 -1
- package/build/render-border.d.ts +1 -1
- package/build/render-border.d.ts.map +1 -0
- package/build/render-border.js +35 -24
- package/build/render-border.js.map +1 -1
- package/build/render-node-to-output.d.ts +1 -1
- package/build/render-node-to-output.d.ts.map +1 -0
- package/build/render-node-to-output.js +35 -18
- package/build/render-node-to-output.js.map +1 -1
- package/build/render-to-string.d.ts +38 -0
- package/build/render-to-string.d.ts.map +1 -0
- package/build/render-to-string.js +116 -0
- package/build/render-to-string.js.map +1 -0
- package/build/render.d.ts +91 -3
- package/build/render.d.ts.map +1 -0
- package/build/render.js +17 -5
- package/build/render.js.map +1 -1
- package/build/renderer.d.ts.map +1 -0
- package/build/sanitize-ansi.d.ts +2 -0
- package/build/sanitize-ansi.d.ts.map +1 -0
- package/build/sanitize-ansi.js +27 -0
- package/build/sanitize-ansi.js.map +1 -0
- package/build/squash-text-nodes.d.ts.map +1 -0
- package/build/squash-text-nodes.js +18 -1
- package/build/squash-text-nodes.js.map +1 -1
- package/build/styles.d.ts +75 -37
- package/build/styles.d.ts.map +1 -0
- package/build/styles.js +87 -44
- package/build/styles.js.map +1 -1
- package/build/utils.d.ts +9 -2
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +18 -3
- package/build/utils.js.map +1 -1
- package/build/wrap-text.d.ts +2 -0
- package/build/wrap-text.d.ts.map +1 -0
- package/build/wrap-text.js +21 -18
- package/build/wrap-text.js.map +1 -1
- package/build/write-synchronized.d.ts +4 -0
- package/build/write-synchronized.d.ts.map +1 -0
- package/build/write-synchronized.js +9 -0
- package/build/write-synchronized.js.map +1 -0
- package/package.json +46 -106
- package/readme.md +850 -64
- package/build/components/FixedLayout.d.ts +0 -12
- package/build/components/FixedLayout.js +0 -19
- package/build/components/FixedLayout.js.map +0 -1
- package/build/components/VirtualizedList.d.ts +0 -21
- package/build/components/VirtualizedList.js +0 -55
- package/build/components/VirtualizedList.js.map +0 -1
- package/build/hooks/use-mouse.d.ts +0 -15
- package/build/hooks/use-mouse.js +0 -121
- package/build/hooks/use-mouse.js.map +0 -1
- package/build/hooks/use-virtualization.d.ts +0 -19
- package/build/hooks/use-virtualization.js +0 -56
- package/build/hooks/use-virtualization.js.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useContext, useRef, useCallback, useInsertionEffect } from 'react';
|
|
2
|
+
import CursorContext from '../components/CursorContext.js';
|
|
3
|
+
/**
|
|
4
|
+
A React hook that returns methods to control the terminal cursor position.
|
|
5
|
+
|
|
6
|
+
Setting a cursor position makes the cursor visible at the specified coordinates (relative to the Ink output origin). This is useful for IME (Input Method Editor) support, where the composing character is displayed at the cursor location.
|
|
7
|
+
|
|
8
|
+
Pass `undefined` to hide the cursor.
|
|
9
|
+
*/
|
|
10
|
+
const useCursor = () => {
|
|
11
|
+
const context = useContext(CursorContext);
|
|
12
|
+
const positionRef = useRef(undefined);
|
|
13
|
+
const setCursorPosition = useCallback((position) => {
|
|
14
|
+
positionRef.current = position;
|
|
15
|
+
}, []);
|
|
16
|
+
// Propagate cursor position to log-update only during commit phase.
|
|
17
|
+
// useInsertionEffect runs before resetAfterCommit (which triggers onRender),
|
|
18
|
+
// and does NOT run for abandoned concurrent renders (e.g. suspended components).
|
|
19
|
+
// This prevents cursor state from leaking across render boundaries.
|
|
20
|
+
useInsertionEffect(() => {
|
|
21
|
+
context.setCursorPosition(positionRef.current);
|
|
22
|
+
return () => {
|
|
23
|
+
context.setCursorPosition(undefined);
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return { setCursorPosition };
|
|
27
|
+
};
|
|
28
|
+
export default useCursor;
|
|
29
|
+
//# sourceMappingURL=use-cursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-cursor.js","sourceRoot":"","sources":["../../src/hooks/use-cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAC,MAAM,OAAO,CAAC;AAC1E,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAG3D;;;;;;EAME;AACF,MAAM,SAAS,GAAG,GAAG,EAAE;IACtB,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,MAAM,CAA6B,SAAS,CAAC,CAAC;IAElE,MAAM,iBAAiB,GAAG,WAAW,CACpC,CAAC,QAAoC,EAAE,EAAE;QACxC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IAChC,CAAC,EACD,EAAE,CACF,CAAC;IAEF,oEAAoE;IACpE,6EAA6E;IAC7E,iFAAiF;IACjF,oEAAoE;IACpE,kBAAkB,CAAC,GAAG,EAAE;QACvB,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC/C,OAAO,GAAG,EAAE;YACX,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAC,iBAAiB,EAAC,CAAC;AAC5B,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -17,12 +17,27 @@ type Output = {
|
|
|
17
17
|
*/
|
|
18
18
|
focusPrevious: Props['focusPrevious'];
|
|
19
19
|
/**
|
|
20
|
-
Switch focus to the element with provided `id`. If there's no element with that `id`, focus
|
|
20
|
+
Switch focus to the element with provided `id`. If there's no element with that `id`, focus is not changed.
|
|
21
21
|
*/
|
|
22
22
|
focus: Props['focus'];
|
|
23
|
+
/**
|
|
24
|
+
The ID of the currently focused component, or `undefined` if no component is focused.
|
|
25
|
+
|
|
26
|
+
@example
|
|
27
|
+
```tsx
|
|
28
|
+
import {Text, useFocusManager} from 'ink';
|
|
29
|
+
|
|
30
|
+
const Example = () => {
|
|
31
|
+
const {activeId} = useFocusManager();
|
|
32
|
+
|
|
33
|
+
return <Text>Focused: {activeId ?? 'none'}</Text>;
|
|
34
|
+
};
|
|
35
|
+
```
|
|
36
|
+
*/
|
|
37
|
+
activeId: Props['activeId'];
|
|
23
38
|
};
|
|
24
39
|
/**
|
|
25
|
-
|
|
40
|
+
A React hook that returns methods to enable or disable focus management for all components or manually switch focus to the next or previous components.
|
|
26
41
|
*/
|
|
27
42
|
declare const useFocusManager: () => Output;
|
|
28
43
|
export default useFocusManager;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-focus-manager.d.ts","sourceRoot":"","sources":["../../src/hooks/use-focus-manager.ts"],"names":[],"mappings":"AACA,OAAqB,EAAC,KAAK,KAAK,EAAC,MAAM,+BAA+B,CAAC;AAEvE,KAAK,MAAM,GAAG;IACb;;MAEE;IACF,WAAW,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAElC;;MAEE;IACF,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAEpC;;MAEE;IACF,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAE9B;;MAEE;IACF,aAAa,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IAEtC;;MAEE;IACF,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAEtB;;;;;;;;;;;;;MAaE;IACF,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CAC5B,CAAC;AAEF;;EAEE;AACF,QAAA,MAAM,eAAe,QAAO,MAW3B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import FocusContext from '../components/FocusContext.js';
|
|
3
3
|
/**
|
|
4
|
-
|
|
4
|
+
A React hook that returns methods to enable or disable focus management for all components or manually switch focus to the next or previous components.
|
|
5
5
|
*/
|
|
6
6
|
const useFocusManager = () => {
|
|
7
7
|
const focusContext = useContext(FocusContext);
|
|
@@ -11,6 +11,7 @@ const useFocusManager = () => {
|
|
|
11
11
|
focusNext: focusContext.focusNext,
|
|
12
12
|
focusPrevious: focusContext.focusPrevious,
|
|
13
13
|
focus: focusContext.focus,
|
|
14
|
+
activeId: focusContext.activeId,
|
|
14
15
|
};
|
|
15
16
|
};
|
|
16
17
|
export default useFocusManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-focus-manager.js","sourceRoot":"","sources":["../../src/hooks/use-focus-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,YAA0B,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"use-focus-manager.js","sourceRoot":"","sources":["../../src/hooks/use-focus-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,YAA0B,MAAM,+BAA+B,CAAC;AA6CvE;;EAEE;AACF,MAAM,eAAe,GAAG,GAAW,EAAE;IACpC,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAE9C,OAAO;QACN,WAAW,EAAE,YAAY,CAAC,WAAW;QACrC,YAAY,EAAE,YAAY,CAAC,YAAY;QACvC,SAAS,EAAE,YAAY,CAAC,SAAS;QACjC,aAAa,EAAE,YAAY,CAAC,aAAa;QACzC,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,QAAQ,EAAE,YAAY,CAAC,QAAQ;KAC/B,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -23,7 +23,8 @@ type Output = {
|
|
|
23
23
|
focus: (id: string) => void;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
A
|
|
26
|
+
A React hook that returns focus state and focus controls for the current component.
|
|
27
|
+
A component that uses the `useFocus` hook becomes "focusable" to Ink, so when the user presses <kbd>Tab</kbd>, Ink will switch focus to this component. If there are multiple components that execute the `useFocus` hook, focus will be given to them in the order in which these components are rendered.
|
|
27
28
|
*/
|
|
28
29
|
declare const useFocus: ({ isActive, autoFocus, id: customId, }?: Input) => Output;
|
|
29
30
|
export default useFocus;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-focus.d.ts","sourceRoot":"","sources":["../../src/hooks/use-focus.ts"],"names":[],"mappings":"AAIA,KAAK,KAAK,GAAG;IACZ;;MAEE;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;MAEE;IACF,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;MAEE;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,KAAK,MAAM,GAAG;IACb;;MAEE;IACF,SAAS,EAAE,OAAO,CAAC;IAEnB;;MAEE;IACF,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5B,CAAC;AAEF;;;EAGE;AACF,QAAA,MAAM,QAAQ,GAAI,yCAIf,KAAU,KAAG,MAyCf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/build/hooks/use-focus.js
CHANGED
|
@@ -2,7 +2,8 @@ import { useEffect, useContext, useMemo } from 'react';
|
|
|
2
2
|
import FocusContext from '../components/FocusContext.js';
|
|
3
3
|
import useStdin from './use-stdin.js';
|
|
4
4
|
/**
|
|
5
|
-
A
|
|
5
|
+
A React hook that returns focus state and focus controls for the current component.
|
|
6
|
+
A component that uses the `useFocus` hook becomes "focusable" to Ink, so when the user presses <kbd>Tab</kbd>, Ink will switch focus to this component. If there are multiple components that execute the `useFocus` hook, focus will be given to them in the order in which these components are rendered.
|
|
6
7
|
*/
|
|
7
8
|
const useFocus = ({ isActive = true, autoFocus = false, id: customId, } = {}) => {
|
|
8
9
|
const { isRawModeSupported, setRawMode } = useStdin();
|
|
@@ -15,7 +16,7 @@ const useFocus = ({ isActive = true, autoFocus = false, id: customId, } = {}) =>
|
|
|
15
16
|
return () => {
|
|
16
17
|
remove(id);
|
|
17
18
|
};
|
|
18
|
-
}, [id, autoFocus]);
|
|
19
|
+
}, [id, autoFocus, add, remove]);
|
|
19
20
|
useEffect(() => {
|
|
20
21
|
if (isActive) {
|
|
21
22
|
activate(id);
|
|
@@ -23,7 +24,7 @@ const useFocus = ({ isActive = true, autoFocus = false, id: customId, } = {}) =>
|
|
|
23
24
|
else {
|
|
24
25
|
deactivate(id);
|
|
25
26
|
}
|
|
26
|
-
}, [isActive, id]);
|
|
27
|
+
}, [isActive, id, activate, deactivate]);
|
|
27
28
|
useEffect(() => {
|
|
28
29
|
if (!isRawModeSupported || !isActive) {
|
|
29
30
|
return;
|
|
@@ -32,7 +33,7 @@ const useFocus = ({ isActive = true, autoFocus = false, id: customId, } = {}) =>
|
|
|
32
33
|
return () => {
|
|
33
34
|
setRawMode(false);
|
|
34
35
|
};
|
|
35
|
-
}, [isActive]);
|
|
36
|
+
}, [isActive, isRawModeSupported, setRawMode]);
|
|
36
37
|
return {
|
|
37
38
|
isFocused: Boolean(id) && activeId === id,
|
|
38
39
|
focus,
|
|
@@ -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
|
|
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;;;EAGE;AACF,MAAM,QAAQ,GAAG,CAAC,EACjB,QAAQ,GAAG,IAAI,EACf,SAAS,GAAG,KAAK,EACjB,EAAE,EAAE,QAAQ,MACF,EAAE,EAAU,EAAE;IACxB,MAAM,EAAC,kBAAkB,EAAE,UAAU,EAAC,GAAG,QAAQ,EAAE,CAAC;IACpD,MAAM,EAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAC,GACzD,UAAU,CAAC,YAAY,CAAC,CAAC;IAE1B,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;QACvB,OAAO,QAAQ,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,SAAS,CAAC,GAAG,EAAE;QACd,GAAG,CAAC,EAAE,EAAE,EAAC,SAAS,EAAC,CAAC,CAAC;QAErB,OAAO,GAAG,EAAE;YACX,MAAM,CAAC,EAAE,CAAC,CAAC;QACZ,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;IAEjC,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,QAAQ,EAAE,CAAC;YACd,QAAQ,CAAC,EAAE,CAAC,CAAC;QACd,CAAC;aAAM,CAAC;YACP,UAAU,CAAC,EAAE,CAAC,CAAC;QAChB,CAAC;IACF,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;IAEzC,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,EAAE,kBAAkB,EAAE,UAAU,CAAC,CAAC,CAAC;IAE/C,OAAO;QACN,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,QAAQ,KAAK,EAAE;QACzC,KAAK;KACL,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -27,6 +27,14 @@ export type Key = {
|
|
|
27
27
|
*/
|
|
28
28
|
pageUp: boolean;
|
|
29
29
|
/**
|
|
30
|
+
Home key was pressed.
|
|
31
|
+
*/
|
|
32
|
+
home: boolean;
|
|
33
|
+
/**
|
|
34
|
+
End key was pressed.
|
|
35
|
+
*/
|
|
36
|
+
end: boolean;
|
|
37
|
+
/**
|
|
30
38
|
Return (Enter) key was pressed.
|
|
31
39
|
*/
|
|
32
40
|
return: boolean;
|
|
@@ -58,6 +66,36 @@ export type Key = {
|
|
|
58
66
|
[Meta key](https://en.wikipedia.org/wiki/Meta_key) was pressed.
|
|
59
67
|
*/
|
|
60
68
|
meta: boolean;
|
|
69
|
+
/**
|
|
70
|
+
Super key (Cmd on Mac, Win on Windows) was pressed.
|
|
71
|
+
|
|
72
|
+
Only available with kitty keyboard protocol.
|
|
73
|
+
*/
|
|
74
|
+
super: boolean;
|
|
75
|
+
/**
|
|
76
|
+
Hyper key was pressed.
|
|
77
|
+
|
|
78
|
+
Only available with kitty keyboard protocol.
|
|
79
|
+
*/
|
|
80
|
+
hyper: boolean;
|
|
81
|
+
/**
|
|
82
|
+
Caps Lock is active.
|
|
83
|
+
|
|
84
|
+
Only available with kitty keyboard protocol.
|
|
85
|
+
*/
|
|
86
|
+
capsLock: boolean;
|
|
87
|
+
/**
|
|
88
|
+
Num Lock is active.
|
|
89
|
+
|
|
90
|
+
Only available with kitty keyboard protocol.
|
|
91
|
+
*/
|
|
92
|
+
numLock: boolean;
|
|
93
|
+
/**
|
|
94
|
+
Event type for key events.
|
|
95
|
+
|
|
96
|
+
Only available with kitty keyboard protocol.
|
|
97
|
+
*/
|
|
98
|
+
eventType?: 'press' | 'repeat' | 'release';
|
|
61
99
|
};
|
|
62
100
|
type Handler = (input: string, key: Key) => void;
|
|
63
101
|
type Options = {
|
|
@@ -69,7 +107,8 @@ type Options = {
|
|
|
69
107
|
isActive?: boolean;
|
|
70
108
|
};
|
|
71
109
|
/**
|
|
72
|
-
|
|
110
|
+
A React hook that returns `void` and handles user input.
|
|
111
|
+
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`.
|
|
73
112
|
|
|
74
113
|
```
|
|
75
114
|
import {useInput} from 'ink';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-input.d.ts","sourceRoot":"","sources":["../../src/hooks/use-input.ts"],"names":[],"mappings":"AAKA;;EAEE;AACF,MAAM,MAAM,GAAG,GAAG;IACjB;;MAEE;IACF,OAAO,EAAE,OAAO,CAAC;IAEjB;;MAEE;IACF,SAAS,EAAE,OAA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9 +1,10 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useRef } 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,14 @@ 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();
|
|
30
|
+
// Use a ref to always have the latest handler without re-subscribing
|
|
31
|
+
// to the event emitter. This avoids useEffectEvent which has a stale
|
|
32
|
+
// closure bug in ink's custom React reconciler when used with forwardRef.
|
|
33
|
+
const handlerRef = useRef(inputHandler);
|
|
34
|
+
handlerRef.current = inputHandler;
|
|
35
|
+
const exitOnCtrlCRef = useRef(internal_exitOnCtrlC);
|
|
36
|
+
exitOnCtrlCRef.current = internal_exitOnCtrlC;
|
|
29
37
|
useEffect(() => {
|
|
30
38
|
if (options.isActive === false) {
|
|
31
39
|
return;
|
|
@@ -48,6 +56,8 @@ const useInput = (inputHandler, options = {}) => {
|
|
|
48
56
|
rightArrow: keypress.name === 'right',
|
|
49
57
|
pageDown: keypress.name === 'pagedown',
|
|
50
58
|
pageUp: keypress.name === 'pageup',
|
|
59
|
+
home: keypress.name === 'home',
|
|
60
|
+
end: keypress.name === 'end',
|
|
51
61
|
return: keypress.name === 'return',
|
|
52
62
|
escape: keypress.name === 'escape',
|
|
53
63
|
ctrl: keypress.ctrl,
|
|
@@ -55,39 +65,69 @@ const useInput = (inputHandler, options = {}) => {
|
|
|
55
65
|
tab: keypress.name === 'tab',
|
|
56
66
|
backspace: keypress.name === 'backspace',
|
|
57
67
|
delete: keypress.name === 'delete',
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
meta: keypress.meta,
|
|
69
|
+
// Kitty keyboard protocol modifiers
|
|
70
|
+
super: keypress.super ?? false,
|
|
71
|
+
hyper: keypress.hyper ?? false,
|
|
72
|
+
capsLock: keypress.capsLock ?? false,
|
|
73
|
+
numLock: keypress.numLock ?? false,
|
|
74
|
+
eventType: keypress.eventType,
|
|
63
75
|
};
|
|
64
|
-
let input
|
|
65
|
-
if (
|
|
76
|
+
let input;
|
|
77
|
+
if (keypress.isKittyProtocol) {
|
|
78
|
+
// Use text-as-codepoints field for printable keys (needed when
|
|
79
|
+
// reportAllKeysAsEscapeCodes flag is enabled), suppress non-printable
|
|
80
|
+
if (keypress.isPrintable) {
|
|
81
|
+
input = keypress.text ?? keypress.name;
|
|
82
|
+
}
|
|
83
|
+
else if (keypress.ctrl && keypress.name.length === 1) {
|
|
84
|
+
// Ctrl+letter via codepoint 1-26 form: not printable text, but
|
|
85
|
+
// the letter name must flow through so handlers (e.g. exitOnCtrlC
|
|
86
|
+
// checking `input === 'c' && key.ctrl`) still work.
|
|
87
|
+
input = keypress.name;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
input = '';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (keypress.ctrl) {
|
|
94
|
+
// Keypress.name is guaranteed non-undefined by parseKeypress,
|
|
95
|
+
// but guard defensively since a TypeError here would crash the
|
|
96
|
+
// entire Ink app (see https://github.com/vadimdemedes/ink/issues/901).
|
|
97
|
+
input = keypress.name ?? '';
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
input = keypress.sequence;
|
|
101
|
+
}
|
|
102
|
+
if (!keypress.isKittyProtocol &&
|
|
103
|
+
nonAlphanumericKeys.includes(keypress.name)) {
|
|
66
104
|
input = '';
|
|
67
105
|
}
|
|
68
|
-
// Strip
|
|
69
|
-
//
|
|
106
|
+
// Strip escape prefix from broken/incomplete sequences that
|
|
107
|
+
// parseKeypress did not fully resolve (e.g. a flushed "\u001B[").
|
|
70
108
|
if (input.startsWith('\u001B')) {
|
|
71
109
|
input = input.slice(1);
|
|
72
110
|
}
|
|
73
|
-
if (input.length === 1 &&
|
|
74
|
-
typeof input[0] === 'string' &&
|
|
75
|
-
/[A-Z]/.test(input[0])) {
|
|
111
|
+
if (input.length === 1 && /[A-Z]/.test(input)) {
|
|
76
112
|
key.shift = true;
|
|
77
113
|
}
|
|
78
|
-
// If app is
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
reconciler.batchedUpdates(() => {
|
|
82
|
-
inputHandler(input, key);
|
|
83
|
-
});
|
|
114
|
+
// If app is supposed to exit on Ctrl+C, skip input listeners.
|
|
115
|
+
if (input === 'c' && key.ctrl && exitOnCtrlCRef.current) {
|
|
116
|
+
return;
|
|
84
117
|
}
|
|
118
|
+
// Use discreteUpdates to assign DiscreteEventPriority to state
|
|
119
|
+
// updates from keyboard input, ensuring they are processed at the
|
|
120
|
+
// highest priority in concurrent mode.
|
|
121
|
+
// @ts-expect-error Types require 5 arguments (fn, a, b, c, d) but only fn is needed at runtime.
|
|
122
|
+
reconciler.discreteUpdates(() => {
|
|
123
|
+
handlerRef.current(input, key);
|
|
124
|
+
});
|
|
85
125
|
};
|
|
86
|
-
internal_eventEmitter
|
|
126
|
+
internal_eventEmitter.on('input', handleData);
|
|
87
127
|
return () => {
|
|
88
|
-
internal_eventEmitter
|
|
128
|
+
internal_eventEmitter.removeListener('input', handleData);
|
|
89
129
|
};
|
|
90
|
-
}, [options.isActive,
|
|
130
|
+
}, [options.isActive, internal_eventEmitter]);
|
|
91
131
|
};
|
|
92
132
|
export default useInput;
|
|
93
133
|
//# 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,MAAM,EAAC,MAAM,OAAO,CAAC;AACxC,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,qEAAqE;IACrE,qEAAqE;IACrE,0EAA0E;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IACxC,UAAU,CAAC,OAAO,GAAG,YAAY,CAAC;IAElC,MAAM,cAAc,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACpD,cAAc,CAAC,OAAO,GAAG,oBAAoB,CAAC;IAE9C,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,EA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gBAC/C,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,CAAC;YAED,8DAA8D;YAC9D,IAAI,KAAK,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;gBACzD,OAAO;YACR,CAAC;YAED,+DAA+D;YAC/D,kEAAkE;YAClE,uCAAuC;YACvC,gGAAgG;YAChG,UAAU,CAAC,eAAe,CAAC,GAAG,EAAE;gBAC/B,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC;QAEF,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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-is-screen-reader-enabled.d.ts","sourceRoot":"","sources":["../../src/hooks/use-is-screen-reader-enabled.ts"],"names":[],"mappings":"AAGA;;;EAGE;AACF,QAAA,MAAM,wBAAwB,QAAO,OAGpC,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"use-paste.d.ts","sourceRoot":"","sources":["../../src/hooks/use-paste.ts"],"names":[],"mappings":"AAIA,KAAK,OAAO,GAAG;IACd;;;;MAIE;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;EAwBE;AACF,QAAA,MAAM,QAAQ,GACb,SAAS,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC/B,UAAS,OAAY,KACnB,IA4CF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useEffect, useRef } 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
|
+
// Use a ref to always have the latest handler. useEffectEvent has a stale
|
|
44
|
+
// closure bug in ink's custom React reconciler when used with forwardRef.
|
|
45
|
+
const handlerRef = useRef(handler);
|
|
46
|
+
handlerRef.current = handler;
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (options.isActive === false) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const handlePaste = (text) => {
|
|
52
|
+
// Use discreteUpdates to assign DiscreteEventPriority to state
|
|
53
|
+
// updates triggered by paste, matching the priority of useInput.
|
|
54
|
+
// @ts-expect-error Types require 5 arguments (fn, a, b, c, d) but only fn is needed at runtime.
|
|
55
|
+
reconciler.discreteUpdates(() => {
|
|
56
|
+
handlerRef.current(text);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
internal_eventEmitter.on('paste', handlePaste);
|
|
60
|
+
return () => {
|
|
61
|
+
internal_eventEmitter.removeListener('paste', handlePaste);
|
|
62
|
+
};
|
|
63
|
+
}, [options.isActive, internal_eventEmitter]);
|
|
64
|
+
};
|
|
65
|
+
export default usePaste;
|
|
66
|
+
//# 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,MAAM,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAW/C;;;;;;;;;;;;;;;;;;;;;;;;EAwBE;AACF,MAAM,QAAQ,GAAG,CAChB,OAA+B,EAC/B,UAAmB,EAAE,EACd,EAAE;IACT,gEAAgE;IAChE,MAAM,EAAC,UAAU,EAAE,qBAAqB,EAAE,qBAAqB,EAAC,GAC/D,eAAe,EAAE,CAAC;IAEnB,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YAChC,OAAO;QACR,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAE5B,OAAO,GAAG,EAAE;YACX,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAE1D,0EAA0E;IAC1E,0EAA0E;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YAChC,OAAO;QACR,CAAC;QAED,MAAM,WAAW,GAAG,CAAC,IAAY,EAAQ,EAAE;YAC1C,+DAA+D;YAC/D,iEAAiE;YACjE,gGAAgG;YAChG,UAAU,CAAC,eAAe,CAAC,GAAG,EAAE;gBAC/B,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC;QAEF,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAE/C,OAAO,GAAG,EAAE;YACX,qBAAqB,CAAC,cAAc,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC5D,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-stderr.d.ts","sourceRoot":"","sources":["../../src/hooks/use-stderr.ts"],"names":[],"mappings":"AAGA;;EAEE;AACF,QAAA,MAAM,SAAS,sDAAkC,CAAC;AAClD,eAAe,SAAS,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-stdin.d.ts","sourceRoot":"","sources":["../../src/hooks/use-stdin.ts"],"names":[],"mappings":"AACA,OAAqB,EACpB,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,MAAM,+BAA+B,CAAC;AAEvC;;EAEE;AACF,QAAA,MAAM,QAAQ,QAAO,WAAuC,CAAC;AAE7D,eAAO,MAAM,eAAe,QAAO,KAAiC,CAAC;AAErE,eAAe,QAAQ,CAAC"}
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-stdout.d.ts","sourceRoot":"","sources":["../../src/hooks/use-stdout.ts"],"names":[],"mappings":"AAGA;;EAEE;AACF,QAAA,MAAM,SAAS,sDAAkC,CAAC;AAClD,eAAe,SAAS,CAAC"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"use-window-size.d.ts","sourceRoot":"","sources":["../../src/hooks/use-window-size.ts"],"names":[],"mappings":"AAIA;;EAEE;AACF,MAAM,MAAM,UAAU,GAAG;IACxB;;MAEE;IACF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;MAEE;IACF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;EAEE;AACF,QAAA,MAAM,aAAa,QAAO,UAiBzB,CAAC;AAEF,eAAe,aAAa,CAAC"}
|