@alchemy.run/sigil 0.0.0-alpha.1 → 0.0.0-alpha.2
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/README.md +299 -299
- package/dist/ansi.d.ts +223 -0
- package/dist/ansi.js +2 -0
- package/dist/{devtools-QpCMm9JH.mjs → devtools-BhYGjb7h.js} +1 -1
- package/dist/index-DDVME65c.d.ts +919 -0
- package/dist/index.d.ts +1657 -0
- package/dist/index.js +4643 -0
- package/dist/sgr-CMfEpjSk.d.ts +91 -0
- package/dist/truncate-CBiyyZzw.js +2156 -0
- package/dist/yoga-5jKhYCJC.js +3465 -0
- package/dist/yoga.d.ts +2 -0
- package/dist/yoga.js +2 -0
- package/package.json +37 -17
- package/src/ansi/chalk.ts +179 -0
- package/src/ansi/cursor.ts +48 -0
- package/src/ansi/east-asian-width.ts +215 -0
- package/src/ansi/escapes.ts +128 -0
- package/src/ansi/index.ts +27 -0
- package/src/ansi/sgr.ts +237 -0
- package/src/ansi/slice.ts +43 -0
- package/src/ansi/string-width.ts +236 -0
- package/src/ansi/strip.ts +33 -0
- package/src/ansi/supports-color.ts +213 -0
- package/src/ansi/tokenize.ts +453 -0
- package/src/ansi/truncate.ts +194 -0
- package/src/ansi/widest-line.ts +12 -0
- package/src/ansi/wrap.ts +766 -0
- package/src/ansi-tokenizer.ts +510 -0
- package/src/auto-bind.ts +41 -0
- package/src/boxes.ts +100 -0
- package/src/code-excerpt.ts +39 -0
- package/src/colorize.ts +60 -0
- package/src/components/AccessibilityContext.ts +5 -0
- package/src/components/AnimationContext.ts +24 -0
- package/src/components/App.tsx +781 -0
- package/src/components/AppContext.ts +111 -0
- package/src/components/BackgroundContext.ts +8 -0
- package/src/components/Box.tsx +116 -0
- package/src/components/CursorContext.ts +19 -0
- package/src/components/ErrorBoundary.tsx +38 -0
- package/src/components/ErrorOverview.tsx +133 -0
- package/src/components/FocusContext.ts +30 -0
- package/src/components/Newline.tsx +15 -0
- package/src/components/Spacer.tsx +10 -0
- package/src/components/Static.tsx +59 -0
- package/src/components/StderrContext.ts +26 -0
- package/src/components/StdinContext.ts +49 -0
- package/src/components/StdoutContext.ts +28 -0
- package/src/components/Text.tsx +144 -0
- package/src/components/Transform.tsx +37 -0
- package/src/cursor-position.ts +103 -0
- package/src/devtools-window-polyfill.ts +73 -0
- package/src/devtools.ts +43 -0
- package/src/dom.ts +292 -0
- package/src/get-max-width.ts +11 -0
- package/src/global.d.ts +36 -0
- package/src/hooks/use-animation.ts +142 -0
- package/src/hooks/use-app.ts +8 -0
- package/src/hooks/use-box-metrics.ts +134 -0
- package/src/hooks/use-cursor.ts +33 -0
- package/src/hooks/use-focus-manager.ts +62 -0
- package/src/hooks/use-focus.ts +83 -0
- package/src/hooks/use-input.ts +267 -0
- package/src/hooks/use-is-screen-reader-enabled.ts +12 -0
- package/src/hooks/use-paste.ts +78 -0
- package/src/hooks/use-stderr.ts +8 -0
- package/src/hooks/use-stdin.ts +10 -0
- package/src/hooks/use-stdout.ts +8 -0
- package/src/hooks/use-window-size.ts +41 -0
- package/src/indent-string.ts +16 -0
- package/src/index.ts +44 -0
- package/src/ink.tsx +1506 -0
- package/src/input-parser.ts +283 -0
- package/src/instances.ts +9 -0
- package/src/is-in-ci.ts +7 -0
- package/src/kitty-keyboard.ts +57 -0
- package/src/log-update.ts +370 -0
- package/src/measure-element.ts +62 -0
- package/src/measure-text.ts +31 -0
- package/src/output.ts +308 -0
- package/src/parse-keypress.ts +516 -0
- package/src/parse-stack-line.ts +139 -0
- package/src/patch-console.ts +62 -0
- package/src/quick-lru.ts +85 -0
- package/src/reconciler.ts +451 -0
- package/src/render-background.ts +38 -0
- package/src/render-border.ts +134 -0
- package/src/render-node-to-output.ts +191 -0
- package/src/render-to-string.ts +131 -0
- package/src/render.ts +276 -0
- package/src/renderer.ts +73 -0
- package/src/sanitize-ansi.ts +33 -0
- package/src/signal-exit.ts +107 -0
- package/src/squash-text-nodes.ts +40 -0
- package/src/stream.ts +30 -0
- package/src/styles.ts +748 -0
- package/src/terminal-size.ts +57 -0
- package/src/throttle.ts +73 -0
- package/src/types.ts +15 -0
- package/src/utils.ts +40 -0
- package/src/wrap-text.ts +50 -0
- package/src/write-synchronized.ts +9 -0
- package/src/yoga/config.ts +57 -0
- package/src/yoga/core/absoluteLayout.ts +626 -0
- package/src/yoga/core/baseline.ts +66 -0
- package/src/yoga/core/cache.ts +136 -0
- package/src/yoga/core/calculateLayout.ts +2920 -0
- package/src/yoga/core/config.ts +104 -0
- package/src/yoga/core/flexLine.ts +177 -0
- package/src/yoga/core/helpers.ts +293 -0
- package/src/yoga/core/layoutResults.ts +167 -0
- package/src/yoga/core/node.ts +611 -0
- package/src/yoga/core/numeric.ts +44 -0
- package/src/yoga/core/pixelGrid.ts +151 -0
- package/src/yoga/core/style.ts +887 -0
- package/src/yoga/core/types.ts +224 -0
- package/src/yoga/generated/YGEnums.ts +263 -0
- package/src/yoga/index.ts +19 -0
- package/src/yoga/node.ts +1140 -0
- package/dist/index.d.mts +0 -2379
- package/dist/index.mjs +0 -10072
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { useEffect, useEffectEvent } from "react";
|
|
2
|
+
|
|
3
|
+
import { ESC } from "../ansi/escapes.ts";
|
|
4
|
+
import { parseKeypress, nonAlphanumericKeys } from "../parse-keypress.ts";
|
|
5
|
+
import { reconciler } from "../reconciler.ts";
|
|
6
|
+
import { useStdinContext } from "./use-stdin.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
Handy information about a key that was pressed.
|
|
10
|
+
*/
|
|
11
|
+
export type Key = {
|
|
12
|
+
/**
|
|
13
|
+
Up arrow key was pressed.
|
|
14
|
+
*/
|
|
15
|
+
upArrow: boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Down arrow key was pressed.
|
|
19
|
+
*/
|
|
20
|
+
downArrow: boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
Left arrow key was pressed.
|
|
24
|
+
*/
|
|
25
|
+
leftArrow: boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
Right arrow key was pressed.
|
|
29
|
+
*/
|
|
30
|
+
rightArrow: boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
Page Down key was pressed.
|
|
34
|
+
*/
|
|
35
|
+
pageDown: boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
Page Up key was pressed.
|
|
39
|
+
*/
|
|
40
|
+
pageUp: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
Home key was pressed.
|
|
44
|
+
*/
|
|
45
|
+
home: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
End key was pressed.
|
|
49
|
+
*/
|
|
50
|
+
end: boolean;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
Return (Enter) key was pressed.
|
|
54
|
+
*/
|
|
55
|
+
return: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
Escape key was pressed.
|
|
59
|
+
*/
|
|
60
|
+
escape: boolean;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
Ctrl key was pressed.
|
|
64
|
+
*/
|
|
65
|
+
ctrl: boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
Shift key was pressed.
|
|
69
|
+
*/
|
|
70
|
+
shift: boolean;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
Tab key was pressed.
|
|
74
|
+
*/
|
|
75
|
+
tab: boolean;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
Backspace key was pressed.
|
|
79
|
+
*/
|
|
80
|
+
backspace: boolean;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
Delete key was pressed.
|
|
84
|
+
*/
|
|
85
|
+
delete: boolean;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
[Meta key](https://en.wikipedia.org/wiki/Meta_key) was pressed.
|
|
89
|
+
*/
|
|
90
|
+
meta: boolean;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
Super key (Cmd on Mac, Win on Windows) was pressed.
|
|
94
|
+
|
|
95
|
+
Only available with kitty keyboard protocol.
|
|
96
|
+
*/
|
|
97
|
+
super: boolean;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
Hyper key was pressed.
|
|
101
|
+
|
|
102
|
+
Only available with kitty keyboard protocol.
|
|
103
|
+
*/
|
|
104
|
+
hyper: boolean;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
Caps Lock is active.
|
|
108
|
+
|
|
109
|
+
Only available with kitty keyboard protocol.
|
|
110
|
+
*/
|
|
111
|
+
capsLock: boolean;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
Num Lock is active.
|
|
115
|
+
|
|
116
|
+
Only available with kitty keyboard protocol.
|
|
117
|
+
*/
|
|
118
|
+
numLock: boolean;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
Event type for key events.
|
|
122
|
+
|
|
123
|
+
Only available with kitty keyboard protocol.
|
|
124
|
+
*/
|
|
125
|
+
eventType?: "press" | "repeat" | "release";
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
type Handler = (input: string, key: Key) => void;
|
|
129
|
+
|
|
130
|
+
type Options = {
|
|
131
|
+
/**
|
|
132
|
+
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.
|
|
133
|
+
|
|
134
|
+
@default true
|
|
135
|
+
*/
|
|
136
|
+
isActive?: boolean;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
A React hook that returns `void` and handles user input.
|
|
141
|
+
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`.
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
import {useInput} from 'ink';
|
|
145
|
+
|
|
146
|
+
const UserInput = () => {
|
|
147
|
+
useInput((input, key) => {
|
|
148
|
+
if (input === 'q') {
|
|
149
|
+
// Exit program
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (key.leftArrow) {
|
|
153
|
+
// Left arrow key pressed
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return …
|
|
158
|
+
};
|
|
159
|
+
```
|
|
160
|
+
*/
|
|
161
|
+
export const useInput = (inputHandler: Handler, options: Options = {}) => {
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
163
|
+
const { setRawMode, internal_exitOnCtrlC, internal_eventEmitter } = useStdinContext();
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (options.isActive === false) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
setRawMode(true);
|
|
171
|
+
|
|
172
|
+
return () => {
|
|
173
|
+
setRawMode(false);
|
|
174
|
+
};
|
|
175
|
+
}, [options.isActive, setRawMode]);
|
|
176
|
+
|
|
177
|
+
const handleData = useEffectEvent((data: string) => {
|
|
178
|
+
const keypress = parseKeypress(data);
|
|
179
|
+
|
|
180
|
+
const key: Key = {
|
|
181
|
+
upArrow: keypress.name === "up",
|
|
182
|
+
downArrow: keypress.name === "down",
|
|
183
|
+
leftArrow: keypress.name === "left",
|
|
184
|
+
rightArrow: keypress.name === "right",
|
|
185
|
+
pageDown: keypress.name === "pagedown",
|
|
186
|
+
pageUp: keypress.name === "pageup",
|
|
187
|
+
home: keypress.name === "home",
|
|
188
|
+
end: keypress.name === "end",
|
|
189
|
+
return: keypress.name === "return",
|
|
190
|
+
escape: keypress.name === "escape",
|
|
191
|
+
ctrl: keypress.ctrl,
|
|
192
|
+
shift: keypress.shift,
|
|
193
|
+
tab: keypress.name === "tab",
|
|
194
|
+
backspace: keypress.name === "backspace",
|
|
195
|
+
delete: keypress.name === "delete",
|
|
196
|
+
meta: keypress.meta,
|
|
197
|
+
// Kitty keyboard protocol modifiers
|
|
198
|
+
super: keypress.super ?? false,
|
|
199
|
+
hyper: keypress.hyper ?? false,
|
|
200
|
+
capsLock: keypress.capsLock ?? false,
|
|
201
|
+
numLock: keypress.numLock ?? false,
|
|
202
|
+
eventType: keypress.eventType,
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
let input: string;
|
|
206
|
+
if (keypress.isKittyProtocol) {
|
|
207
|
+
// Use text-as-codepoints field for printable keys (needed when
|
|
208
|
+
// reportAllKeysAsEscapeCodes flag is enabled), suppress non-printable
|
|
209
|
+
if (keypress.isPrintable) {
|
|
210
|
+
input = keypress.text ?? keypress.name;
|
|
211
|
+
} else if (keypress.ctrl && keypress.name.length === 1) {
|
|
212
|
+
// Ctrl+letter via codepoint 1-26 form: not printable text, but
|
|
213
|
+
// the letter name must flow through so handlers (e.g. exitOnCtrlC
|
|
214
|
+
// checking `input === 'c' && key.ctrl`) still work.
|
|
215
|
+
input = keypress.name;
|
|
216
|
+
} else {
|
|
217
|
+
input = "";
|
|
218
|
+
}
|
|
219
|
+
} else if (keypress.ctrl) {
|
|
220
|
+
// Keypress.name is guaranteed non-undefined by parseKeypress,
|
|
221
|
+
// but guard defensively since a TypeError here would crash the
|
|
222
|
+
// entire Ink app (see https://github.com/vadimdemedes/ink/issues/901).
|
|
223
|
+
input = keypress.name ?? "";
|
|
224
|
+
} else {
|
|
225
|
+
input = keypress.sequence;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!keypress.isKittyProtocol && nonAlphanumericKeys.includes(keypress.name)) {
|
|
229
|
+
input = "";
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Strip escape prefix from broken/incomplete sequences that
|
|
233
|
+
// parseKeypress did not fully resolve (e.g. a flushed "\u001B[").
|
|
234
|
+
if (input.startsWith(ESC)) {
|
|
235
|
+
input = input.slice(1);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (input.length === 1 && /[A-Z]/.test(input)) {
|
|
239
|
+
key.shift = true;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// If app is supposed to exit on Ctrl+C, skip input listeners.
|
|
243
|
+
if (input === "c" && key.ctrl && internal_exitOnCtrlC) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Use discreteUpdates to assign DiscreteEventPriority to state
|
|
248
|
+
// updates from keyboard input, ensuring they are processed at the
|
|
249
|
+
// highest priority in concurrent mode.
|
|
250
|
+
// @ts-expect-error Types require 5 arguments (fn, a, b, c, d) but only fn is needed at runtime.
|
|
251
|
+
reconciler.discreteUpdates(() => {
|
|
252
|
+
inputHandler(input, key);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
useEffect(() => {
|
|
257
|
+
if (options.isActive === false) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
internal_eventEmitter.on("input", handleData);
|
|
262
|
+
|
|
263
|
+
return () => {
|
|
264
|
+
internal_eventEmitter.removeListener("input", handleData);
|
|
265
|
+
};
|
|
266
|
+
}, [options.isActive, internal_eventEmitter]);
|
|
267
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
|
|
3
|
+
import { accessibilityContext } from "../components/AccessibilityContext.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
A React hook that returns whether a screen reader is enabled.
|
|
7
|
+
This is useful when you want to render different output for screen readers.
|
|
8
|
+
*/
|
|
9
|
+
export const useIsScreenReaderEnabled = (): boolean => {
|
|
10
|
+
const { isScreenReaderEnabled } = useContext(accessibilityContext);
|
|
11
|
+
return isScreenReaderEnabled;
|
|
12
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useEffect, useEffectEvent } from "react";
|
|
2
|
+
|
|
3
|
+
import { reconciler } from "../reconciler.ts";
|
|
4
|
+
import { useStdinContext } from "./use-stdin.ts";
|
|
5
|
+
|
|
6
|
+
type Options = {
|
|
7
|
+
/**
|
|
8
|
+
Enable or disable the paste handler. Useful when multiple components use `usePaste` and only one should be active at a time.
|
|
9
|
+
|
|
10
|
+
@default true
|
|
11
|
+
*/
|
|
12
|
+
isActive?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
`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.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
import {useInput, usePaste} from 'ink';
|
|
22
|
+
|
|
23
|
+
const MyInput = () => {
|
|
24
|
+
useInput((input, key) => {
|
|
25
|
+
// Only receives typed characters and key events, not pasted text.
|
|
26
|
+
if (key.return) {
|
|
27
|
+
// Submit
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
usePaste((text) => {
|
|
32
|
+
// Receives the full pasted string, including newlines.
|
|
33
|
+
console.log('Pasted:', text);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return …
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
*/
|
|
40
|
+
export const usePaste = (handler: (text: string) => void, options: Options = {}): void => {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
42
|
+
const { setRawMode, setBracketedPasteMode, internal_eventEmitter } = useStdinContext();
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (options.isActive === false) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setRawMode(true);
|
|
50
|
+
setBracketedPasteMode(true);
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
setRawMode(false);
|
|
54
|
+
setBracketedPasteMode(false);
|
|
55
|
+
};
|
|
56
|
+
}, [options.isActive, setRawMode, setBracketedPasteMode]);
|
|
57
|
+
|
|
58
|
+
const handlePaste = useEffectEvent((text: string) => {
|
|
59
|
+
// Use discreteUpdates to assign DiscreteEventPriority to state
|
|
60
|
+
// updates triggered by paste, matching the priority of useInput.
|
|
61
|
+
// @ts-expect-error Types require 5 arguments (fn, a, b, c, d) but only fn is needed at runtime.
|
|
62
|
+
reconciler.discreteUpdates(() => {
|
|
63
|
+
handler(text);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (options.isActive === false) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
internal_eventEmitter.on("paste", handlePaste);
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
internal_eventEmitter.removeListener("paste", handlePaste);
|
|
76
|
+
};
|
|
77
|
+
}, [options.isActive, internal_eventEmitter]);
|
|
78
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
|
|
3
|
+
import { StdinContext, type PublicProps, type Props } from "../components/StdinContext.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
A React hook that returns the stdin stream and stdin-related utilities.
|
|
7
|
+
*/
|
|
8
|
+
export const useStdin = (): PublicProps => useContext(StdinContext);
|
|
9
|
+
|
|
10
|
+
export const useStdinContext = (): Props => useContext(StdinContext);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import { getWindowSize } from "../utils.ts";
|
|
4
|
+
import { useStdout } from "./use-stdout.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Dimensions of the terminal window.
|
|
8
|
+
*/
|
|
9
|
+
export type WindowSize = {
|
|
10
|
+
/**
|
|
11
|
+
Number of columns (horizontal character cells).
|
|
12
|
+
*/
|
|
13
|
+
readonly columns: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
Number of rows (vertical character cells).
|
|
17
|
+
*/
|
|
18
|
+
readonly rows: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
A React hook that returns the current terminal window dimensions and re-renders the component whenever the terminal is resized.
|
|
23
|
+
*/
|
|
24
|
+
export const useWindowSize = (): WindowSize => {
|
|
25
|
+
const { stdout } = useStdout();
|
|
26
|
+
const [size, setSize] = useState<WindowSize>(() => getWindowSize(stdout));
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const onResize = () => {
|
|
30
|
+
setSize(getWindowSize(stdout));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
stdout.on("resize", onResize);
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
stdout.off("resize", onResize);
|
|
37
|
+
};
|
|
38
|
+
}, [stdout]);
|
|
39
|
+
|
|
40
|
+
return size;
|
|
41
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Derived from `indent-string` (MIT, Sindre Sorhus), reduced to the surface Ink uses.
|
|
2
|
+
export const indentString = (
|
|
3
|
+
string: string,
|
|
4
|
+
count = 1,
|
|
5
|
+
options: { indent?: string; includeEmptyLines?: boolean } = {},
|
|
6
|
+
): string => {
|
|
7
|
+
const { indent = " ", includeEmptyLines = false } = options;
|
|
8
|
+
|
|
9
|
+
if (count === 0) {
|
|
10
|
+
return string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
|
|
14
|
+
|
|
15
|
+
return string.replace(regex, indent.repeat(count));
|
|
16
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type { RenderOptions, Instance } from "./render.ts";
|
|
2
|
+
export type { CapturedOutputSource } from "./ink.tsx";
|
|
3
|
+
export { render } from "./render.ts";
|
|
4
|
+
export type { RenderToStringOptions } from "./render-to-string.ts";
|
|
5
|
+
export { renderToString } from "./render-to-string.ts";
|
|
6
|
+
export type { Props as BoxProps } from "./components/Box.tsx";
|
|
7
|
+
export { Box } from "./components/Box.tsx";
|
|
8
|
+
export type { Props as TextProps } from "./components/Text.tsx";
|
|
9
|
+
export { Text } from "./components/Text.tsx";
|
|
10
|
+
export type { Props as AppProps } from "./components/AppContext.ts";
|
|
11
|
+
export type { PublicProps as StdinProps } from "./components/StdinContext.ts";
|
|
12
|
+
export type { Props as StdoutProps } from "./components/StdoutContext.ts";
|
|
13
|
+
export type { Props as StderrProps } from "./components/StderrContext.ts";
|
|
14
|
+
export type { Props as StaticProps } from "./components/Static.tsx";
|
|
15
|
+
export { Static } from "./components/Static.tsx";
|
|
16
|
+
export type { Props as TransformProps } from "./components/Transform.tsx";
|
|
17
|
+
export { Transform } from "./components/Transform.tsx";
|
|
18
|
+
export type { Props as NewlineProps } from "./components/Newline.tsx";
|
|
19
|
+
export { Newline } from "./components/Newline.tsx";
|
|
20
|
+
export { Spacer } from "./components/Spacer.tsx";
|
|
21
|
+
export type { Key } from "./hooks/use-input.ts";
|
|
22
|
+
export { useInput } from "./hooks/use-input.ts";
|
|
23
|
+
export { usePaste } from "./hooks/use-paste.ts";
|
|
24
|
+
export type { SuspendTerminal, TerminalSuspension } from "./components/AppContext.ts";
|
|
25
|
+
export { useApp } from "./hooks/use-app.ts";
|
|
26
|
+
export { useStdin } from "./hooks/use-stdin.ts";
|
|
27
|
+
export { useStdout } from "./hooks/use-stdout.ts";
|
|
28
|
+
export { useStderr } from "./hooks/use-stderr.ts";
|
|
29
|
+
export { useFocus } from "./hooks/use-focus.ts";
|
|
30
|
+
export { useFocusManager } from "./hooks/use-focus-manager.ts";
|
|
31
|
+
export { useIsScreenReaderEnabled } from "./hooks/use-is-screen-reader-enabled.ts";
|
|
32
|
+
export { useCursor } from "./hooks/use-cursor.ts";
|
|
33
|
+
export type { AnimationResult } from "./hooks/use-animation.ts";
|
|
34
|
+
export { useAnimation } from "./hooks/use-animation.ts";
|
|
35
|
+
export type { WindowSize } from "./hooks/use-window-size.ts";
|
|
36
|
+
export { useWindowSize } from "./hooks/use-window-size.ts";
|
|
37
|
+
export type { BoxMetrics, UseBoxMetricsResult } from "./hooks/use-box-metrics.ts";
|
|
38
|
+
export { useBoxMetrics } from "./hooks/use-box-metrics.ts";
|
|
39
|
+
export type { CursorPosition } from "./log-update.ts";
|
|
40
|
+
export { measureElement } from "./measure-element.ts";
|
|
41
|
+
export type { ElementMetrics } from "./measure-element.ts";
|
|
42
|
+
export type { DOMElement } from "./dom.ts";
|
|
43
|
+
export { kittyFlags, kittyModifiers } from "./kitty-keyboard.ts";
|
|
44
|
+
export type { KittyKeyboardOptions, KittyFlagName } from "./kitty-keyboard.ts";
|