@jrichman/ink 6.3.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/build/colorize.d.ts +3 -0
- package/build/colorize.js +48 -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 +59 -0
- package/build/components/App.js +286 -0
- package/build/components/App.js.map +1 -0
- package/build/components/AppContext.d.ts +11 -0
- package/build/components/AppContext.js +11 -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 +122 -0
- package/build/components/Box.js +34 -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 +17 -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 +28 -0
- package/build/components/Static.js.map +1 -0
- package/build/components/StderrContext.d.ts +15 -0
- package/build/components/StderrContext.js +13 -0
- package/build/components/StderrContext.js.map +1 -0
- package/build/components/StdinContext.d.ts +22 -0
- package/build/components/StdinContext.js +19 -0
- package/build/components/StdinContext.js.map +1 -0
- package/build/components/StdoutContext.d.ts +15 -0
- package/build/components/StdoutContext.js +13 -0
- package/build/components/StdoutContext.js.map +1 -0
- package/build/components/Text.d.ts +55 -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/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 +2 -0
- package/build/devtools.js.map +1 -0
- package/build/dom.d.ts +62 -0
- package/build/dom.js +123 -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 +93 -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 +28 -0
- package/build/index.js +17 -0
- package/build/index.js.map +1 -0
- package/build/ink.d.ts +43 -0
- package/build/ink.js +315 -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/log-update.d.ts +15 -0
- package/build/log-update.js +109 -0
- package/build/log-update.js.map +1 -0
- package/build/measure-element.d.ts +38 -0
- package/build/measure-element.js +118 -0
- package/build/measure-element.js.map +1 -0
- package/build/measure-text.d.ts +6 -0
- package/build/measure-text.js +21 -0
- package/build/measure-text.js.map +1 -0
- package/build/output.d.ts +36 -0
- package/build/output.js +191 -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 +254 -0
- package/build/reconciler.js.map +1 -0
- package/build/render-background.d.ts +4 -0
- package/build/render-background.js +25 -0
- package/build/render-background.js.map +1 -0
- package/build/render-border.d.ts +4 -0
- package/build/render-border.js +73 -0
- package/build/render-border.js.map +1 -0
- package/build/render-node-to-output.d.ts +14 -0
- package/build/render-node-to-output.js +296 -0
- package/build/render-node-to-output.js.map +1 -0
- package/build/render.d.ts +87 -0
- package/build/render.js +50 -0
- package/build/render.js.map +1 -0
- package/build/renderer.d.ts +8 -0
- package/build/renderer.js +55 -0
- package/build/renderer.js.map +1 -0
- package/build/scroll.d.ts +8 -0
- package/build/scroll.js +35 -0
- package/build/scroll.js.map +1 -0
- package/build/squash-text-nodes.d.ts +3 -0
- package/build/squash-text-nodes.js +35 -0
- package/build/squash-text-nodes.js.map +1 -0
- package/build/styles.d.ts +260 -0
- package/build/styles.js +257 -0
- package/build/styles.js.map +1 -0
- package/build/wrap-text.d.ts +3 -0
- package/build/wrap-text.js +31 -0
- package/build/wrap-text.js.map +1 -0
- package/license +9 -0
- package/package.json +194 -0
- package/readme.md +2331 -0
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type { RenderOptions, Instance } from './render.js';
|
|
2
|
+
export { default as render } from './render.js';
|
|
3
|
+
export type { Props as BoxProps } from './components/Box.js';
|
|
4
|
+
export { default as Box } from './components/Box.js';
|
|
5
|
+
export type { Props as TextProps } from './components/Text.js';
|
|
6
|
+
export { default as Text } from './components/Text.js';
|
|
7
|
+
export type { Props as AppProps } from './components/AppContext.js';
|
|
8
|
+
export type { Props as StdinProps } from './components/StdinContext.js';
|
|
9
|
+
export type { Props as StdoutProps } from './components/StdoutContext.js';
|
|
10
|
+
export type { Props as StderrProps } from './components/StderrContext.js';
|
|
11
|
+
export type { Props as StaticProps } from './components/Static.js';
|
|
12
|
+
export { default as Static } from './components/Static.js';
|
|
13
|
+
export type { Props as TransformProps } from './components/Transform.js';
|
|
14
|
+
export { default as Transform } from './components/Transform.js';
|
|
15
|
+
export type { Props as NewlineProps } from './components/Newline.js';
|
|
16
|
+
export { default as Newline } from './components/Newline.js';
|
|
17
|
+
export { default as Spacer } from './components/Spacer.js';
|
|
18
|
+
export type { Key } from './hooks/use-input.js';
|
|
19
|
+
export { default as useInput } from './hooks/use-input.js';
|
|
20
|
+
export { default as useApp } from './hooks/use-app.js';
|
|
21
|
+
export { default as useStdin } from './hooks/use-stdin.js';
|
|
22
|
+
export { default as useStdout } from './hooks/use-stdout.js';
|
|
23
|
+
export { default as useStderr } from './hooks/use-stderr.js';
|
|
24
|
+
export { default as useFocus } from './hooks/use-focus.js';
|
|
25
|
+
export { default as useFocusManager } from './hooks/use-focus-manager.js';
|
|
26
|
+
export { default as useIsScreenReaderEnabled } from './hooks/use-is-screen-reader-enabled.js';
|
|
27
|
+
export { default as measureElement, getBoundingBox, getInnerWidth, getInnerHeight, getScrollHeight, getScrollWidth, } from './measure-element.js';
|
|
28
|
+
export type { DOMElement } from './dom.js';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { default as render } from './render.js';
|
|
2
|
+
export { default as Box } from './components/Box.js';
|
|
3
|
+
export { default as Text } from './components/Text.js';
|
|
4
|
+
export { default as Static } from './components/Static.js';
|
|
5
|
+
export { default as Transform } from './components/Transform.js';
|
|
6
|
+
export { default as Newline } from './components/Newline.js';
|
|
7
|
+
export { default as Spacer } from './components/Spacer.js';
|
|
8
|
+
export { default as useInput } from './hooks/use-input.js';
|
|
9
|
+
export { default as useApp } from './hooks/use-app.js';
|
|
10
|
+
export { default as useStdin } from './hooks/use-stdin.js';
|
|
11
|
+
export { default as useStdout } from './hooks/use-stdout.js';
|
|
12
|
+
export { default as useStderr } from './hooks/use-stderr.js';
|
|
13
|
+
export { default as useFocus } from './hooks/use-focus.js';
|
|
14
|
+
export { default as useFocusManager } from './hooks/use-focus-manager.js';
|
|
15
|
+
export { default as useIsScreenReaderEnabled } from './hooks/use-is-screen-reader-enabled.js';
|
|
16
|
+
export { default as measureElement, getBoundingBox, getInnerWidth, getInnerHeight, getScrollHeight, getScrollWidth, } from './measure-element.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAC,OAAO,IAAI,GAAG,EAAC,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAC,OAAO,IAAI,IAAI,EAAC,MAAM,sBAAsB,CAAC;AAMrD,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAC,OAAO,IAAI,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAC,OAAO,IAAI,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,OAAO,IAAI,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAC,OAAO,IAAI,wBAAwB,EAAC,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EACN,OAAO,IAAI,cAAc,EACzB,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,GACd,MAAM,sBAAsB,CAAC"}
|
package/build/ink.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export type Options = {
|
|
3
|
+
stdout: NodeJS.WriteStream;
|
|
4
|
+
stdin: NodeJS.ReadStream;
|
|
5
|
+
stderr: NodeJS.WriteStream;
|
|
6
|
+
debug: boolean;
|
|
7
|
+
exitOnCtrlC: boolean;
|
|
8
|
+
patchConsole: boolean;
|
|
9
|
+
onRender?: (renderTime: number) => void;
|
|
10
|
+
isScreenReaderEnabled?: boolean;
|
|
11
|
+
waitUntilExit?: () => Promise<void>;
|
|
12
|
+
maxFps?: number;
|
|
13
|
+
alternateBuffer?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export default class Ink {
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly log;
|
|
18
|
+
private readonly throttledLog;
|
|
19
|
+
private readonly isScreenReaderEnabled;
|
|
20
|
+
private isUnmounted;
|
|
21
|
+
private lastOutput;
|
|
22
|
+
private lastOutputHeight;
|
|
23
|
+
private readonly container;
|
|
24
|
+
private readonly rootNode;
|
|
25
|
+
private fullStaticOutput;
|
|
26
|
+
private exitPromise?;
|
|
27
|
+
private restoreConsole?;
|
|
28
|
+
private readonly unsubscribeResize?;
|
|
29
|
+
constructor(options: Options);
|
|
30
|
+
resized: () => void;
|
|
31
|
+
resolveExitPromise: () => void;
|
|
32
|
+
rejectExitPromise: (reason?: Error) => void;
|
|
33
|
+
unsubscribeExit: () => void;
|
|
34
|
+
calculateLayout: () => void;
|
|
35
|
+
onRender: () => void;
|
|
36
|
+
render(node: ReactNode): void;
|
|
37
|
+
writeToStdout(data: string): void;
|
|
38
|
+
writeToStderr(data: string): void;
|
|
39
|
+
unmount(error?: Error | number | null): void;
|
|
40
|
+
waitUntilExit(): Promise<void>;
|
|
41
|
+
clear(): void;
|
|
42
|
+
patchConsole(): void;
|
|
43
|
+
}
|
package/build/ink.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { throttle } from 'es-toolkit/compat';
|
|
4
|
+
import ansiEscapes from 'ansi-escapes';
|
|
5
|
+
import isInCi from 'is-in-ci';
|
|
6
|
+
import autoBind from 'auto-bind';
|
|
7
|
+
import signalExit from 'signal-exit';
|
|
8
|
+
import patchConsole from 'patch-console';
|
|
9
|
+
import { LegacyRoot } from 'react-reconciler/constants.js';
|
|
10
|
+
import Yoga from 'yoga-layout';
|
|
11
|
+
import wrapAnsi from 'wrap-ansi';
|
|
12
|
+
import reconciler from './reconciler.js';
|
|
13
|
+
import render from './renderer.js';
|
|
14
|
+
import * as dom from './dom.js';
|
|
15
|
+
import logUpdate from './log-update.js';
|
|
16
|
+
import instances from './instances.js';
|
|
17
|
+
import App from './components/App.js';
|
|
18
|
+
import { accessibilityContext as AccessibilityContext } from './components/AccessibilityContext.js';
|
|
19
|
+
const noop = () => { };
|
|
20
|
+
export default class Ink {
|
|
21
|
+
options;
|
|
22
|
+
log;
|
|
23
|
+
throttledLog;
|
|
24
|
+
isScreenReaderEnabled;
|
|
25
|
+
// Ignore last render after unmounting a tree to prevent empty output before exit
|
|
26
|
+
isUnmounted;
|
|
27
|
+
lastOutput;
|
|
28
|
+
lastOutputHeight;
|
|
29
|
+
container;
|
|
30
|
+
rootNode;
|
|
31
|
+
// This variable is used only in debug mode to store full static output
|
|
32
|
+
// so that it's rerendered every time, not just new static parts, like in non-debug mode
|
|
33
|
+
fullStaticOutput;
|
|
34
|
+
exitPromise;
|
|
35
|
+
restoreConsole;
|
|
36
|
+
unsubscribeResize;
|
|
37
|
+
constructor(options) {
|
|
38
|
+
autoBind(this);
|
|
39
|
+
this.options = options;
|
|
40
|
+
this.rootNode = dom.createNode('ink-root');
|
|
41
|
+
this.rootNode.onComputeLayout = this.calculateLayout;
|
|
42
|
+
this.isScreenReaderEnabled =
|
|
43
|
+
options.isScreenReaderEnabled ??
|
|
44
|
+
process.env['INK_SCREEN_READER'] === 'true';
|
|
45
|
+
const unthrottled = options.debug || this.isScreenReaderEnabled;
|
|
46
|
+
const maxFps = options.maxFps ?? 30;
|
|
47
|
+
const renderThrottleMs = maxFps > 0 ? Math.max(1, Math.ceil(1000 / maxFps)) : 0;
|
|
48
|
+
this.rootNode.onRender = unthrottled
|
|
49
|
+
? this.onRender
|
|
50
|
+
: throttle(this.onRender, renderThrottleMs, {
|
|
51
|
+
leading: true,
|
|
52
|
+
trailing: true,
|
|
53
|
+
});
|
|
54
|
+
this.rootNode.onImmediateRender = this.onRender;
|
|
55
|
+
this.log = logUpdate.create(options.stdout, {
|
|
56
|
+
alternateBuffer: options.alternateBuffer,
|
|
57
|
+
getRows: () => options.stdout.rows,
|
|
58
|
+
});
|
|
59
|
+
this.throttledLog = unthrottled
|
|
60
|
+
? this.log
|
|
61
|
+
: throttle(this.log, undefined, {
|
|
62
|
+
leading: true,
|
|
63
|
+
trailing: true,
|
|
64
|
+
});
|
|
65
|
+
// Ignore last render after unmounting a tree to prevent empty output before exit
|
|
66
|
+
this.isUnmounted = false;
|
|
67
|
+
// Store last output to only rerender when needed
|
|
68
|
+
this.lastOutput = '';
|
|
69
|
+
this.lastOutputHeight = 0;
|
|
70
|
+
// This variable is used only in debug mode to store full static output
|
|
71
|
+
// so that it's rerendered every time, not just new static parts, like in non-debug mode
|
|
72
|
+
this.fullStaticOutput = '';
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
74
|
+
this.container = reconciler.createContainer(this.rootNode, LegacyRoot, null, false, null, 'id', () => { }, () => { },
|
|
75
|
+
// TODO(jacobr): change this back to ts-expect-error if we can
|
|
76
|
+
// figure out how to align the Gemini CLI version with the Ink ones.
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
|
+
// @ts-ignore the types for `react-reconciler` are not up to date with the library.
|
|
79
|
+
// See https://github.com/facebook/react/blob/c0464aedb16b1c970d717651bba8d1c66c578729/packages/react-reconciler/src/ReactFiberReconciler.js#L236-L259
|
|
80
|
+
() => { }, () => { }, null);
|
|
81
|
+
// Unmount when process exits
|
|
82
|
+
this.unsubscribeExit = signalExit(this.unmount, { alwaysLast: false });
|
|
83
|
+
if (process.env['DEV'] === 'true') {
|
|
84
|
+
reconciler.injectIntoDevTools({
|
|
85
|
+
bundleType: 0,
|
|
86
|
+
// Reporting React DOM's version, not Ink's
|
|
87
|
+
// See https://github.com/facebook/react/issues/16666#issuecomment-532639905
|
|
88
|
+
version: '16.13.1',
|
|
89
|
+
rendererPackageName: 'ink',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (options.patchConsole) {
|
|
93
|
+
this.patchConsole();
|
|
94
|
+
}
|
|
95
|
+
if (!isInCi) {
|
|
96
|
+
options.stdout.on('resize', this.resized);
|
|
97
|
+
this.unsubscribeResize = () => {
|
|
98
|
+
options.stdout.off('resize', this.resized);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
resized = () => {
|
|
103
|
+
this.calculateLayout();
|
|
104
|
+
this.onRender();
|
|
105
|
+
};
|
|
106
|
+
resolveExitPromise = () => { };
|
|
107
|
+
rejectExitPromise = () => { };
|
|
108
|
+
unsubscribeExit = () => { };
|
|
109
|
+
calculateLayout = () => {
|
|
110
|
+
// The 'columns' property can be undefined or 0 when not using a TTY.
|
|
111
|
+
// In that case we fall back to 80.
|
|
112
|
+
const terminalWidth = this.options.stdout.columns || 80;
|
|
113
|
+
this.rootNode.yogaNode.setWidth(terminalWidth);
|
|
114
|
+
this.rootNode.yogaNode.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
|
115
|
+
};
|
|
116
|
+
onRender = () => {
|
|
117
|
+
if (this.isUnmounted) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const { output, outputHeight, staticOutput } = render(this.rootNode, this.isScreenReaderEnabled);
|
|
121
|
+
// If <Static> output isn't empty, it means new children have been added to it
|
|
122
|
+
const hasStaticOutput = staticOutput && staticOutput !== '\n';
|
|
123
|
+
if (this.options.debug) {
|
|
124
|
+
if (hasStaticOutput) {
|
|
125
|
+
this.fullStaticOutput += staticOutput;
|
|
126
|
+
}
|
|
127
|
+
this.options.stdout.write(this.fullStaticOutput + output);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (isInCi) {
|
|
131
|
+
if (hasStaticOutput) {
|
|
132
|
+
this.options.stdout.write(staticOutput);
|
|
133
|
+
}
|
|
134
|
+
this.lastOutput = output;
|
|
135
|
+
this.lastOutputHeight = outputHeight;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (this.options.alternateBuffer) {
|
|
139
|
+
if (hasStaticOutput) {
|
|
140
|
+
this.fullStaticOutput += staticOutput;
|
|
141
|
+
}
|
|
142
|
+
this.log(this.fullStaticOutput + output);
|
|
143
|
+
this.lastOutput = output;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (this.isScreenReaderEnabled) {
|
|
147
|
+
if (hasStaticOutput) {
|
|
148
|
+
// We need to erase the main output before writing new static output
|
|
149
|
+
const erase = this.lastOutputHeight > 0
|
|
150
|
+
? ansiEscapes.eraseLines(this.lastOutputHeight)
|
|
151
|
+
: '';
|
|
152
|
+
this.options.stdout.write(erase + staticOutput);
|
|
153
|
+
// After erasing, the last output is gone, so we should reset its height
|
|
154
|
+
this.lastOutputHeight = 0;
|
|
155
|
+
}
|
|
156
|
+
if (output === this.lastOutput && !hasStaticOutput) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const terminalWidth = this.options.stdout.columns || 80;
|
|
160
|
+
const wrappedOutput = wrapAnsi(output, terminalWidth, {
|
|
161
|
+
trim: false,
|
|
162
|
+
hard: true,
|
|
163
|
+
});
|
|
164
|
+
// If we haven't erased yet, do it now.
|
|
165
|
+
if (hasStaticOutput) {
|
|
166
|
+
this.options.stdout.write(wrappedOutput);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
const erase = this.lastOutputHeight > 0
|
|
170
|
+
? ansiEscapes.eraseLines(this.lastOutputHeight)
|
|
171
|
+
: '';
|
|
172
|
+
this.options.stdout.write(erase + wrappedOutput);
|
|
173
|
+
}
|
|
174
|
+
this.lastOutput = output;
|
|
175
|
+
this.lastOutputHeight =
|
|
176
|
+
wrappedOutput === '' ? 0 : wrappedOutput.split('\n').length;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (hasStaticOutput) {
|
|
180
|
+
this.fullStaticOutput += staticOutput;
|
|
181
|
+
}
|
|
182
|
+
if (this.lastOutputHeight >= this.options.stdout.rows) {
|
|
183
|
+
this.options.stdout.write(ansiEscapes.clearTerminal + this.fullStaticOutput + output);
|
|
184
|
+
this.lastOutput = output;
|
|
185
|
+
this.lastOutputHeight = outputHeight;
|
|
186
|
+
this.log.sync(output);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
// To ensure static output is cleanly rendered before main output, clear main output first
|
|
190
|
+
if (hasStaticOutput) {
|
|
191
|
+
this.log.clear();
|
|
192
|
+
this.options.stdout.write(staticOutput);
|
|
193
|
+
this.log(output);
|
|
194
|
+
}
|
|
195
|
+
if (!hasStaticOutput && output !== this.lastOutput) {
|
|
196
|
+
this.throttledLog(output);
|
|
197
|
+
}
|
|
198
|
+
this.lastOutput = output;
|
|
199
|
+
this.lastOutputHeight = outputHeight;
|
|
200
|
+
};
|
|
201
|
+
render(node) {
|
|
202
|
+
const tree = (React.createElement(AccessibilityContext.Provider, { value: { isScreenReaderEnabled: this.isScreenReaderEnabled } },
|
|
203
|
+
React.createElement(App, { stdin: this.options.stdin, stdout: this.options.stdout, stderr: this.options.stderr, writeToStdout: this.writeToStdout, writeToStderr: this.writeToStderr, exitOnCtrlC: this.options.exitOnCtrlC, onExit: this.unmount }, node)));
|
|
204
|
+
const start = Date.now();
|
|
205
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
207
|
+
reconciler.updateContainerSync(tree, this.container, null, noop);
|
|
208
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
209
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
210
|
+
reconciler.flushSyncWork();
|
|
211
|
+
if (this.options.onRender) {
|
|
212
|
+
const end = Date.now();
|
|
213
|
+
this.options.onRender(end - start);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
writeToStdout(data) {
|
|
217
|
+
if (this.isUnmounted) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (this.options.debug) {
|
|
221
|
+
this.options.stdout.write(data + this.fullStaticOutput + this.lastOutput);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (isInCi) {
|
|
225
|
+
this.options.stdout.write(data);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
this.log.clear();
|
|
229
|
+
this.options.stdout.write(data);
|
|
230
|
+
this.log(this.lastOutput);
|
|
231
|
+
}
|
|
232
|
+
writeToStderr(data) {
|
|
233
|
+
if (this.isUnmounted) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (this.options.debug) {
|
|
237
|
+
this.options.stderr.write(data);
|
|
238
|
+
this.options.stdout.write(this.fullStaticOutput + this.lastOutput);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (isInCi) {
|
|
242
|
+
this.options.stderr.write(data);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.log.clear();
|
|
246
|
+
this.options.stderr.write(data);
|
|
247
|
+
this.log(this.lastOutput);
|
|
248
|
+
}
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
250
|
+
unmount(error) {
|
|
251
|
+
if (this.isUnmounted) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
this.calculateLayout();
|
|
255
|
+
this.onRender();
|
|
256
|
+
this.unsubscribeExit();
|
|
257
|
+
if (typeof this.restoreConsole === 'function') {
|
|
258
|
+
this.restoreConsole();
|
|
259
|
+
}
|
|
260
|
+
if (typeof this.unsubscribeResize === 'function') {
|
|
261
|
+
this.unsubscribeResize();
|
|
262
|
+
}
|
|
263
|
+
// CIs don't handle erasing ansi escapes well, so it's better to
|
|
264
|
+
// only render last frame of non-static output
|
|
265
|
+
if (isInCi) {
|
|
266
|
+
this.options.stdout.write(this.lastOutput + '\n');
|
|
267
|
+
}
|
|
268
|
+
else if (!this.options.debug) {
|
|
269
|
+
this.log.done();
|
|
270
|
+
}
|
|
271
|
+
this.isUnmounted = true;
|
|
272
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
273
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
274
|
+
reconciler.updateContainerSync(null, this.container, null, noop);
|
|
275
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
276
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
277
|
+
reconciler.flushSyncWork();
|
|
278
|
+
instances.delete(this.options.stdout);
|
|
279
|
+
if (error instanceof Error) {
|
|
280
|
+
this.rejectExitPromise(error);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
this.resolveExitPromise();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async waitUntilExit() {
|
|
287
|
+
this.exitPromise ||= new Promise((resolve, reject) => {
|
|
288
|
+
this.resolveExitPromise = resolve;
|
|
289
|
+
this.rejectExitPromise = reject;
|
|
290
|
+
});
|
|
291
|
+
return this.exitPromise;
|
|
292
|
+
}
|
|
293
|
+
clear() {
|
|
294
|
+
if (!isInCi && !this.options.debug) {
|
|
295
|
+
this.log.clear();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
patchConsole() {
|
|
299
|
+
if (this.options.debug) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
this.restoreConsole = patchConsole((stream, data) => {
|
|
303
|
+
if (stream === 'stdout') {
|
|
304
|
+
this.writeToStdout(data);
|
|
305
|
+
}
|
|
306
|
+
if (stream === 'stderr') {
|
|
307
|
+
const isReactMessage = data.startsWith('The above error occurred');
|
|
308
|
+
if (!isReactMessage) {
|
|
309
|
+
this.writeToStderr(data);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=ink.js.map
|
package/build/ink.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ink.js","sourceRoot":"","sources":["../src/ink.tsx"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,KAAuB,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,UAAU,EAAC,MAAM,+BAA+B,CAAC;AAEzD,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,QAAQ,MAAM,WAAW,CAAC;A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CAAC;IACzB,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACpC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;IACF,CAAC;IAED,YAAY;QACX,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACxB,OAAO;QACR,CAAC;QAED,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;YACnD,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;YAED,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzB,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC;gBAEnE,IAAI,CAAC,cAAc,EAAE,CAAC;oBACrB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gBAC1B,CAAC;YACF,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Store all instances of Ink (instance.js) to ensure that consecutive render() calls
|
|
2
|
+
// use the same instance of Ink and don't create a new one
|
|
3
|
+
//
|
|
4
|
+
// This map has to be stored in a separate file, because render.js creates instances,
|
|
5
|
+
// but instance.js should delete itself from the map on unmount
|
|
6
|
+
const instances = new WeakMap();
|
|
7
|
+
export default instances;
|
|
8
|
+
//# sourceMappingURL=instances.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instances.js","sourceRoot":"","sources":["../src/instances.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,0DAA0D;AAC1D,EAAE;AACF,qFAAqF;AACrF,+DAA+D;AAI/D,MAAM,SAAS,GAAG,IAAI,OAAO,EAA2B,CAAC;AACzD,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Writable } from 'node:stream';
|
|
2
|
+
export type LogUpdate = {
|
|
3
|
+
clear: () => void;
|
|
4
|
+
done: () => void;
|
|
5
|
+
sync: (str: string) => void;
|
|
6
|
+
(str: string): void;
|
|
7
|
+
};
|
|
8
|
+
declare const logUpdate: {
|
|
9
|
+
create: (stream: Writable, { showCursor, alternateBuffer, getRows, }?: {
|
|
10
|
+
showCursor?: boolean;
|
|
11
|
+
alternateBuffer?: boolean;
|
|
12
|
+
getRows?: () => number;
|
|
13
|
+
}) => LogUpdate;
|
|
14
|
+
};
|
|
15
|
+
export default logUpdate;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import ansiEscapes from 'ansi-escapes';
|
|
3
|
+
import cliCursor from 'cli-cursor';
|
|
4
|
+
const enterSynchronizedOutput = '\u001B[?2026h';
|
|
5
|
+
const exitSynchronizedOutput = '\u001B[?2026l';
|
|
6
|
+
const create = (stream, { showCursor = false, alternateBuffer = false, getRows = () => 0, } = {}) => {
|
|
7
|
+
let previousLineCount = 0;
|
|
8
|
+
let previousOutput = '';
|
|
9
|
+
// Keep track of the actual previous output rendered to the alternate buffer
|
|
10
|
+
// which may be truncated to the terminal height.
|
|
11
|
+
let previousOutputAlternateBuffer = '';
|
|
12
|
+
let hasHiddenCursor = false;
|
|
13
|
+
if (alternateBuffer) {
|
|
14
|
+
stream.write(ansiEscapes.enterAlternativeScreen);
|
|
15
|
+
}
|
|
16
|
+
const render = (str) => {
|
|
17
|
+
if (!showCursor && !hasHiddenCursor) {
|
|
18
|
+
cliCursor.hide();
|
|
19
|
+
hasHiddenCursor = true;
|
|
20
|
+
}
|
|
21
|
+
const output = str + '\n';
|
|
22
|
+
if (alternateBuffer) {
|
|
23
|
+
let alternateBufferOutput = output;
|
|
24
|
+
const rows = getRows() ?? 0;
|
|
25
|
+
if (rows > 0) {
|
|
26
|
+
const lines = str.split('\n');
|
|
27
|
+
const lineCount = lines.length;
|
|
28
|
+
// Only write the last `rows` lines as the alternate buffer
|
|
29
|
+
// will not scroll so all we accomplish by writing more
|
|
30
|
+
// content is risking flicker and confusing the terminal about
|
|
31
|
+
// the cursor position.
|
|
32
|
+
if (lineCount > rows) {
|
|
33
|
+
alternateBufferOutput = lines.slice(-rows).join('\n');
|
|
34
|
+
}
|
|
35
|
+
// Only write the last `rows` lines as the alternate buffer
|
|
36
|
+
// will not scroll so all we accomplish by writing more
|
|
37
|
+
// content is risking flicker and confusing the terminal about
|
|
38
|
+
// the cursor position.
|
|
39
|
+
if (lineCount > rows) {
|
|
40
|
+
alternateBufferOutput = str.split('\n').slice(-rows).join('\n');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// In alternate buffer mode we need to re-render based on whether content
|
|
44
|
+
// visible within the clipped alternate output buffer has changed even
|
|
45
|
+
// if the entire output string has not changed.
|
|
46
|
+
if (alternateBufferOutput !== previousOutputAlternateBuffer) {
|
|
47
|
+
// Unfortunately, eraseScreen does not work correctly in iTerm2 so we
|
|
48
|
+
// have to use clearTerminal instead.
|
|
49
|
+
const eraseOperation = process.env['TERM_PROGRAM'] === 'iTerm.app'
|
|
50
|
+
? ansiEscapes.clearTerminal
|
|
51
|
+
: ansiEscapes.eraseScreen;
|
|
52
|
+
stream.write(enterSynchronizedOutput +
|
|
53
|
+
ansiEscapes.cursorTo(0, 0) +
|
|
54
|
+
eraseOperation +
|
|
55
|
+
alternateBufferOutput +
|
|
56
|
+
exitSynchronizedOutput);
|
|
57
|
+
previousOutputAlternateBuffer = alternateBufferOutput;
|
|
58
|
+
}
|
|
59
|
+
previousOutput = output;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
previousOutput = output;
|
|
63
|
+
stream.write(ansiEscapes.eraseLines(previousLineCount) + output);
|
|
64
|
+
previousLineCount = output.split('\n').length;
|
|
65
|
+
};
|
|
66
|
+
render.clear = () => {
|
|
67
|
+
if (alternateBuffer) {
|
|
68
|
+
const eraseOperation = process.env['TERM_PROGRAM'] === 'iTerm.app'
|
|
69
|
+
? ansiEscapes.clearTerminal
|
|
70
|
+
: ansiEscapes.eraseScreen;
|
|
71
|
+
stream.write(eraseOperation);
|
|
72
|
+
previousOutput = '';
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
stream.write(ansiEscapes.eraseLines(previousLineCount));
|
|
76
|
+
previousOutput = '';
|
|
77
|
+
previousLineCount = 0;
|
|
78
|
+
};
|
|
79
|
+
render.done = () => {
|
|
80
|
+
const lastFrame = previousOutput;
|
|
81
|
+
previousOutput = '';
|
|
82
|
+
previousLineCount = 0;
|
|
83
|
+
if (!showCursor) {
|
|
84
|
+
cliCursor.show();
|
|
85
|
+
hasHiddenCursor = false;
|
|
86
|
+
}
|
|
87
|
+
if (alternateBuffer) {
|
|
88
|
+
stream.write(ansiEscapes.exitAlternativeScreen);
|
|
89
|
+
// The last frame was rendered to the alternate buffer.
|
|
90
|
+
// We need to render it again to the main buffer. If apps do not
|
|
91
|
+
// want this behavior, they can make sure the last frame is empty
|
|
92
|
+
// before unmounting.
|
|
93
|
+
stream.write(lastFrame);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
render.sync = (str) => {
|
|
97
|
+
if (alternateBuffer) {
|
|
98
|
+
previousOutput = str;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const output = str + '\n';
|
|
102
|
+
previousOutput = output;
|
|
103
|
+
previousLineCount = output.split('\n').length;
|
|
104
|
+
};
|
|
105
|
+
return render;
|
|
106
|
+
};
|
|
107
|
+
const logUpdate = { create };
|
|
108
|
+
export default logUpdate;
|
|
109
|
+
//# sourceMappingURL=log-update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-update.js","sourceRoot":"","sources":["../src/log-update.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OA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-0,0 +1,38 @@
|
|
|
1
|
+
import { type DOMElement } from './dom.js';
|
|
2
|
+
type Output = {
|
|
3
|
+
/**
|
|
4
|
+
Element width.
|
|
5
|
+
*/
|
|
6
|
+
width: number;
|
|
7
|
+
/**
|
|
8
|
+
Element height.
|
|
9
|
+
*/
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
Measure the dimensions of a particular `<Box>` element.
|
|
14
|
+
*/
|
|
15
|
+
declare const measureElement: (node: DOMElement) => Output;
|
|
16
|
+
/**
|
|
17
|
+
* Get an element's inner width.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getInnerWidth: (node: DOMElement) => number;
|
|
20
|
+
export declare const getInnerHeight: (node: DOMElement) => number;
|
|
21
|
+
/**
|
|
22
|
+
* Get an element's position and dimensions relative to the root.
|
|
23
|
+
*/
|
|
24
|
+
export declare const getBoundingBox: (node: DOMElement) => {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The entire height of an elements content.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getScrollHeight: (node: DOMElement) => number;
|
|
34
|
+
/**
|
|
35
|
+
* The entire width of an elements content.
|
|
36
|
+
*/
|
|
37
|
+
export declare const getScrollWidth: (node: DOMElement) => number;
|
|
38
|
+
export default measureElement;
|