@visulima/tui 2.0.0 → 2.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/CHANGELOG.md +2 -0
- package/dist/components/box.d.ts +25 -25
- package/dist/components/canvas.d.ts +26 -31
- package/dist/components/cursor.d.ts +39 -44
- package/dist/components/error-overview.d.ts +1 -3
- package/dist/components/error-overview.js +1 -1
- package/dist/components/newline.d.ts +6 -8
- package/dist/components/spacer.d.ts +4 -4
- package/dist/components/static-render.d.ts +9 -40
- package/dist/components/static.d.ts +13 -13
- package/dist/components/text.d.ts +34 -47
- package/dist/components/transform.d.ts +7 -11
- package/dist/core/index.d.ts +11 -11
- package/dist/core/index.js +1 -1
- package/dist/ink/canvas/index.d.ts +10 -10
- package/dist/ink/hooks/use-animation.d.ts +22 -22
- package/dist/ink/hooks/use-app.d.ts +3 -3
- package/dist/ink/hooks/use-box-metrics.d.ts +16 -16
- package/dist/ink/hooks/use-clipboard.d.ts +16 -16
- package/dist/ink/hooks/use-color-blindness.d.ts +16 -16
- package/dist/ink/hooks/use-console-capture.d.ts +19 -19
- package/dist/ink/hooks/use-cursor.d.ts +6 -6
- package/dist/ink/hooks/use-focus-manager.d.ts +25 -25
- package/dist/ink/hooks/use-focus.d.ts +14 -18
- package/dist/ink/hooks/use-form.d.ts +32 -32
- package/dist/ink/hooks/use-hotkey.d.ts +17 -17
- package/dist/ink/hooks/use-input.d.ts +92 -92
- package/dist/ink/hooks/use-input.js +2 -2
- package/dist/ink/hooks/use-interval.d.ts +14 -14
- package/dist/ink/hooks/use-is-screen-reader-enabled.d.ts +3 -3
- package/dist/ink/hooks/use-key-bindings.d.ts +32 -32
- package/dist/ink/hooks/use-key-chord.d.ts +15 -15
- package/dist/ink/hooks/use-paste.d.ts +38 -38
- package/dist/ink/hooks/use-paste.js +1 -1
- package/dist/ink/hooks/use-persistent-state.d.ts +46 -46
- package/dist/ink/hooks/use-persistent-state.js +2 -2
- package/dist/ink/hooks/use-scroll-acceleration.d.ts +24 -24
- package/dist/ink/hooks/use-scroll-input.d.ts +15 -15
- package/dist/ink/hooks/use-stderr.d.ts +6 -6
- package/dist/ink/hooks/use-stderr.js +1 -1
- package/dist/ink/hooks/use-stdin.d.ts +10 -10
- package/dist/ink/hooks/use-stdin.js +1 -1
- package/dist/ink/hooks/use-stdout.d.ts +6 -6
- package/dist/ink/hooks/use-stdout.js +1 -1
- package/dist/ink/hooks/use-stopwatch.d.ts +12 -12
- package/dist/ink/hooks/use-terminal-palette.d.ts +11 -11
- package/dist/ink/hooks/use-text-buffer.d.ts +2 -2
- package/dist/ink/hooks/use-text-selection.d.ts +18 -18
- package/dist/ink/hooks/use-timeout.d.ts +11 -11
- package/dist/ink/hooks/use-timer.d.ts +19 -19
- package/dist/ink/hooks/use-window-size.d.ts +8 -8
- package/dist/ink/hooks/use-window-size.js +1 -1
- package/dist/ink/index.d.ts +109 -122
- package/dist/ink/index.js +1 -1
- package/dist/ink/mouse/use-element-position.d.ts +6 -6
- package/dist/ink/mouse/use-mouse-action.d.ts +1 -1
- package/dist/ink/mouse/use-mouse-position.d.ts +1 -1
- package/dist/ink/mouse/use-mouse.d.ts +1 -1
- package/dist/ink/mouse/use-on-mouse-click.d.ts +3 -3
- package/dist/ink/mouse/use-on-mouse-hover.d.ts +2 -2
- package/dist/ink/mouse/use-on-mouse-state.d.ts +2 -2
- package/dist/ink/public/cursor.d.ts +21 -21
- package/dist/ink/public/dom.d.ts +2 -2
- package/dist/ink/public/highlighter.d.ts +16 -26
- package/dist/ink/public/input.d.ts +6 -6
- package/dist/ink/public/styles.d.ts +1 -1
- package/dist/ink/public/utils.d.ts +2 -2
- package/dist/packem_shared/{DevTools-D9tfChBc.js → DevTools-BxD3PYAN.js} +1 -1
- package/dist/packem_shared/MouseProvider-DOcWCRVq.js +1 -0
- package/dist/packem_shared/{Renderer-DsskdkUd.js → Renderer-BeS49FNq.js} +1 -1
- package/dist/packem_shared/{TuiApp-DjIgv5Sk.js → TuiApp-CCVaiKbf.js} +1 -1
- package/dist/packem_shared/app-context.d-DMLw5Nxy.d.ts +56 -0
- package/dist/packem_shared/{buffer.d-j_dP5JyC.d.ts → buffer.d-CttIC480.d.ts} +26 -26
- package/dist/packem_shared/clipboard.d-nDPQkZ2H.d.ts +23 -0
- package/dist/packem_shared/color-matrix.d-sTqnJ23h.d.ts +50 -0
- package/dist/packem_shared/{createInlineLoop-BT40Wpmx.js → createInlineLoop-DnEvE2eM.js} +1 -1
- package/dist/packem_shared/{dom.d-g-nsYquD.d.ts → dom.d-CLGlidfI.d.ts} +138 -151
- package/dist/packem_shared/{input.d-D-Yxqha8.d.ts → input.d-Bb8pWHvp.d.ts} +24 -24
- package/dist/packem_shared/load-native-root-binding-CxJnHcac.js +1 -0
- package/dist/packem_shared/{mouse-context.d-BfL9xGk_.d.ts → mouse-context.d-W-nszUps.d.ts} +8 -8
- package/dist/packem_shared/reconciler-DkwOtC5B.js +1 -0
- package/dist/packem_shared/{render-D7aV_hO1.js → render-CuCo-R-l.js} +17 -17
- package/dist/packem_shared/{render-DMcWfI6-.js → render-DtQd8qQq.js} +1 -1
- package/dist/packem_shared/render.d-DjQhFsiN.d.ts +435 -0
- package/dist/packem_shared/{renderToString-DqLFFPvO.js → renderToString-B1LgWcJe.js} +1 -1
- package/dist/packem_shared/{selection.d-KWphH--_.d.ts → selection.d-BSAWa4ey.d.ts} +16 -16
- package/dist/packem_shared/stderr-context-CR2LLec6.js +1 -0
- package/dist/packem_shared/stdin-context-BjMA9Sbi.js +1 -0
- package/dist/packem_shared/stdout-context-DAAlQct2.js +1 -0
- package/dist/packem_shared/styles.d-CKGQFfm4.d.ts +485 -0
- package/dist/packem_shared/{terminal-palette.d-D2SQjfn-.d.ts → terminal-palette.d-JbWHISW-.d.ts} +7 -7
- package/dist/packem_shared/utils-CVgM8kTn.js +1 -0
- package/dist/react/index.d.ts +160 -178
- package/dist/react/index.js +1 -1
- package/dist/testing/index.d.ts +151 -151
- package/dist/testing/index.js +1 -1
- package/index.js +52 -52
- package/package.json +9 -9
- package/dist/packem_shared/MouseProvider-DUqQ3Eaa.js +0 -1
- package/dist/packem_shared/app-context.d-CG88lgkg.d.ts +0 -56
- package/dist/packem_shared/clipboard.d-D6lZTQ21.d.ts +0 -23
- package/dist/packem_shared/color-matrix.d-DSXLsB64.d.ts +0 -50
- package/dist/packem_shared/load-native-root-binding-DDikxNox.js +0 -1
- package/dist/packem_shared/reconciler-DhUGYWCr.js +0 -1
- package/dist/packem_shared/render.d-BvfwvSCx.d.ts +0 -435
- package/dist/packem_shared/stderr-context-Bvnik0hL.js +0 -1
- package/dist/packem_shared/stdin-context-88AhuztD.js +0 -1
- package/dist/packem_shared/stdout-context-BnblEPez.js +0 -1
- package/dist/packem_shared/styles.d-D7iZuNC-.d.ts +0 -492
- package/dist/packem_shared/utils-C8l_3Dzw.js +0 -1
|
@@ -1,149 +1,149 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Handy information about a key that was pressed.
|
|
3
|
-
*/
|
|
2
|
+
* Handy information about a key that was pressed.
|
|
3
|
+
*/
|
|
4
4
|
type Key = {
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
* Backspace key was pressed.
|
|
7
|
+
*/
|
|
8
8
|
backspace: boolean;
|
|
9
9
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
* Caps Lock is active.
|
|
11
|
+
*
|
|
12
|
+
* Only available with kitty keyboard protocol.
|
|
13
|
+
*/
|
|
14
14
|
capsLock: boolean;
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
* Ctrl key was pressed.
|
|
17
|
+
*/
|
|
18
18
|
ctrl: boolean;
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
* Delete key was pressed.
|
|
21
|
+
*/
|
|
22
22
|
delete: boolean;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
* Down arrow key was pressed.
|
|
25
|
+
*/
|
|
26
26
|
downArrow: boolean;
|
|
27
27
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
* End key was pressed.
|
|
29
|
+
*/
|
|
30
30
|
end: boolean;
|
|
31
31
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
* Escape key was pressed.
|
|
33
|
+
*/
|
|
34
34
|
escape: boolean;
|
|
35
35
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
* Event type for key events.
|
|
37
|
+
*
|
|
38
|
+
* Only available with kitty keyboard protocol.
|
|
39
|
+
*/
|
|
40
40
|
eventType?: "press" | "repeat" | "release";
|
|
41
41
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
* Home key was pressed.
|
|
43
|
+
*/
|
|
44
44
|
home: boolean;
|
|
45
45
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
* Hyper key was pressed.
|
|
47
|
+
*
|
|
48
|
+
* Only available with kitty keyboard protocol.
|
|
49
|
+
*/
|
|
50
50
|
hyper: boolean;
|
|
51
51
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
* Left arrow key was pressed.
|
|
53
|
+
*/
|
|
54
54
|
leftArrow: boolean;
|
|
55
55
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
* [Meta key](https://en.wikipedia.org/wiki/Meta_key) was pressed.
|
|
57
|
+
*/
|
|
58
58
|
meta: boolean;
|
|
59
59
|
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
* Num Lock is active.
|
|
61
|
+
*
|
|
62
|
+
* Only available with kitty keyboard protocol.
|
|
63
|
+
*/
|
|
64
64
|
numLock: boolean;
|
|
65
65
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
* Page Down key was pressed.
|
|
67
|
+
*/
|
|
68
68
|
pageDown: boolean;
|
|
69
69
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
* Page Up key was pressed.
|
|
71
|
+
*/
|
|
72
72
|
pageUp: boolean;
|
|
73
73
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
* Return (Enter) key was pressed.
|
|
75
|
+
*/
|
|
76
76
|
return: boolean;
|
|
77
77
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
* Right arrow key was pressed.
|
|
79
|
+
*/
|
|
80
80
|
rightArrow: boolean;
|
|
81
81
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
* Shift key was pressed.
|
|
83
|
+
*/
|
|
84
84
|
shift: boolean;
|
|
85
85
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
* Super key (Cmd on Mac, Win on Windows) was pressed.
|
|
87
|
+
*
|
|
88
|
+
* Only available with kitty keyboard protocol.
|
|
89
|
+
*/
|
|
90
90
|
super: boolean;
|
|
91
91
|
/**
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
* Tab key was pressed.
|
|
93
|
+
*/
|
|
94
94
|
tab: boolean;
|
|
95
95
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
* Up arrow key was pressed.
|
|
97
|
+
*/
|
|
98
98
|
upArrow: boolean;
|
|
99
99
|
};
|
|
100
100
|
type Handler = (input: string, key: Key) => void;
|
|
101
101
|
type Options = {
|
|
102
102
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
* Enable IME (Input Method Editor) composition buffering for Vietnamese, Chinese,
|
|
104
|
+
* Japanese, Korean, and other non-ASCII input methods.
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
107
|
imeEnabled?: boolean;
|
|
108
108
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
* Timeout in milliseconds to wait before flushing IME composition buffer.
|
|
110
|
+
* @default 50
|
|
111
|
+
*/
|
|
112
112
|
imeTimeout?: number;
|
|
113
113
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
* Enable or disable capturing of user input. Useful when there are multiple `useInput` hooks used at once to avoid handling the same input several times.
|
|
115
|
+
* @default true
|
|
116
|
+
*/
|
|
117
117
|
isActive?: boolean;
|
|
118
118
|
};
|
|
119
119
|
/**
|
|
120
|
-
* A React hook that returns `void` and handles user input.
|
|
121
|
-
* It's a more convenient alternative to using `StdinContext` and listening for
|
|
122
|
-
* `data` events. The callback you pass to `useInput` is called for typed
|
|
123
|
-
* characters and key events.
|
|
124
|
-
*
|
|
125
|
-
* Bracketed paste payloads belong to `usePaste`. If no `usePaste` handler is
|
|
126
|
-
* active, Ink still forwards bracketed paste text to `useInput` for backward
|
|
127
|
-
* compatibility, but that fallback is deprecated and will be removed in the next
|
|
128
|
-
* major version.
|
|
129
|
-
*
|
|
130
|
-
* ```
|
|
131
|
-
* import {useInput} from '@visulima/tui/hooks/use-input';
|
|
132
|
-
*
|
|
133
|
-
* const UserInput = () => {
|
|
134
|
-
* useInput((input, key) => {
|
|
135
|
-
* if (input === 'q') {
|
|
136
|
-
* // Exit program
|
|
137
|
-
* }
|
|
138
|
-
*
|
|
139
|
-
* if (key.leftArrow) {
|
|
140
|
-
* // Left arrow key pressed
|
|
141
|
-
* }
|
|
142
|
-
* });
|
|
143
|
-
*
|
|
144
|
-
* return …
|
|
145
|
-
* };
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
120
|
+
* A React hook that returns `void` and handles user input.
|
|
121
|
+
* It's a more convenient alternative to using `StdinContext` and listening for
|
|
122
|
+
* `data` events. The callback you pass to `useInput` is called for typed
|
|
123
|
+
* characters and key events.
|
|
124
|
+
*
|
|
125
|
+
* Bracketed paste payloads belong to `usePaste`. If no `usePaste` handler is
|
|
126
|
+
* active, Ink still forwards bracketed paste text to `useInput` for backward
|
|
127
|
+
* compatibility, but that fallback is deprecated and will be removed in the next
|
|
128
|
+
* major version.
|
|
129
|
+
*
|
|
130
|
+
* ```
|
|
131
|
+
* import {useInput} from '@visulima/tui/hooks/use-input';
|
|
132
|
+
*
|
|
133
|
+
* const UserInput = () => {
|
|
134
|
+
* useInput((input, key) => {
|
|
135
|
+
* if (input === 'q') {
|
|
136
|
+
* // Exit program
|
|
137
|
+
* }
|
|
138
|
+
*
|
|
139
|
+
* if (key.leftArrow) {
|
|
140
|
+
* // Left arrow key pressed
|
|
141
|
+
* }
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* return …
|
|
145
|
+
* };
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
148
|
declare const useInput: (inputHandler: Handler, options?: Options) => void;
|
|
149
149
|
export { Key, useInput as default, useInput };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createRequire as $}from"node:module";import{useRef as P,useEffectEvent as
|
|
2
|
-
`:{t.name="enter";break}case" ":{t.name="tab";break}case" ":case"\x1B ":{t.name="space",t.meta=e.length===2;break}case"\b":case"\x1B\b":{t.name="backspace",t.meta=e.charAt(0)==="\x1B";break}case"\x1B":case"\x1B\x1B":{t.name="escape",t.meta=e.length===2;break}case"\x1B":case"":{t.name="backspace",t.meta=e.charAt(0)==="\x1B";break}default:if(e.length===1&&e<="")t.name=String.fromCharCode(e.charCodeAt(0)+97-1),t.ctrl=!0;else if(e.length===1&&e>="0"&&e<="9")t.name="number";else if(e.length===1&&e>="a"&&e<="z")t.name=e;else if(e.length===1&&e>="A"&&e<="Z")t.name=e.toLowerCase(),t.shift=!0;else if(a=
|
|
1
|
+
import{createRequire as $}from"node:module";import{useRef as P,useEffectEvent as q,useEffect as b,useLayoutEffect as E}from"react";import{IMECompositionBuffer as S,isIMEInput as I}from"../../packem_shared/IMECompositionBuffer-VhC9HRCv.js";import{kittyModifiers as p}from"../../packem_shared/kittyFlags-g8ALyoCU.js";import{j as w}from"../../packem_shared/reconciler-DkwOtC5B.js";import{useStdinContext as N}from"./use-stdin.js";let _;const C=e=>(_??=$(import.meta.url))(e),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,L=e=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,s]=m.versions.node.split(".").map(Number);if(a>22||a===22&&s>=3||a===20&&s>=16)return m.getBuiltinModule(e)}return C(e)},{Buffer:j}=L("node:buffer"),M=/^\u001B([a-z0-9])$/i,R=/^\u001B+([ON[]|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,y={"[1~":"home","[2$":"insert","[2^":"insert","[2~":"insert","[3$":"delete","[3^":"delete","[3~":"delete","[4~":"end","[5$":"pageup","[5^":"pageup","[5~":"pageup","[6$":"pagedown","[6^":"pagedown","[6~":"pagedown","[7$":"home","[7^":"home","[7~":"home","[8$":"end","[8^":"end","[8~":"end","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[[5~":"pageup","[[6~":"pagedown","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[A":"up","[a":"up","[B":"down","[b":"down","[C":"right","[c":"right","[D":"left","[d":"left","[E":"clear","[e":"clear","[F":"end","[H":"home","[P":"f1","[Q":"f2","[R":"f3","[S":"f4","[Z":"tab",OA:"up",Oa:"up",OB:"down",Ob:"down",OC:"right",Oc:"right",OD:"left",Od:"left",OE:"clear",Oe:"clear",OF:"end",OH:"home",OP:"f1",OQ:"f2",OR:"f3",OS:"f4"},T=[...Object.values(y),"backspace"],K=e=>["[2$","[3$","[5$","[6$","[7$","[8$","[a","[b","[c","[d","[e","[Z"].includes(e),Z=e=>["[2^","[3^","[5^","[6^","[7^","[8^","Oa","Ob","Oc","Od","Oe"].includes(e),B=/^\u001B\[(\d+)(?:;(\d+)(?::(\d+))?(?:;([\d:]+))?)?u$/,D=/^\u001B\[(\d+);(\d+):(\d+)([A-Z~])$/i,F={A:"up",B:"down",C:"right",D:"left",E:"clear",F:"end",H:"home",P:"f1",Q:"f2",R:"f3",S:"f4"},U={2:"insert",3:"delete",5:"pageup",6:"pagedown",7:"home",8:"end",11:"f1",12:"f2",13:"f3",14:"f4",15:"f5",17:"f6",18:"f7",19:"f8",20:"f9",21:"f10",23:"f11",24:"f12"},v={8:"backspace",9:"tab",27:"escape",127:"backspace",57358:"capslock",57359:"scrolllock",57360:"numlock",57361:"printscreen",57362:"pause",57363:"menu",57376:"f13",57377:"f14",57378:"f15",57379:"f16",57380:"f17",57381:"f18",57382:"f19",57383:"f20",57384:"f21",57385:"f22",57386:"f23",57387:"f24",57388:"f25",57389:"f26",57390:"f27",57391:"f28",57392:"f29",57393:"f30",57394:"f31",57395:"f32",57396:"f33",57397:"f34",57398:"f35",57399:"kp0",57400:"kp1",57401:"kp2",57402:"kp3",57403:"kp4",57404:"kp5",57405:"kp6",57406:"kp7",57407:"kp8",57408:"kp9",57409:"kpdecimal",57410:"kpdivide",57411:"kpmultiply",57412:"kpsubtract",57413:"kpadd",57414:"kpenter",57415:"kpequal",57416:"kpseparator",57417:"kpleft",57418:"kpright",57419:"kpup",57420:"kpdown",57421:"kppageup",57422:"kppagedown",57423:"kphome",57424:"kpend",57425:"kpinsert",57426:"kpdelete",57427:"kpbegin",57428:"mediaplay",57429:"mediapause",57430:"mediaplaypause",57431:"mediareverse",57432:"mediastop",57433:"mediafastforward",57434:"mediarewind",57435:"mediatracknext",57436:"mediatrackprevious",57437:"mediarecord",57438:"lowervolume",57439:"raisevolume",57440:"mutevolume",57441:"leftshift",57442:"leftcontrol",57443:"leftalt",57444:"leftsuper",57445:"lefthyper",57446:"leftmeta",57447:"rightshift",57448:"rightcontrol",57449:"rightalt",57450:"rightsuper",57451:"righthyper",57452:"rightmeta",57453:"isoLevel3Shift",57454:"isoLevel5Shift"},x=e=>e>=0&&e<=1114111&&!(e>=55296&&e<=57343),g=e=>x(e)?String.fromCodePoint(e):"?";function A(e){return e===3?"release":e===2?"repeat":"press"}function O(e){return{capsLock:!!(e&p.capsLock),ctrl:!!(e&p.ctrl),hyper:!!(e&p.hyper),meta:!!(e&p.meta),numLock:!!(e&p.numLock),option:!!(e&p.alt),shift:!!(e&p.shift),super:!!(e&p.super)}}const z=e=>{const a=B.exec(e);if(!a)return null;const s=Number.parseInt(a[1],10),c=a[2]?Math.max(0,Number.parseInt(a[2],10)-1):0,t=a[3]?Number.parseInt(a[3],10):1,l=a[4];if(!x(s))return null;let n;l&&(n=l.split(":").map(d=>g(Number.parseInt(d,10))).join(""));let o,i;return s===32?(o="space",i=!0):s===13?(o="return",i=!0):v[s]?(o=v[s],i=!1):s>=1&&s<=26?(o=String.fromCodePoint(s+96),i=!1):(o=g(s).toLowerCase(),i=!0),i&&!n&&(n=g(s)),{name:o,...O(c),eventType:A(t),isKittyProtocol:!0,isPrintable:i,raw:e,sequence:e,text:n}},H=e=>{const a=D.exec(e);if(!a)return null;const s=Number.parseInt(a[1],10),c=Math.max(0,Number.parseInt(a[2],10)-1),t=Number.parseInt(a[3],10),l=a[4],n=l==="~"?U[s]:F[l];return n?{name:n,...O(c),eventType:A(t),isKittyProtocol:!0,isPrintable:!1,raw:e,sequence:e}:null},Q=(e="")=>{let a;j.isBuffer(e)?e[0]>127&&e[1]===void 0?(e[0]-=128,e=`\x1B${String(e)}`):e=String(e):e!==void 0&&typeof e!="string"?e=String(e):e||(e="");const s=z(e);if(s)return s;const c=H(e);if(c)return c;if(B.test(e))return{ctrl:!1,isKittyProtocol:!0,isPrintable:!1,meta:!1,name:"",option:!1,raw:e,sequence:e,shift:!1};const t={ctrl:!1,meta:!1,name:"",option:!1,raw:e,sequence:e,shift:!1};switch(t.sequence=t.sequence||e||t.name,e){case"\r":case"\x1B\r":{t.raw=void 0,t.name="return",t.option=e.length===2;break}case`
|
|
2
|
+
`:{t.name="enter";break}case" ":{t.name="tab";break}case" ":case"\x1B ":{t.name="space",t.meta=e.length===2;break}case"\b":case"\x1B\b":{t.name="backspace",t.meta=e.charAt(0)==="\x1B";break}case"\x1B":case"\x1B\x1B":{t.name="escape",t.meta=e.length===2;break}case"\x1B":case"":{t.name="backspace",t.meta=e.charAt(0)==="\x1B";break}default:if(e.length===1&&e<="")t.name=String.fromCharCode(e.charCodeAt(0)+97-1),t.ctrl=!0;else if(e.length===1&&e>="0"&&e<="9")t.name="number";else if(e.length===1&&e>="a"&&e<="z")t.name=e;else if(e.length===1&&e>="A"&&e<="Z")t.name=e.toLowerCase(),t.shift=!0;else if(a=M.exec(e))t.meta=!0,t.shift=/^[A-Z]$/.test(a[1]);else if(a=R.exec(e)){const l=[...e];l[0]==="\x1B"&&l[1]==="\x1B"&&(t.option=!0);const n=[a[1],a[2],a[4],a[6]].filter(Boolean).join(""),o=(a[3]||a[5]||1)-1;t.ctrl=!!(o&4),t.meta=!!(o&10),t.shift=!!(o&1),t.code=n,t.name=y[n]??"",t.shift=K(n)||t.shift,t.ctrl=Z(n)||t.ctrl}}return t},ee=(e,a={})=>{const{internal_eventEmitter:s,internal_exitOnCtrlC:c,setRawMode:t,stdin:l}=N(),n=a.imeEnabled??!0,o=a.imeTimeout??50,i=P(void 0),d=q(e);b(()=>{if(n)return i.current=new S({onFlush:h=>{const u={backspace:!1,capsLock:!1,ctrl:!1,delete:!1,downArrow:!1,end:!1,escape:!1,home:!1,hyper:!1,leftArrow:!1,meta:!1,numLock:!1,pageDown:!1,pageUp:!1,return:!1,rightArrow:!1,shift:!1,super:!1,tab:!1,upArrow:!1};w.discreteUpdates(()=>{d(h,u)})},timeout:o}),()=>{i.current?.destroy(),i.current=void 0}},[n,o]),b(()=>{if(a.isActive!==!1)return t(!0),()=>{t(!1)}},[a.isActive,t]),E(()=>{if(a.isActive===!1)return;const h=u=>{if(n&&I(u)){i.current?.add(u);return}i.current?.flush();const r=Q(u),k={backspace:r.name==="backspace",capsLock:r.capsLock??!1,ctrl:r.ctrl,delete:r.name==="delete",downArrow:r.name==="down",end:r.name==="end",escape:r.name==="escape",eventType:r.eventType,home:r.name==="home",hyper:r.hyper??!1,leftArrow:r.name==="left",meta:r.meta||r.option,numLock:r.numLock??!1,pageDown:r.name==="pagedown",pageUp:r.name==="pageup",return:r.name==="return",rightArrow:r.name==="right",shift:r.shift,super:r.super??!1,tab:r.name==="tab",upArrow:r.name==="up"};let f;r.isKittyProtocol?r.isPrintable?f=r.text??r.name:r.ctrl&&r.name.length===1?f=r.name:f="":r.ctrl?f=r.name:f=r.sequence,!r.isKittyProtocol&&T.includes(r.name)&&(f=""),f.startsWith("\x1B")&&(f=f.slice(1)),f.length===1&&typeof f[0]=="string"&&/[A-Z]/.test(f[0])&&(k.shift=!0),!(f==="c"&&k.ctrl&&c)&&(!r.name&&f===""||w.discreteUpdates(()=>{d(f,k)}))};return s.on("input",h),()=>{s.removeListener("input",h)}},[a.isActive,l,c,n])};export{ee as default,ee as useInput};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
type UseIntervalOptions = {
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
* When false, the timer is paused. Flipping back to true restarts it.
|
|
4
|
+
* @default true
|
|
5
|
+
*/
|
|
6
6
|
readonly isActive?: boolean;
|
|
7
7
|
};
|
|
8
8
|
type UseIntervalResult = {
|
|
9
9
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
* Cancel the currently-running timer. The hook effect will reschedule on
|
|
11
|
+
* the next re-render if `isActive` remains true.
|
|
12
|
+
*/
|
|
13
13
|
readonly clear: () => void;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* A React hook that invokes `callback` every `interval` ms. The callback
|
|
17
|
-
* reference is captured in a ref so it always sees the latest closure; only
|
|
18
|
-
* `interval` and `isActive` cause the timer to be rebuilt.
|
|
19
|
-
* @param callback Invoked on every tick. Latest closure is captured in a ref.
|
|
20
|
-
* @param interval Tick period in milliseconds. Invalid values pause the timer.
|
|
21
|
-
* @param options Optional `isActive` flag to pause without unmounting.
|
|
22
|
-
* @returns A stable object with a `clear()` method to cancel on demand.
|
|
23
|
-
*/
|
|
16
|
+
* A React hook that invokes `callback` every `interval` ms. The callback
|
|
17
|
+
* reference is captured in a ref so it always sees the latest closure; only
|
|
18
|
+
* `interval` and `isActive` cause the timer to be rebuilt.
|
|
19
|
+
* @param callback Invoked on every tick. Latest closure is captured in a ref.
|
|
20
|
+
* @param interval Tick period in milliseconds. Invalid values pause the timer.
|
|
21
|
+
* @param options Optional `isActive` flag to pause without unmounting.
|
|
22
|
+
* @returns A stable object with a `clear()` method to cancel on demand.
|
|
23
|
+
*/
|
|
24
24
|
declare const useInterval: (callback: () => void, interval: number, options?: UseIntervalOptions) => UseIntervalResult;
|
|
25
25
|
export { UseIntervalOptions, UseIntervalResult, useInterval as default, useInterval };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
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.
|
|
4
|
-
*/
|
|
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.
|
|
4
|
+
*/
|
|
5
5
|
declare const useIsScreenReaderEnabled: () => boolean;
|
|
6
6
|
export { useIsScreenReaderEnabled as default, useIsScreenReaderEnabled };
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A single key binding definition.
|
|
3
|
-
*/
|
|
2
|
+
* A single key binding definition.
|
|
3
|
+
*/
|
|
4
4
|
type KeyBinding = {
|
|
5
5
|
/** Human-readable description shown in Help. */
|
|
6
6
|
readonly description: string;
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
* Whether this binding is active.
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
11
|
readonly enabled?: boolean;
|
|
12
12
|
/** Optional group name for organizing in the Help component's full mode. */
|
|
13
13
|
readonly group?: string;
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
* Key(s) that trigger this binding.
|
|
16
|
+
*
|
|
17
|
+
* A string can be:
|
|
18
|
+
* - A single character: `"q"`, `"a"`, `" "` (space)
|
|
19
|
+
* - A `Key` boolean field name: `"return"`, `"escape"`, `"upArrow"`, `"leftArrow"`, etc.
|
|
20
|
+
* - A modifier combo: `"ctrl+c"`, `"meta+s"` (modifier + character)
|
|
21
|
+
*
|
|
22
|
+
* Provide an array to match multiple keys for the same action.
|
|
23
|
+
*/
|
|
24
24
|
readonly key: string | ReadonlyArray<string>;
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
|
-
* A binding paired with its handler function.
|
|
28
|
-
*/
|
|
27
|
+
* A binding paired with its handler function.
|
|
28
|
+
*/
|
|
29
29
|
type KeyBindingHandler = {
|
|
30
30
|
readonly binding: KeyBinding;
|
|
31
31
|
readonly handler: () => void;
|
|
32
32
|
};
|
|
33
33
|
type UseKeyBindingsOptions = {
|
|
34
34
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
* Whether keyboard input is captured.
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
38
|
readonly isActive?: boolean;
|
|
39
39
|
};
|
|
40
40
|
type UseKeyBindingsResult = {
|
|
@@ -42,18 +42,18 @@ type UseKeyBindingsResult = {
|
|
|
42
42
|
readonly bindings: ReadonlyArray<KeyBinding>;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
|
-
* Declarative keybinding hook. Registers multiple key bindings with handlers
|
|
46
|
-
* and returns the enabled bindings for display in a Help component.
|
|
47
|
-
*
|
|
48
|
-
* ```tsx
|
|
49
|
-
* const { bindings } = useKeyBindings([
|
|
50
|
-
* { binding: { key: "q", description: "Quit" }, handler: () => exit() },
|
|
51
|
-
* { binding: { key: ["upArrow", "k"], description: "Move up" }, handler: () => moveUp() },
|
|
52
|
-
* { binding: { key: "ctrl+s", description: "Save" }, handler: () => save() },
|
|
53
|
-
* ]);
|
|
54
|
-
*
|
|
55
|
-
* <Help bindings={bindings} />
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
45
|
+
* Declarative keybinding hook. Registers multiple key bindings with handlers
|
|
46
|
+
* and returns the enabled bindings for display in a Help component.
|
|
47
|
+
*
|
|
48
|
+
* ```tsx
|
|
49
|
+
* const { bindings } = useKeyBindings([
|
|
50
|
+
* { binding: { key: "q", description: "Quit" }, handler: () => exit() },
|
|
51
|
+
* { binding: { key: ["upArrow", "k"], description: "Move up" }, handler: () => moveUp() },
|
|
52
|
+
* { binding: { key: "ctrl+s", description: "Save" }, handler: () => save() },
|
|
53
|
+
* ]);
|
|
54
|
+
*
|
|
55
|
+
* <Help bindings={bindings} />
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
58
|
declare function useKeyBindings(handlers: ReadonlyArray<KeyBindingHandler>, options?: UseKeyBindingsOptions): UseKeyBindingsResult;
|
|
59
59
|
export { KeyBinding, KeyBindingHandler, useKeyBindings as default, useKeyBindings };
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
type KeyChordStep = string;
|
|
2
2
|
type UseKeyChordOptions = {
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
* Disable the chord while keeping the component rendered.
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
7
|
readonly isActive?: boolean;
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
* Milliseconds of silence after which the partial chord resets.
|
|
10
|
+
* @default 1000
|
|
11
|
+
*/
|
|
12
12
|
readonly resetAfter?: number;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
* Invoke `callback` when the user types the given sequence of keys in order
|
|
16
|
-
* (like Vim's `g d` or Emacs's `C-x C-s`). The chord resets automatically
|
|
17
|
-
* after `resetAfter` ms of silence.
|
|
18
|
-
* @param sequence Ordered list of chord steps. Each step is compared against
|
|
19
|
-
* a canonical key token (e.g. `"g"`, `"space"`, `"ctrl+s"`).
|
|
20
|
-
* @param callback Invoked exactly once per successful chord match. Latest
|
|
21
|
-
* reference is captured in a ref.
|
|
22
|
-
* @param options Optional `isActive` flag and `resetAfter` silence timeout.
|
|
23
|
-
*/
|
|
15
|
+
* Invoke `callback` when the user types the given sequence of keys in order
|
|
16
|
+
* (like Vim's `g d` or Emacs's `C-x C-s`). The chord resets automatically
|
|
17
|
+
* after `resetAfter` ms of silence.
|
|
18
|
+
* @param sequence Ordered list of chord steps. Each step is compared against
|
|
19
|
+
* a canonical key token (e.g. `"g"`, `"space"`, `"ctrl+s"`).
|
|
20
|
+
* @param callback Invoked exactly once per successful chord match. Latest
|
|
21
|
+
* reference is captured in a ref.
|
|
22
|
+
* @param options Optional `isActive` flag and `resetAfter` silence timeout.
|
|
23
|
+
*/
|
|
24
24
|
declare const useKeyChord: (sequence: ReadonlyArray<KeyChordStep>, callback: () => void, options?: UseKeyChordOptions) => void;
|
|
25
25
|
export { KeyChordStep, UseKeyChordOptions, useKeyChord as default, useKeyChord };
|
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
type Options = {
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
* Enable or disable the paste handler. Useful when multiple components use `usePaste` and only one should be active at a time.
|
|
4
|
+
* @default true
|
|
5
|
+
*/
|
|
6
6
|
isActive?: boolean;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* A React hook that calls `handler` whenever the user pastes text in the
|
|
10
|
-
* terminal. Bracketed paste mode (`\x1b[?2004h`) is automatically enabled while
|
|
11
|
-
* the hook is active, so pasted text arrives as a single string rather than being
|
|
12
|
-
* misinterpreted as individual key presses.
|
|
13
|
-
*
|
|
14
|
-
* `usePaste` is the dedicated API for paste blobs. `usePaste` and `useInput` can
|
|
15
|
-
* be used together in the same component; they operate on separate event
|
|
16
|
-
* channels, so paste content is never forwarded to `useInput` handlers while a
|
|
17
|
-
* `usePaste` handler is active.
|
|
18
|
-
*
|
|
19
|
-
* If no `usePaste` handler is active, Ink still forwards bracketed paste text to
|
|
20
|
-
* `useInput` for backward compatibility. That fallback is deprecated and will be
|
|
21
|
-
* removed in the next major version.
|
|
22
|
-
*
|
|
23
|
-
* ```
|
|
24
|
-
* import {useInput} from '@visulima/tui/hooks/use-input';
|
|
25
|
-
* import {usePaste} from '@visulima/tui/hooks/use-paste';
|
|
26
|
-
*
|
|
27
|
-
* const MyInput = () => {
|
|
28
|
-
* useInput((input, key) => {
|
|
29
|
-
* // Only receives typed characters and key events, not pasted text.
|
|
30
|
-
* if (key.return) {
|
|
31
|
-
* // Submit
|
|
32
|
-
* }
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* usePaste((text) => {
|
|
36
|
-
* // Receives the full pasted string, including newlines.
|
|
37
|
-
* console.log('Pasted:', text);
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* return …
|
|
41
|
-
* };
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
9
|
+
* A React hook that calls `handler` whenever the user pastes text in the
|
|
10
|
+
* terminal. Bracketed paste mode (`\x1b[?2004h`) is automatically enabled while
|
|
11
|
+
* the hook is active, so pasted text arrives as a single string rather than being
|
|
12
|
+
* misinterpreted as individual key presses.
|
|
13
|
+
*
|
|
14
|
+
* `usePaste` is the dedicated API for paste blobs. `usePaste` and `useInput` can
|
|
15
|
+
* be used together in the same component; they operate on separate event
|
|
16
|
+
* channels, so paste content is never forwarded to `useInput` handlers while a
|
|
17
|
+
* `usePaste` handler is active.
|
|
18
|
+
*
|
|
19
|
+
* If no `usePaste` handler is active, Ink still forwards bracketed paste text to
|
|
20
|
+
* `useInput` for backward compatibility. That fallback is deprecated and will be
|
|
21
|
+
* removed in the next major version.
|
|
22
|
+
*
|
|
23
|
+
* ```
|
|
24
|
+
* import {useInput} from '@visulima/tui/hooks/use-input';
|
|
25
|
+
* import {usePaste} from '@visulima/tui/hooks/use-paste';
|
|
26
|
+
*
|
|
27
|
+
* const MyInput = () => {
|
|
28
|
+
* useInput((input, key) => {
|
|
29
|
+
* // Only receives typed characters and key events, not pasted text.
|
|
30
|
+
* if (key.return) {
|
|
31
|
+
* // Submit
|
|
32
|
+
* }
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* usePaste((text) => {
|
|
36
|
+
* // Receives the full pasted string, including newlines.
|
|
37
|
+
* console.log('Pasted:', text);
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* return …
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
44
|
declare const usePaste: (handler: (text: string) => void, options?: Options) => void;
|
|
45
45
|
export { usePaste as default, usePaste };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffectEvent as c,useEffect as a}from"react";import{j as u}from"../../packem_shared/reconciler-
|
|
1
|
+
import{useEffectEvent as c,useEffect as a}from"react";import{j as u}from"../../packem_shared/reconciler-DkwOtC5B.js";import{useStdinContext as m}from"./use-stdin.js";const l=(o,e={})=>{const{internal_eventEmitter:t,setBracketedPasteMode:s,setRawMode:r}=m(),f=c(o);a(()=>{if(e.isActive!==!1)return r(!0),s(!0),()=>{r(!1),s(!1)}},[e.isActive,r,s]),a(()=>{if(e.isActive===!1)return;const i=n=>{u.discreteUpdates(()=>{f(n)})};return t.on("paste",i),()=>{t.removeListener("paste",i)}},[e.isActive,t])};export{l as default,l as usePaste};
|