@alchemy.run/sigil 0.0.0-alpha.1 → 0.0.0-alpha.10
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 +499 -313
- package/THIRD_PARTY_NOTICES.md +70 -23
- package/dist/Text-DV9CuzAT.d.ts +452 -0
- package/dist/ansi.d.ts +217 -0
- package/dist/ansi.js +87 -0
- package/dist/capabilities.d.ts +5 -0
- package/dist/capabilities.js +3 -0
- package/dist/cell-_ZVhbfl0.js +44 -0
- package/dist/color-CkbalRqK.js +2 -0
- package/dist/color-policy-BAC9-TZX.js +592 -0
- package/dist/color-policy-CCxuHIdD.d.ts +22 -0
- package/dist/color-profile-CyeHnG1T.d.ts +97 -0
- package/dist/color-profile-DHhQHY55.js +36 -0
- package/dist/color.d.ts +21 -0
- package/dist/color.js +3 -0
- package/dist/cursor-position-D2LAkRG0.d.ts +7 -0
- package/dist/detect-B3dL4Q11.js +374 -0
- package/dist/detect-Db6GbKOm.d.ts +195 -0
- package/dist/{devtools-QpCMm9JH.mjs → devtools-DbthxoD1.js} +23 -24
- package/dist/env-YVw64yZS.js +9 -0
- package/dist/escapes-CB_6CWOE.d.ts +72 -0
- package/dist/geometry-BxXOzJgo.d.ts +11 -0
- package/dist/index-D48vQhhe.d.ts +21 -0
- package/dist/index-DDVME65c.d.ts +919 -0
- package/dist/index.d.ts +1310 -0
- package/dist/index.js +3209 -0
- package/dist/osc-BFKKSqpg.js +71 -0
- package/dist/osc-Cn0fw77g.d.ts +23 -0
- package/dist/paint-Cx-zC_sX.d.ts +81 -0
- package/dist/query-BNc2B8GD.d.ts +152 -0
- package/dist/router.d.ts +392 -0
- package/dist/router.js +709 -0
- package/dist/sample-Cqw1bjUL.js +445 -0
- package/dist/screen-CgC2WlVM.d.ts +49 -0
- package/dist/screen-CiPytswf.js +342 -0
- package/dist/screen.d.ts +5 -0
- package/dist/screen.js +5 -0
- package/dist/semantic-text-style-DIMzC7xt.js +91 -0
- package/dist/serialize-BTkAZgw1.js +79 -0
- package/dist/session-DDQ5V300.js +723 -0
- package/dist/sgr-BhwaWAJB.js +246 -0
- package/dist/store-C1P5fOUi.d.ts +72 -0
- package/dist/string-width-CijQwpIk.js +69 -0
- package/dist/strip-BvU4toXG.js +6 -0
- package/dist/terminal.d.ts +121 -0
- package/dist/terminal.js +2 -0
- package/dist/tokenize-AjqbvtiT.js +1242 -0
- package/dist/tokenize-Dx1y_l5H.d.ts +57 -0
- package/dist/truncate-D31fhU6i.js +562 -0
- package/dist/use-focus-CcCIdCWA.js +1337 -0
- package/dist/yoga-5jKhYCJC.js +3465 -0
- package/dist/yoga.d.ts +2 -0
- package/dist/yoga.js +2 -0
- package/package.json +70 -24
- package/src/ansi/chalk.ts +138 -0
- package/src/ansi/cursor.ts +46 -0
- package/src/ansi/east-asian-width.ts +259 -0
- package/src/ansi/escapes.ts +120 -0
- package/src/ansi/graphemes.ts +8 -0
- package/src/ansi/hyperlink.ts +44 -0
- package/src/ansi/index.ts +27 -0
- package/src/ansi/osc.ts +77 -0
- package/src/ansi/sgr.ts +234 -0
- package/src/ansi/slice.ts +43 -0
- package/src/ansi/string-width.ts +121 -0
- package/src/ansi/strip.ts +13 -0
- package/src/ansi/tokenize.ts +380 -0
- package/src/ansi/truncate.ts +196 -0
- package/src/ansi/wrap.ts +765 -0
- package/src/ansi-tokenizer.ts +510 -0
- package/src/capabilities/color-policy.ts +34 -0
- package/src/capabilities/detect.ts +608 -0
- package/src/capabilities/index.ts +37 -0
- package/src/capabilities/query.ts +679 -0
- package/src/capabilities/store.ts +394 -0
- package/src/code-excerpt.ts +39 -0
- package/src/color/index.ts +3 -0
- package/src/color/paint.ts +169 -0
- package/src/color/palette.ts +48 -0
- package/src/color/sample.ts +323 -0
- package/src/color.ts +1 -0
- package/src/components/AccessibilityContext.ts +5 -0
- package/src/components/AnimationContext.ts +24 -0
- package/src/components/AnsiText.tsx +42 -0
- package/src/components/App.tsx +878 -0
- package/src/components/AppContext.ts +111 -0
- package/src/components/BackgroundContext.ts +7 -0
- package/src/components/Box.tsx +100 -0
- package/src/components/CursorContext.ts +19 -0
- package/src/components/ErrorBoundary.tsx +39 -0
- package/src/components/ErrorOverview.tsx +135 -0
- package/src/components/FocusContext.ts +30 -0
- package/src/components/Hyperlink.tsx +56 -0
- package/src/components/Newline.tsx +16 -0
- package/src/components/Spacer.tsx +11 -0
- package/src/components/Static.tsx +60 -0
- package/src/components/StderrContext.ts +24 -0
- package/src/components/StdinContext.ts +48 -0
- package/src/components/StdoutContext.ts +26 -0
- package/src/components/TerminalOscContext.ts +25 -0
- package/src/components/Text.tsx +122 -0
- package/src/components/Transform.tsx +38 -0
- package/src/components/VirtualList.tsx +128 -0
- package/src/cursor-position.ts +103 -0
- package/src/devtools.ts +103 -0
- package/src/dom.ts +301 -0
- package/src/env.ts +12 -0
- package/src/get-max-width.ts +11 -0
- package/src/global.d.ts +38 -0
- package/src/glyphs.ts +99 -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-capabilities.ts +73 -0
- package/src/hooks/use-cursor.ts +33 -0
- package/src/hooks/use-focus-manager.ts +62 -0
- package/src/hooks/use-focus.ts +82 -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-terminal-osc.ts +59 -0
- package/src/hooks/use-virtual-scroll.ts +84 -0
- package/src/hooks/use-window-size.ts +37 -0
- package/src/index.ts +96 -0
- package/src/ink.tsx +1452 -0
- package/src/input-parser.ts +303 -0
- package/src/instances.ts +9 -0
- package/src/kitty-keyboard.ts +185 -0
- package/src/measure-element.ts +62 -0
- package/src/measure-text.ts +31 -0
- package/src/paint-tree.ts +220 -0
- package/src/parse-keypress.ts +515 -0
- package/src/parse-stack-line.ts +138 -0
- package/src/patch-console.ts +106 -0
- package/src/quick-lru.ts +85 -0
- package/src/reconciler.ts +425 -0
- package/src/render-background.ts +59 -0
- package/src/render-border.ts +167 -0
- package/src/render-frame.ts +83 -0
- package/src/render-to-string.ts +146 -0
- package/src/render.ts +284 -0
- package/src/router/components.tsx +343 -0
- package/src/router/context.ts +41 -0
- package/src/router/history.ts +194 -0
- package/src/router/hooks.tsx +391 -0
- package/src/router/index.ts +34 -0
- package/src/router/matcher.ts +571 -0
- package/src/sanitize-ansi.ts +33 -0
- package/src/screen/ansi.ts +184 -0
- package/src/screen/canvas.ts +160 -0
- package/src/screen/cell.ts +138 -0
- package/src/screen/color-profile.ts +47 -0
- package/src/screen/geometry.ts +9 -0
- package/src/screen/index.ts +6 -0
- package/src/screen/screen.ts +305 -0
- package/src/screen/serialize.ts +129 -0
- package/src/screen.ts +1 -0
- package/src/semantic-text-style.ts +118 -0
- package/src/signal-exit.ts +106 -0
- package/src/squash-text-nodes.ts +37 -0
- package/src/stream.ts +28 -0
- package/src/structured-text.ts +325 -0
- package/src/styles.ts +753 -0
- package/src/terminal/index.ts +2 -0
- package/src/terminal/inline-presenter.ts +120 -0
- package/src/terminal/input.ts +92 -0
- package/src/terminal/render-scheduler.ts +37 -0
- package/src/terminal/screen-presenter.ts +242 -0
- package/src/terminal/session.ts +408 -0
- package/src/terminal-size.ts +58 -0
- package/src/terminal.ts +1 -0
- package/src/testing/browser.ts +588 -0
- package/src/testing/emulators.ts +205 -0
- package/src/testing/explorer-app/index.html +12 -0
- package/src/testing/explorer-app/main.ts +381 -0
- package/src/testing/explorer-app/style.css +194 -0
- package/src/testing/explorer-app/tsconfig.json +15 -0
- package/src/testing/explorer-app/vite-env.d.ts +1 -0
- package/src/testing/index.ts +26 -0
- package/src/testing/keys.ts +56 -0
- package/src/testing/live.ts +85 -0
- package/src/testing/matchers.ts +70 -0
- package/src/testing/public.ts +94 -0
- package/src/testing/terminal.ts +361 -0
- package/src/testing/vitest.ts +157 -0
- package/src/throttle.ts +73 -0
- package/src/transform-adapter.ts +14 -0
- package/src/types.ts +10 -0
- package/src/virtual-scroll.ts +133 -0
- package/src/wrap-text.ts +54 -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 +2926 -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,78 @@
|
|
|
1
|
+
import { useEffect, useEffectEvent } from "react";
|
|
2
|
+
|
|
3
|
+
import { useStdinContext } from "#/hooks/use-stdin.ts";
|
|
4
|
+
import { reconciler } from "#/reconciler.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,59 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import type { ClipboardSelection, TerminalProgressState } from "#/ansi/osc.ts";
|
|
4
|
+
import { TerminalOscContext } from "#/components/TerminalOscContext.ts";
|
|
5
|
+
|
|
6
|
+
export type ProgressOptions = {
|
|
7
|
+
readonly state: TerminalProgressState;
|
|
8
|
+
readonly value?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const useProgress = ({ state, value }: ProgressOptions): void => {
|
|
12
|
+
const terminal = useContext(TerminalOscContext);
|
|
13
|
+
const owner = useRef<symbol>(undefined);
|
|
14
|
+
owner.current ??= Symbol("terminal-progress");
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
terminal.publishProgress(owner.current!, state, value);
|
|
18
|
+
}, [state, terminal, value]);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
return () => {
|
|
22
|
+
terminal.publishProgress(owner.current!, "inactive");
|
|
23
|
+
};
|
|
24
|
+
}, [terminal]);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const useClipboard = (): ((text: string, selection?: ClipboardSelection) => void) => {
|
|
28
|
+
const terminal = useContext(TerminalOscContext);
|
|
29
|
+
return useCallback((text, selection) => terminal.copyToClipboard(text, selection), [terminal]);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const useTitle = (title?: string): void => {
|
|
33
|
+
const terminal = useContext(TerminalOscContext);
|
|
34
|
+
const owner = useRef<symbol>(undefined);
|
|
35
|
+
owner.current ??= Symbol("terminal-title");
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
terminal.publishTitle(owner.current!, title);
|
|
38
|
+
}, [terminal, title]);
|
|
39
|
+
useEffect(() => () => terminal.publishTitle(owner.current!, undefined), [terminal]);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const useWorkingDirectory = (directory: URL | string): void => {
|
|
43
|
+
const terminal = useContext(TerminalOscContext);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
terminal.setWorkingDirectory(directory);
|
|
46
|
+
}, [directory, terminal]);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const useNotification = (): ((title: string) => void) => {
|
|
50
|
+
const terminal = useContext(TerminalOscContext);
|
|
51
|
+
return useCallback((title) => terminal.notify(title), [terminal]);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const usePointerShape = (shape: string): void => {
|
|
55
|
+
const terminal = useContext(TerminalOscContext);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
terminal.setPointerShape(shape);
|
|
58
|
+
}, [shape, terminal]);
|
|
59
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
virtualScrollWindow,
|
|
5
|
+
type VirtualScrollOptions,
|
|
6
|
+
type VirtualScrollWindow,
|
|
7
|
+
} from "#/virtual-scroll.ts";
|
|
8
|
+
|
|
9
|
+
export type UseVirtualScrollOptions = Omit<VirtualScrollOptions, "scrollTop">;
|
|
10
|
+
|
|
11
|
+
export type UseVirtualScrollResult = VirtualScrollWindow & {
|
|
12
|
+
/**
|
|
13
|
+
Scroll so the viewport starts `top` rows from the top of the list.
|
|
14
|
+
*/
|
|
15
|
+
readonly scrollTo: (top: number) => void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Scroll by `delta` rows; negative values scroll up.
|
|
19
|
+
*/
|
|
20
|
+
readonly scrollBy: (delta: number) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
A React hook that owns the scroll position of a windowed list and returns which
|
|
25
|
+
items to render for it. The position is clamped to the scrollable range and,
|
|
26
|
+
while `focusedIndex` is set, moved as little as necessary to keep that item
|
|
27
|
+
fully visible. Render the items in `[start, end)` inside an `overflowY="hidden"`
|
|
28
|
+
box of `viewportHeight` rows, shifted up by `offset` rows.
|
|
29
|
+
|
|
30
|
+
`<VirtualList>` wraps this hook; use it directly to draw your own chrome such
|
|
31
|
+
as overflow markers or a scrollbar around the window.
|
|
32
|
+
|
|
33
|
+
@example
|
|
34
|
+
```tsx
|
|
35
|
+
import { Box, Text, useVirtualScroll } from "@alchemy.run/sigil";
|
|
36
|
+
|
|
37
|
+
const Example = ({ lines, cursor }: { lines: string[]; cursor: number }) => {
|
|
38
|
+
const { start, end, offset, hiddenAbove, hiddenBelow } = useVirtualScroll({
|
|
39
|
+
count: lines.length,
|
|
40
|
+
itemHeight: () => 1,
|
|
41
|
+
viewportHeight: 10,
|
|
42
|
+
focusedIndex: cursor,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Box flexDirection="column">
|
|
47
|
+
<Text dimColor>{hiddenAbove > 0 ? `↑ ${hiddenAbove} more` : ""}</Text>
|
|
48
|
+
<Box flexDirection="column" height={10} overflowY="hidden">
|
|
49
|
+
<Box flexDirection="column" flexShrink={0} marginTop={offset}>
|
|
50
|
+
{lines.slice(start, end).map((line, index) => (
|
|
51
|
+
<Text key={start + index} inverse={start + index === cursor}>
|
|
52
|
+
{line}
|
|
53
|
+
</Text>
|
|
54
|
+
))}
|
|
55
|
+
</Box>
|
|
56
|
+
</Box>
|
|
57
|
+
<Text dimColor>{hiddenBelow > 0 ? `↓ ${hiddenBelow} more` : ""}</Text>
|
|
58
|
+
</Box>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
*/
|
|
63
|
+
export const useVirtualScroll = (options: UseVirtualScrollOptions): UseVirtualScrollResult => {
|
|
64
|
+
const [position, setPosition] = useState(0);
|
|
65
|
+
const window = virtualScrollWindow({ ...options, scrollTop: position });
|
|
66
|
+
|
|
67
|
+
// Persist clamping and follow-focus corrections so the next scroll starts
|
|
68
|
+
// from where the viewport actually is, not from the stale request.
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (window.scrollTop !== position) {
|
|
71
|
+
setPosition(window.scrollTop);
|
|
72
|
+
}
|
|
73
|
+
}, [window.scrollTop, position]);
|
|
74
|
+
|
|
75
|
+
const scrollTo = useCallback((top: number) => {
|
|
76
|
+
setPosition(top);
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
79
|
+
const scrollBy = useCallback((delta: number) => {
|
|
80
|
+
setPosition((current) => current + delta);
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
return { ...window, scrollTo, scrollBy };
|
|
84
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useMemo, useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
import { getCapabilities } from "#/capabilities/store.ts";
|
|
4
|
+
import { useStdinContext } from "#/hooks/use-stdin.ts";
|
|
5
|
+
import { useStdout } from "#/hooks/use-stdout.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Dimensions of the terminal window.
|
|
9
|
+
*/
|
|
10
|
+
export type WindowSize = {
|
|
11
|
+
/**
|
|
12
|
+
Number of columns (horizontal character cells).
|
|
13
|
+
*/
|
|
14
|
+
readonly columns: number;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
Number of rows (vertical character cells).
|
|
18
|
+
*/
|
|
19
|
+
readonly rows: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
A React hook that returns the current terminal window dimensions and re-renders the component whenever the terminal is resized.
|
|
24
|
+
|
|
25
|
+
Reads the capabilities store, so on terminals that send in-band size reports
|
|
26
|
+
(mode 2048) the dimensions are the emulator's own, arriving after it has
|
|
27
|
+
rewrapped its screen; elsewhere they are the stream's `columns`/`rows`.
|
|
28
|
+
Subscribing to dimensions does not initiate capability queries. In-band reports
|
|
29
|
+
are used when another consumer has explicitly enabled capability discovery.
|
|
30
|
+
*/
|
|
31
|
+
export const useWindowSize = (): WindowSize => {
|
|
32
|
+
const { stdin } = useStdinContext();
|
|
33
|
+
const { stdout } = useStdout();
|
|
34
|
+
const store = getCapabilities(stdin, stdout);
|
|
35
|
+
const { size } = useSyncExternalStore(store.subscribe, () => store.current);
|
|
36
|
+
return useMemo(() => ({ columns: size.columns, rows: size.rows }), [size.columns, size.rows]);
|
|
37
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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 AnsiTextProps } from "#/components/AnsiText.tsx";
|
|
11
|
+
export { AnsiText } from "#/components/AnsiText.tsx";
|
|
12
|
+
export type { Props as AppProps } from "#/components/AppContext.ts";
|
|
13
|
+
export type { PublicProps as StdinProps } from "#/components/StdinContext.ts";
|
|
14
|
+
export type { Props as StdoutProps } from "#/components/StdoutContext.ts";
|
|
15
|
+
export type { Props as StderrProps } from "#/components/StderrContext.ts";
|
|
16
|
+
export type { Props as StaticProps } from "#/components/Static.tsx";
|
|
17
|
+
export { Static } from "#/components/Static.tsx";
|
|
18
|
+
export type { Props as TransformProps } from "#/components/Transform.tsx";
|
|
19
|
+
export { Transform } from "#/components/Transform.tsx";
|
|
20
|
+
export type { Props as HyperlinkProps } from "#/components/Hyperlink.tsx";
|
|
21
|
+
export { Hyperlink } from "#/components/Hyperlink.tsx";
|
|
22
|
+
export type { Props as NewlineProps } from "#/components/Newline.tsx";
|
|
23
|
+
export { Newline } from "#/components/Newline.tsx";
|
|
24
|
+
export { Spacer } from "#/components/Spacer.tsx";
|
|
25
|
+
export type { Props as VirtualListProps } from "#/components/VirtualList.tsx";
|
|
26
|
+
export { VirtualList } from "#/components/VirtualList.tsx";
|
|
27
|
+
// Keep the Ink-compatible root surface fixed. New terminal-core APIs live on
|
|
28
|
+
// their focused subpaths rather than leaking through this entry point.
|
|
29
|
+
export type {
|
|
30
|
+
Capabilities,
|
|
31
|
+
ColorInfo,
|
|
32
|
+
ColorSupport,
|
|
33
|
+
ColorSupportLevel,
|
|
34
|
+
Multiplexer,
|
|
35
|
+
PixelGeometry,
|
|
36
|
+
RgbColor,
|
|
37
|
+
TerminalAppearance,
|
|
38
|
+
TerminalIdentity,
|
|
39
|
+
} from "#/capabilities/detect.ts";
|
|
40
|
+
export {
|
|
41
|
+
createSupportsColor,
|
|
42
|
+
detectCapabilities,
|
|
43
|
+
detectColorLevel,
|
|
44
|
+
detectHyperlinkSupport,
|
|
45
|
+
detectTerminal,
|
|
46
|
+
detectUnicodeSupport,
|
|
47
|
+
} from "#/capabilities/detect.ts";
|
|
48
|
+
export type { PixelSize, TerminalQueryOptions, TerminalQueryResult } from "#/capabilities/query.ts";
|
|
49
|
+
export {
|
|
50
|
+
applyTerminalQuery,
|
|
51
|
+
getTerminalQuery,
|
|
52
|
+
queryTerminal,
|
|
53
|
+
refreshTerminalQuery,
|
|
54
|
+
} from "#/capabilities/query.ts";
|
|
55
|
+
export type { CapabilitiesStore } from "#/capabilities/store.ts";
|
|
56
|
+
export { capabilities, getCapabilities } from "#/capabilities/store.ts";
|
|
57
|
+
export { useCapabilities, useCapabilitiesChange } from "#/hooks/use-capabilities.ts";
|
|
58
|
+
export type { Key } from "#/hooks/use-input.ts";
|
|
59
|
+
export { useInput } from "#/hooks/use-input.ts";
|
|
60
|
+
export { usePaste } from "#/hooks/use-paste.ts";
|
|
61
|
+
export type { SuspendTerminal, TerminalSuspension } from "#/components/AppContext.ts";
|
|
62
|
+
export { useApp } from "#/hooks/use-app.ts";
|
|
63
|
+
export { useStdin } from "#/hooks/use-stdin.ts";
|
|
64
|
+
export { useStdout } from "#/hooks/use-stdout.ts";
|
|
65
|
+
export { useStderr } from "#/hooks/use-stderr.ts";
|
|
66
|
+
export { useFocus } from "#/hooks/use-focus.ts";
|
|
67
|
+
export { useFocusManager } from "#/hooks/use-focus-manager.ts";
|
|
68
|
+
export { useIsScreenReaderEnabled } from "#/hooks/use-is-screen-reader-enabled.ts";
|
|
69
|
+
export { useCursor } from "#/hooks/use-cursor.ts";
|
|
70
|
+
export type { AnimationResult } from "#/hooks/use-animation.ts";
|
|
71
|
+
export { useAnimation } from "#/hooks/use-animation.ts";
|
|
72
|
+
export type { ProgressOptions } from "#/hooks/use-terminal-osc.ts";
|
|
73
|
+
export {
|
|
74
|
+
useClipboard,
|
|
75
|
+
useNotification,
|
|
76
|
+
usePointerShape,
|
|
77
|
+
useProgress,
|
|
78
|
+
useTitle,
|
|
79
|
+
useWorkingDirectory,
|
|
80
|
+
} from "#/hooks/use-terminal-osc.ts";
|
|
81
|
+
export type { WindowSize } from "#/hooks/use-window-size.ts";
|
|
82
|
+
export { useWindowSize } from "#/hooks/use-window-size.ts";
|
|
83
|
+
export type { BoxMetrics, UseBoxMetricsResult } from "#/hooks/use-box-metrics.ts";
|
|
84
|
+
export { useBoxMetrics } from "#/hooks/use-box-metrics.ts";
|
|
85
|
+
export type { VirtualScrollWindow } from "#/virtual-scroll.ts";
|
|
86
|
+
export type {
|
|
87
|
+
UseVirtualScrollOptions,
|
|
88
|
+
UseVirtualScrollResult,
|
|
89
|
+
} from "#/hooks/use-virtual-scroll.ts";
|
|
90
|
+
export { useVirtualScroll } from "#/hooks/use-virtual-scroll.ts";
|
|
91
|
+
export type { CursorPosition } from "#/cursor-position.ts";
|
|
92
|
+
export { measureElement } from "#/measure-element.ts";
|
|
93
|
+
export type { ElementMetrics } from "#/measure-element.ts";
|
|
94
|
+
export type { DOMElement } from "#/dom.ts";
|
|
95
|
+
export { kittyFlags, kittyModifiers } from "#/kitty-keyboard.ts";
|
|
96
|
+
export type { KittyKeyboardOptions, KittyFlagName } from "#/kitty-keyboard.ts";
|