@kingkoo1985/ink 6.6.6
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/colorize.d.ts +4 -0
- package/build/colorize.js +59 -0
- package/build/colorize.js.map +1 -0
- package/build/components/AccessibilityContext.d.ts +3 -0
- package/build/components/AccessibilityContext.js +5 -0
- package/build/components/AccessibilityContext.js.map +1 -0
- package/build/components/App.d.ts +68 -0
- package/build/components/App.js +290 -0
- package/build/components/App.js.map +1 -0
- package/build/components/AppContext.d.ts +52 -0
- package/build/components/AppContext.js +16 -0
- package/build/components/AppContext.js.map +1 -0
- package/build/components/BackgroundContext.d.ts +4 -0
- package/build/components/BackgroundContext.js +3 -0
- package/build/components/BackgroundContext.js.map +1 -0
- package/build/components/Box.d.ts +171 -0
- package/build/components/Box.js +40 -0
- package/build/components/Box.js.map +1 -0
- package/build/components/ErrorOverview.d.ts +6 -0
- package/build/components/ErrorOverview.js +84 -0
- package/build/components/ErrorOverview.js.map +1 -0
- package/build/components/FocusContext.d.ts +16 -0
- package/build/components/FocusContext.js +16 -0
- package/build/components/FocusContext.js.map +1 -0
- package/build/components/Newline.d.ts +13 -0
- package/build/components/Newline.js +8 -0
- package/build/components/Newline.js.map +1 -0
- package/build/components/Spacer.d.ts +7 -0
- package/build/components/Spacer.js +11 -0
- package/build/components/Spacer.js.map +1 -0
- package/build/components/Static.d.ts +24 -0
- package/build/components/Static.js +29 -0
- package/build/components/Static.js.map +1 -0
- package/build/components/StaticRender.d.ts +8 -0
- package/build/components/StaticRender.js +19 -0
- package/build/components/StaticRender.js.map +1 -0
- package/build/components/StderrContext.d.ts +15 -0
- package/build/components/StderrContext.js +12 -0
- package/build/components/StderrContext.js.map +1 -0
- package/build/components/StdinContext.d.ts +22 -0
- package/build/components/StdinContext.js +16 -0
- package/build/components/StdinContext.js.map +1 -0
- package/build/components/StdoutContext.d.ts +15 -0
- package/build/components/StdoutContext.js +12 -0
- package/build/components/StdoutContext.js.map +1 -0
- package/build/components/Text.d.ts +63 -0
- package/build/components/Text.js +50 -0
- package/build/components/Text.js.map +1 -0
- package/build/components/Transform.d.ts +16 -0
- package/build/components/Transform.js +15 -0
- package/build/components/Transform.js.map +1 -0
- package/build/data-limited-lru-map.d.ts +20 -0
- package/build/data-limited-lru-map.js +65 -0
- package/build/data-limited-lru-map.js.map +1 -0
- package/build/debug-log.d.ts +2 -0
- package/build/debug-log.js +44 -0
- package/build/debug-log.js.map +1 -0
- package/build/devtools-window-polyfill.d.ts +1 -0
- package/build/devtools-window-polyfill.js +65 -0
- package/build/devtools-window-polyfill.js.map +1 -0
- package/build/devtools.d.ts +1 -0
- package/build/devtools.js +8 -0
- package/build/devtools.js.map +1 -0
- package/build/dom.d.ts +114 -0
- package/build/dom.js +169 -0
- package/build/dom.js.map +1 -0
- package/build/get-max-width.d.ts +3 -0
- package/build/get-max-width.js +10 -0
- package/build/get-max-width.js.map +1 -0
- package/build/hooks/use-app.d.ts +5 -0
- package/build/hooks/use-app.js +8 -0
- package/build/hooks/use-app.js.map +1 -0
- package/build/hooks/use-focus-manager.d.ts +28 -0
- package/build/hooks/use-focus-manager.js +17 -0
- package/build/hooks/use-focus-manager.js.map +1 -0
- package/build/hooks/use-focus.d.ts +29 -0
- package/build/hooks/use-focus.js +42 -0
- package/build/hooks/use-focus.js.map +1 -0
- package/build/hooks/use-input.d.ts +93 -0
- package/build/hooks/use-input.js +92 -0
- package/build/hooks/use-input.js.map +1 -0
- package/build/hooks/use-is-screen-reader-enabled.d.ts +5 -0
- package/build/hooks/use-is-screen-reader-enabled.js +11 -0
- package/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
- package/build/hooks/use-stderr.d.ts +5 -0
- package/build/hooks/use-stderr.js +8 -0
- package/build/hooks/use-stderr.js.map +1 -0
- package/build/hooks/use-stdin.d.ts +5 -0
- package/build/hooks/use-stdin.js +8 -0
- package/build/hooks/use-stdin.js.map +1 -0
- package/build/hooks/use-stdout.d.ts +5 -0
- package/build/hooks/use-stdout.js +8 -0
- package/build/hooks/use-stdout.js.map +1 -0
- package/build/index.d.ts +38 -0
- package/build/index.js +27 -0
- package/build/index.js.map +1 -0
- package/build/ink.d.ts +110 -0
- package/build/ink.js +576 -0
- package/build/ink.js.map +1 -0
- package/build/instances.d.ts +3 -0
- package/build/instances.js +8 -0
- package/build/instances.js.map +1 -0
- package/build/layout.d.ts +18 -0
- package/build/layout.js +54 -0
- package/build/layout.js.map +1 -0
- package/build/log-update.d.ts +28 -0
- package/build/log-update.js +529 -0
- package/build/log-update.js.map +1 -0
- package/build/measure-element.d.ts +119 -0
- package/build/measure-element.js +825 -0
- package/build/measure-element.js.map +1 -0
- package/build/measure-text.d.ts +50 -0
- package/build/measure-text.js +237 -0
- package/build/measure-text.js.map +1 -0
- package/build/output.d.ts +242 -0
- package/build/output.js +607 -0
- package/build/output.js.map +1 -0
- package/build/parse-keypress.d.ts +14 -0
- package/build/parse-keypress.js +225 -0
- package/build/parse-keypress.js.map +1 -0
- package/build/reconciler.d.ts +4 -0
- package/build/reconciler.js +326 -0
- package/build/reconciler.js.map +1 -0
- package/build/render-background.d.ts +4 -0
- package/build/render-background.js +37 -0
- package/build/render-background.js.map +1 -0
- package/build/render-border.d.ts +4 -0
- package/build/render-border.js +81 -0
- package/build/render-border.js.map +1 -0
- package/build/render-cached.d.ts +18 -0
- package/build/render-cached.js +66 -0
- package/build/render-cached.js.map +1 -0
- package/build/render-container.d.ts +27 -0
- package/build/render-container.js +169 -0
- package/build/render-container.js.map +1 -0
- package/build/render-node-to-output.d.ts +32 -0
- package/build/render-node-to-output.js +177 -0
- package/build/render-node-to-output.js.map +1 -0
- package/build/render-screen-reader.d.ts +5 -0
- package/build/render-screen-reader.js +54 -0
- package/build/render-screen-reader.js.map +1 -0
- package/build/render-scrollbar.d.ts +23 -0
- package/build/render-scrollbar.js +70 -0
- package/build/render-scrollbar.js.map +1 -0
- package/build/render-sticky.d.ts +53 -0
- package/build/render-sticky.js +317 -0
- package/build/render-sticky.js.map +1 -0
- package/build/render-text-node.d.ts +20 -0
- package/build/render-text-node.js +155 -0
- package/build/render-text-node.js.map +1 -0
- package/build/render.d.ts +165 -0
- package/build/render.js +60 -0
- package/build/render.js.map +1 -0
- package/build/renderer.d.ts +24 -0
- package/build/renderer.js +292 -0
- package/build/renderer.js.map +1 -0
- package/build/replay.d.ts +59 -0
- package/build/replay.js +128 -0
- package/build/replay.js.map +1 -0
- package/build/resize-observer.d.ts +24 -0
- package/build/resize-observer.js +102 -0
- package/build/resize-observer.js.map +1 -0
- package/build/scroll.d.ts +11 -0
- package/build/scroll.js +123 -0
- package/build/scroll.js.map +1 -0
- package/build/selection.d.ts +52 -0
- package/build/selection.js +359 -0
- package/build/selection.js.map +1 -0
- package/build/serialization.d.ts +25 -0
- package/build/serialization.js +224 -0
- package/build/serialization.js.map +1 -0
- package/build/squash-text-nodes.d.ts +16 -0
- package/build/squash-text-nodes.js +58 -0
- package/build/squash-text-nodes.js.map +1 -0
- package/build/styled-line.d.ts +58 -0
- package/build/styled-line.js +629 -0
- package/build/styled-line.js.map +1 -0
- package/build/styles.d.ts +286 -0
- package/build/styles.js +257 -0
- package/build/styles.js.map +1 -0
- package/build/terminal-buffer.d.ts +57 -0
- package/build/terminal-buffer.js +507 -0
- package/build/terminal-buffer.js.map +1 -0
- package/build/text-wrap.d.ts +12 -0
- package/build/text-wrap.js +154 -0
- package/build/text-wrap.js.map +1 -0
- package/build/tokenize.d.ts +47 -0
- package/build/tokenize.js +419 -0
- package/build/tokenize.js.map +1 -0
- package/build/vertical-gap.d.ts +17 -0
- package/build/vertical-gap.js +20 -0
- package/build/vertical-gap.js.map +1 -0
- package/build/worker/animation-controller.d.ts +72 -0
- package/build/worker/animation-controller.js +128 -0
- package/build/worker/animation-controller.js.map +1 -0
- package/build/worker/ansi-utils.d.ts +16 -0
- package/build/worker/ansi-utils.js +40 -0
- package/build/worker/ansi-utils.js.map +1 -0
- package/build/worker/canvas.d.ts +49 -0
- package/build/worker/canvas.js +90 -0
- package/build/worker/canvas.js.map +1 -0
- package/build/worker/compositor.d.ts +33 -0
- package/build/worker/compositor.js +308 -0
- package/build/worker/compositor.js.map +1 -0
- package/build/worker/platform.d.ts +15 -0
- package/build/worker/platform.js +19 -0
- package/build/worker/platform.js.map +1 -0
- package/build/worker/render-worker.d.ts +112 -0
- package/build/worker/render-worker.js +944 -0
- package/build/worker/render-worker.js.map +1 -0
- package/build/worker/scene-manager.d.ts +26 -0
- package/build/worker/scene-manager.js +109 -0
- package/build/worker/scene-manager.js.map +1 -0
- package/build/worker/scroll-optimizer.d.ts +32 -0
- package/build/worker/scroll-optimizer.js +110 -0
- package/build/worker/scroll-optimizer.js.map +1 -0
- package/build/worker/terminal-writer.d.ts +116 -0
- package/build/worker/terminal-writer.js +708 -0
- package/build/worker/terminal-writer.js.map +1 -0
- package/build/worker/worker-entry.d.ts +6 -0
- package/build/worker/worker-entry.js +130 -0
- package/build/worker/worker-entry.js.map +1 -0
- package/license +9 -0
- package/package.json +208 -0
- package/readme.md +2353 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
const rgbRegex = /^rgb\(\s?(\d+),\s?(\d+),\s?(\d+)\s?\)$/;
|
|
3
|
+
const ansiRegex = /^ansi256\(\s?(\d+)\s?\)$/;
|
|
4
|
+
const isNamedColor = (color) => {
|
|
5
|
+
return color in chalk;
|
|
6
|
+
};
|
|
7
|
+
const colorize = (str, color, type) => {
|
|
8
|
+
if (!color) {
|
|
9
|
+
return str;
|
|
10
|
+
}
|
|
11
|
+
if (isNamedColor(color)) {
|
|
12
|
+
if (type === 'foreground') {
|
|
13
|
+
return chalk[color](str);
|
|
14
|
+
}
|
|
15
|
+
const methodName = `bg${color[0].toUpperCase() + color.slice(1)}`;
|
|
16
|
+
return chalk[methodName](str);
|
|
17
|
+
}
|
|
18
|
+
if (color.startsWith('#')) {
|
|
19
|
+
return type === 'foreground'
|
|
20
|
+
? chalk.hex(color)(str)
|
|
21
|
+
: chalk.bgHex(color)(str);
|
|
22
|
+
}
|
|
23
|
+
if (color.startsWith('ansi256')) {
|
|
24
|
+
const matches = ansiRegex.exec(color);
|
|
25
|
+
if (!matches) {
|
|
26
|
+
return str;
|
|
27
|
+
}
|
|
28
|
+
const value = Number(matches[1]);
|
|
29
|
+
return type === 'foreground'
|
|
30
|
+
? chalk.ansi256(value)(str)
|
|
31
|
+
: chalk.bgAnsi256(value)(str);
|
|
32
|
+
}
|
|
33
|
+
if (color.startsWith('rgb')) {
|
|
34
|
+
const matches = rgbRegex.exec(color);
|
|
35
|
+
if (!matches) {
|
|
36
|
+
return str;
|
|
37
|
+
}
|
|
38
|
+
const firstValue = Number(matches[1]);
|
|
39
|
+
const secondValue = Number(matches[2]);
|
|
40
|
+
const thirdValue = Number(matches[3]);
|
|
41
|
+
return type === 'foreground'
|
|
42
|
+
? chalk.rgb(firstValue, secondValue, thirdValue)(str)
|
|
43
|
+
: chalk.bgRgb(firstValue, secondValue, thirdValue)(str);
|
|
44
|
+
}
|
|
45
|
+
return str;
|
|
46
|
+
};
|
|
47
|
+
export const getBackgroundColorEscape = (color) => {
|
|
48
|
+
// Chalk automatically downgrades colors based on terminal support.
|
|
49
|
+
// Since Chalk doesn't expose the raw escape codes directly without
|
|
50
|
+
// applying them to a string, we colorize a dummy character and extract
|
|
51
|
+
// the generated ANSI escape prefix.
|
|
52
|
+
const colorized = colorize('x', color, 'background');
|
|
53
|
+
if (colorized !== 'x') {
|
|
54
|
+
return colorized.split('x')[0];
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
};
|
|
58
|
+
export default colorize;
|
|
59
|
+
//# sourceMappingURL=colorize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorize.js","sourceRoot":"","sources":["../src/colorize.ts"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAIhF,MAAM,QAAQ,GAAG,wCAAwC,CAAC;AAC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|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccessibilityContext.js","sourceRoot":"","sources":["../../src/components/AccessibilityContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;IACjD,qBAAqB,EAAE,KAAK;CAC5B,CAAC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import React, { PureComponent, type ReactNode } from 'react';
|
|
3
|
+
import { type Selection } from '../selection.js';
|
|
4
|
+
import { type InkOptions } from './AppContext.js';
|
|
5
|
+
type Props = {
|
|
6
|
+
readonly children: ReactNode;
|
|
7
|
+
readonly stdin: NodeJS.ReadStream;
|
|
8
|
+
readonly stdout: NodeJS.WriteStream;
|
|
9
|
+
readonly stderr: NodeJS.WriteStream;
|
|
10
|
+
readonly writeToStdout: (data: string) => void;
|
|
11
|
+
readonly writeToStderr: (data: string) => void;
|
|
12
|
+
readonly exitOnCtrlC: boolean;
|
|
13
|
+
readonly onExit: (error?: Error) => void;
|
|
14
|
+
readonly onRerender: () => void;
|
|
15
|
+
readonly selection?: Selection;
|
|
16
|
+
readonly options: InkOptions;
|
|
17
|
+
readonly setOptions: (options: Partial<InkOptions>) => void;
|
|
18
|
+
readonly dumpCurrentFrame: (filename: string) => void;
|
|
19
|
+
readonly startRecording: (filename: string) => void;
|
|
20
|
+
readonly stopRecording: () => void;
|
|
21
|
+
};
|
|
22
|
+
type State = {
|
|
23
|
+
readonly isFocusEnabled: boolean;
|
|
24
|
+
readonly activeFocusId?: string;
|
|
25
|
+
readonly focusables: Focusable[];
|
|
26
|
+
readonly error?: Error;
|
|
27
|
+
};
|
|
28
|
+
type Focusable = {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly isActive: boolean;
|
|
31
|
+
};
|
|
32
|
+
export default class App extends PureComponent<Props, State> {
|
|
33
|
+
static displayName: string;
|
|
34
|
+
static getDerivedStateFromError(error: Error): {
|
|
35
|
+
error: Error;
|
|
36
|
+
};
|
|
37
|
+
state: {
|
|
38
|
+
isFocusEnabled: boolean;
|
|
39
|
+
activeFocusId: undefined;
|
|
40
|
+
focusables: never[];
|
|
41
|
+
error: undefined;
|
|
42
|
+
};
|
|
43
|
+
rawModeEnabledCount: number;
|
|
44
|
+
internal_eventEmitter: EventEmitter<[never]>;
|
|
45
|
+
isRawModeSupported(): boolean;
|
|
46
|
+
render(): React.JSX.Element;
|
|
47
|
+
componentDidMount(): void;
|
|
48
|
+
componentWillUnmount(): void;
|
|
49
|
+
componentDidCatch(error: Error): void;
|
|
50
|
+
handleSetRawMode: (isEnabled: boolean) => void;
|
|
51
|
+
handleReadable: () => void;
|
|
52
|
+
handleInput: (input: string) => void;
|
|
53
|
+
handleExit: (error?: Error) => void;
|
|
54
|
+
enableFocus: () => void;
|
|
55
|
+
disableFocus: () => void;
|
|
56
|
+
focus: (id: string) => void;
|
|
57
|
+
focusNext: () => void;
|
|
58
|
+
focusPrevious: () => void;
|
|
59
|
+
addFocusable: (id: string, { autoFocus }: {
|
|
60
|
+
autoFocus: boolean;
|
|
61
|
+
}) => void;
|
|
62
|
+
removeFocusable: (id: string) => void;
|
|
63
|
+
activateFocusable: (id: string) => void;
|
|
64
|
+
deactivateFocusable: (id: string) => void;
|
|
65
|
+
findNextFocusable: (state: State) => string | undefined;
|
|
66
|
+
findPreviousFocusable: (state: State) => string | undefined;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import React, { PureComponent } from 'react';
|
|
4
|
+
import cliCursor from 'cli-cursor';
|
|
5
|
+
import AppContext from './AppContext.js';
|
|
6
|
+
import StdinContext from './StdinContext.js';
|
|
7
|
+
import StdoutContext from './StdoutContext.js';
|
|
8
|
+
import StderrContext from './StderrContext.js';
|
|
9
|
+
import FocusContext from './FocusContext.js';
|
|
10
|
+
import ErrorOverview from './ErrorOverview.js';
|
|
11
|
+
const tab = '\t';
|
|
12
|
+
const shiftTab = '\u001B[Z';
|
|
13
|
+
const escape = '\u001B';
|
|
14
|
+
// Root component for all Ink apps
|
|
15
|
+
// It renders stdin and stdout contexts, so that children can access them if needed
|
|
16
|
+
// It also handles Ctrl+C exiting and cursor visibility
|
|
17
|
+
export default class App extends PureComponent {
|
|
18
|
+
static displayName = 'InternalApp';
|
|
19
|
+
static getDerivedStateFromError(error) {
|
|
20
|
+
return { error };
|
|
21
|
+
}
|
|
22
|
+
state = {
|
|
23
|
+
isFocusEnabled: true,
|
|
24
|
+
activeFocusId: undefined,
|
|
25
|
+
focusables: [],
|
|
26
|
+
error: undefined,
|
|
27
|
+
};
|
|
28
|
+
// Count how many components enabled raw mode to avoid disabling
|
|
29
|
+
// raw mode until all components don't need it anymore
|
|
30
|
+
rawModeEnabledCount = 0;
|
|
31
|
+
internal_eventEmitter = new EventEmitter();
|
|
32
|
+
// Determines if TTY is supported on the provided stdin
|
|
33
|
+
isRawModeSupported() {
|
|
34
|
+
return this.props.stdin.isTTY;
|
|
35
|
+
}
|
|
36
|
+
render() {
|
|
37
|
+
return (React.createElement(AppContext.Provider
|
|
38
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
39
|
+
, {
|
|
40
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
41
|
+
value: {
|
|
42
|
+
exit: this.handleExit,
|
|
43
|
+
rerender: this.props.onRerender,
|
|
44
|
+
selection: this.props.selection,
|
|
45
|
+
options: this.props.options,
|
|
46
|
+
setOptions: this.props.setOptions,
|
|
47
|
+
dumpCurrentFrame: this.props.dumpCurrentFrame,
|
|
48
|
+
startRecording: this.props.startRecording,
|
|
49
|
+
stopRecording: this.props.stopRecording,
|
|
50
|
+
} },
|
|
51
|
+
React.createElement(StdinContext.Provider
|
|
52
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
53
|
+
, {
|
|
54
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
55
|
+
value: {
|
|
56
|
+
stdin: this.props.stdin,
|
|
57
|
+
setRawMode: this.handleSetRawMode,
|
|
58
|
+
isRawModeSupported: this.isRawModeSupported(),
|
|
59
|
+
internal_exitOnCtrlC: this.props.exitOnCtrlC,
|
|
60
|
+
internal_eventEmitter: this.internal_eventEmitter,
|
|
61
|
+
} },
|
|
62
|
+
React.createElement(StdoutContext.Provider
|
|
63
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
64
|
+
, {
|
|
65
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
66
|
+
value: {
|
|
67
|
+
stdout: this.props.stdout,
|
|
68
|
+
write: this.props.writeToStdout,
|
|
69
|
+
} },
|
|
70
|
+
React.createElement(StderrContext.Provider
|
|
71
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
72
|
+
, {
|
|
73
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
74
|
+
value: {
|
|
75
|
+
stderr: this.props.stderr,
|
|
76
|
+
write: this.props.writeToStderr,
|
|
77
|
+
} },
|
|
78
|
+
React.createElement(FocusContext.Provider
|
|
79
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
80
|
+
, {
|
|
81
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
82
|
+
value: {
|
|
83
|
+
activeId: this.state.activeFocusId,
|
|
84
|
+
add: this.addFocusable,
|
|
85
|
+
remove: this.removeFocusable,
|
|
86
|
+
activate: this.activateFocusable,
|
|
87
|
+
deactivate: this.deactivateFocusable,
|
|
88
|
+
enableFocus: this.enableFocus,
|
|
89
|
+
disableFocus: this.disableFocus,
|
|
90
|
+
focusNext: this.focusNext,
|
|
91
|
+
focusPrevious: this.focusPrevious,
|
|
92
|
+
focus: this.focus,
|
|
93
|
+
} }, this.state.error ? (React.createElement(ErrorOverview, { error: this.state.error })) : (this.props.children)))))));
|
|
94
|
+
}
|
|
95
|
+
componentDidMount() {
|
|
96
|
+
cliCursor.hide(this.props.stdout);
|
|
97
|
+
}
|
|
98
|
+
componentWillUnmount() {
|
|
99
|
+
cliCursor.show(this.props.stdout);
|
|
100
|
+
// ignore calling setRawMode on an handle stdin it cannot be called
|
|
101
|
+
if (this.isRawModeSupported()) {
|
|
102
|
+
this.handleSetRawMode(false);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
componentDidCatch(error) {
|
|
106
|
+
this.handleExit(error);
|
|
107
|
+
}
|
|
108
|
+
handleSetRawMode = (isEnabled) => {
|
|
109
|
+
const { stdin } = this.props;
|
|
110
|
+
if (!this.isRawModeSupported()) {
|
|
111
|
+
if (stdin === process.stdin) {
|
|
112
|
+
throw new Error('Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.\nRead about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
throw new Error('Raw mode is not supported on the stdin provided to Ink.\nRead about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
stdin.setEncoding('utf8');
|
|
119
|
+
if (isEnabled) {
|
|
120
|
+
// Ensure raw mode is enabled only once
|
|
121
|
+
if (this.rawModeEnabledCount === 0) {
|
|
122
|
+
stdin.ref();
|
|
123
|
+
stdin.setRawMode(true);
|
|
124
|
+
stdin.addListener('readable', this.handleReadable);
|
|
125
|
+
}
|
|
126
|
+
this.rawModeEnabledCount++;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// Disable raw mode only when no components left that are using it
|
|
130
|
+
if (--this.rawModeEnabledCount === 0) {
|
|
131
|
+
stdin.setRawMode(false);
|
|
132
|
+
stdin.removeListener('readable', this.handleReadable);
|
|
133
|
+
stdin.unref();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
handleReadable = () => {
|
|
137
|
+
let chunk;
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
139
|
+
while ((chunk = this.props.stdin.read()) !== null) {
|
|
140
|
+
this.handleInput(chunk);
|
|
141
|
+
this.internal_eventEmitter.emit('input', chunk);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
handleInput = (input) => {
|
|
145
|
+
// Exit on Ctrl+C
|
|
146
|
+
// eslint-disable-next-line unicorn/no-hex-escape
|
|
147
|
+
if (input.includes('\x03') && this.props.exitOnCtrlC) {
|
|
148
|
+
this.handleExit();
|
|
149
|
+
}
|
|
150
|
+
// Reset focus when there's an active focused component on Esc
|
|
151
|
+
if (input === escape && this.state.activeFocusId) {
|
|
152
|
+
this.setState({
|
|
153
|
+
activeFocusId: undefined,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (this.state.isFocusEnabled && this.state.focusables.length > 0) {
|
|
157
|
+
if (input === tab) {
|
|
158
|
+
this.focusNext();
|
|
159
|
+
}
|
|
160
|
+
if (input === shiftTab) {
|
|
161
|
+
this.focusPrevious();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
handleExit = (error) => {
|
|
166
|
+
if (this.isRawModeSupported()) {
|
|
167
|
+
this.handleSetRawMode(false);
|
|
168
|
+
}
|
|
169
|
+
this.props.onExit(error);
|
|
170
|
+
};
|
|
171
|
+
enableFocus = () => {
|
|
172
|
+
this.setState({
|
|
173
|
+
isFocusEnabled: true,
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
disableFocus = () => {
|
|
177
|
+
this.setState({
|
|
178
|
+
isFocusEnabled: false,
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
focus = (id) => {
|
|
182
|
+
this.setState(previousState => {
|
|
183
|
+
const hasFocusableId = previousState.focusables.some(focusable => focusable?.id === id);
|
|
184
|
+
if (!hasFocusableId) {
|
|
185
|
+
return previousState;
|
|
186
|
+
}
|
|
187
|
+
return { activeFocusId: id };
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
focusNext = () => {
|
|
191
|
+
this.setState(previousState => {
|
|
192
|
+
const firstFocusableId = previousState.focusables.find(focusable => focusable.isActive)?.id;
|
|
193
|
+
const nextFocusableId = this.findNextFocusable(previousState);
|
|
194
|
+
return {
|
|
195
|
+
activeFocusId: nextFocusableId ?? firstFocusableId,
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
focusPrevious = () => {
|
|
200
|
+
this.setState(previousState => {
|
|
201
|
+
const lastFocusableId = previousState.focusables.findLast(focusable => focusable.isActive)?.id;
|
|
202
|
+
const previousFocusableId = this.findPreviousFocusable(previousState);
|
|
203
|
+
return {
|
|
204
|
+
activeFocusId: previousFocusableId ?? lastFocusableId,
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
addFocusable = (id, { autoFocus }) => {
|
|
209
|
+
this.setState(previousState => {
|
|
210
|
+
let nextFocusId = previousState.activeFocusId;
|
|
211
|
+
if (!nextFocusId && autoFocus) {
|
|
212
|
+
nextFocusId = id;
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
activeFocusId: nextFocusId,
|
|
216
|
+
focusables: [
|
|
217
|
+
...previousState.focusables,
|
|
218
|
+
{
|
|
219
|
+
id,
|
|
220
|
+
isActive: true,
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
removeFocusable = (id) => {
|
|
227
|
+
this.setState(previousState => ({
|
|
228
|
+
activeFocusId: previousState.activeFocusId === id
|
|
229
|
+
? undefined
|
|
230
|
+
: previousState.activeFocusId,
|
|
231
|
+
focusables: previousState.focusables.filter(focusable => {
|
|
232
|
+
return focusable.id !== id;
|
|
233
|
+
}),
|
|
234
|
+
}));
|
|
235
|
+
};
|
|
236
|
+
activateFocusable = (id) => {
|
|
237
|
+
this.setState(previousState => ({
|
|
238
|
+
focusables: previousState.focusables.map(focusable => {
|
|
239
|
+
if (focusable.id !== id) {
|
|
240
|
+
return focusable;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
id,
|
|
244
|
+
isActive: true,
|
|
245
|
+
};
|
|
246
|
+
}),
|
|
247
|
+
}));
|
|
248
|
+
};
|
|
249
|
+
deactivateFocusable = (id) => {
|
|
250
|
+
this.setState(previousState => ({
|
|
251
|
+
activeFocusId: previousState.activeFocusId === id
|
|
252
|
+
? undefined
|
|
253
|
+
: previousState.activeFocusId,
|
|
254
|
+
focusables: previousState.focusables.map(focusable => {
|
|
255
|
+
if (focusable.id !== id) {
|
|
256
|
+
return focusable;
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
id,
|
|
260
|
+
isActive: false,
|
|
261
|
+
};
|
|
262
|
+
}),
|
|
263
|
+
}));
|
|
264
|
+
};
|
|
265
|
+
findNextFocusable = (state) => {
|
|
266
|
+
const activeIndex = state.focusables.findIndex(focusable => {
|
|
267
|
+
return focusable.id === state.activeFocusId;
|
|
268
|
+
});
|
|
269
|
+
for (let index = activeIndex + 1; index < state.focusables.length; index++) {
|
|
270
|
+
const focusable = state.focusables[index];
|
|
271
|
+
if (focusable?.isActive) {
|
|
272
|
+
return focusable.id;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return undefined;
|
|
276
|
+
};
|
|
277
|
+
findPreviousFocusable = (state) => {
|
|
278
|
+
const activeIndex = state.focusables.findIndex(focusable => {
|
|
279
|
+
return focusable.id === state.activeFocusId;
|
|
280
|
+
});
|
|
281
|
+
for (let index = activeIndex - 1; index >= 0; index--) {
|
|
282
|
+
const focusable = state.focusables[index];
|
|
283
|
+
if (focusable?.isActive) {
|
|
284
|
+
return focusable.id;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return undefined;
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=App.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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C,UAAU,CAAC,KAAK,CAAC,CAAC;YAE1C,IAAI,SAAS,EAAE,QAAQ,EAAE,CAAC;gBACzB,OAAO,SAAS,CAAC,EAAE,CAAC;YACrB,CAAC;QACF,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Selection } from '../selection.js';
|
|
2
|
+
export type InkOptions = {
|
|
3
|
+
readonly isAlternateBufferEnabled?: boolean;
|
|
4
|
+
readonly stickyHeadersInBackbuffer?: boolean;
|
|
5
|
+
readonly animatedScroll?: boolean;
|
|
6
|
+
readonly animationInterval?: number;
|
|
7
|
+
readonly backbufferUpdateDelay?: number;
|
|
8
|
+
readonly maxScrollbackLength?: number;
|
|
9
|
+
/**
|
|
10
|
+
* When set to true, Ink will attempt to force the terminal to scroll to the bottom
|
|
11
|
+
* when performing a full re-render (e.g. when the backbuffer is refreshed).
|
|
12
|
+
*
|
|
13
|
+
* Currently this is only supported in VS Code due to lack of robust APIs in other
|
|
14
|
+
* terminals to force scrolling to the bottom.
|
|
15
|
+
*/
|
|
16
|
+
readonly forceScrollToBottomOnBackbufferRefresh?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type Props = {
|
|
19
|
+
/**
|
|
20
|
+
Exit (unmount) the whole Ink app.
|
|
21
|
+
*/
|
|
22
|
+
readonly exit: (error?: Error) => void;
|
|
23
|
+
/**
|
|
24
|
+
Force a full rerender of the app, clearing the screen.
|
|
25
|
+
*/
|
|
26
|
+
readonly rerender: () => void;
|
|
27
|
+
readonly selection?: Selection;
|
|
28
|
+
readonly options: InkOptions;
|
|
29
|
+
readonly setOptions: (options: Partial<InkOptions>) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Exports the current internal rendering state to a JSON file and a human-readable text dump.
|
|
32
|
+
* Only supported when `terminalBuffer` is enabled.
|
|
33
|
+
* @param filename The path/name for the JSON file (e.g., 'snapshot.json').
|
|
34
|
+
*/
|
|
35
|
+
readonly dumpCurrentFrame: (filename: string) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Starts recording internal rendering states (frames) to a sequence.
|
|
38
|
+
* Only supported when `terminalBuffer` is enabled.
|
|
39
|
+
* @param filename The path/name for the JSON file where the sequence will be saved when stopped.
|
|
40
|
+
*/
|
|
41
|
+
readonly startRecording: (filename: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Stops recording and saves the collected frames to the filename specified in `startRecording`.
|
|
44
|
+
* Only supported when `terminalBuffer` is enabled.
|
|
45
|
+
*/
|
|
46
|
+
readonly stopRecording: () => void;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
`AppContext` is a React context that exposes a method to manually exit the app (unmount).
|
|
50
|
+
*/
|
|
51
|
+
export declare const AppContext: import("react").Context<Props>;
|
|
52
|
+
export default AppContext;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
`AppContext` is a React context that exposes a method to manually exit the app (unmount).
|
|
4
|
+
*/
|
|
5
|
+
export const AppContext = createContext({
|
|
6
|
+
exit() { },
|
|
7
|
+
rerender() { },
|
|
8
|
+
options: {},
|
|
9
|
+
setOptions() { },
|
|
10
|
+
dumpCurrentFrame() { },
|
|
11
|
+
startRecording() { },
|
|
12
|
+
stopRecording() { },
|
|
13
|
+
});
|
|
14
|
+
AppContext.displayName = 'AppContext';
|
|
15
|
+
export default AppContext;
|
|
16
|
+
//# sourceMappingURL=AppContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppContext.js","sourceRoot":"","sources":["../../src/components/AppContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAwDpC;;EAEE;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAQ;IAC9C,IAAI,KAAI,CAAC;IACT,QAAQ,KAAI,CAAC;IACb,OAAO,EAAE,EAAE;IACX,UAAU,KAAI,CAAC;IACf,gBAAgB,KAAI,CAAC;IACrB,cAAc,KAAI,CAAC;IACnB,aAAa,KAAI,CAAC;CAClB,CAAC,CAAC;AAEH,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC;AAEtC,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type LiteralUnion } from 'type-fest';
|
|
2
|
+
import { type ForegroundColorName } from 'ansi-styles';
|
|
3
|
+
export type BackgroundColor = LiteralUnion<ForegroundColorName, string>;
|
|
4
|
+
export declare const backgroundContext: import("react").Context<BackgroundColor | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BackgroundContext.js","sourceRoot":"","sources":["../../src/components/BackgroundContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAMpC,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAC7C,SAAS,CACT,CAAC"}
|