@nuvin/ink 6.5.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 +117 -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 +11 -0
- package/build/devtools.js.map +1 -0
- package/build/dom.d.ts +56 -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 +54 -0
- package/build/ink.js +309 -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-to-file.d.ts +49 -0
- package/build/log-to-file.js +83 -0
- package/build/log-to-file.js.map +1 -0
- package/build/log-update.d.ts +14 -0
- package/build/log-update.js +116 -0
- package/build/log-update.js.map +1 -0
- package/build/measure-element.d.ts +16 -0
- package/build/measure-element.js +9 -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 +34 -0
- package/build/output.js +150 -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 +147 -0
- package/build/render-node-to-output.js.map +1 -0
- package/build/render.d.ts +88 -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/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 +240 -0
- package/build/styles.js +232 -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 +10 -0
- package/package.json +195 -0
- package/readme.md +2356 -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 } 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 } 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,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,sBAAsB,CAAC"}
|
package/build/ink.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
Performance metrics for a render operation.
|
|
4
|
+
*/
|
|
5
|
+
export type RenderMetrics = {
|
|
6
|
+
/**
|
|
7
|
+
Time spent rendering in milliseconds.
|
|
8
|
+
*/
|
|
9
|
+
renderTime: number;
|
|
10
|
+
};
|
|
11
|
+
export type Options = {
|
|
12
|
+
stdout: NodeJS.WriteStream;
|
|
13
|
+
stdin: NodeJS.ReadStream;
|
|
14
|
+
stderr: NodeJS.WriteStream;
|
|
15
|
+
debug: boolean;
|
|
16
|
+
exitOnCtrlC: boolean;
|
|
17
|
+
patchConsole: boolean;
|
|
18
|
+
onRender?: (metrics: RenderMetrics) => void;
|
|
19
|
+
isScreenReaderEnabled?: boolean;
|
|
20
|
+
waitUntilExit?: () => Promise<void>;
|
|
21
|
+
maxFps?: number;
|
|
22
|
+
incrementalRendering?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export default class Ink {
|
|
25
|
+
private readonly options;
|
|
26
|
+
private readonly log;
|
|
27
|
+
private readonly throttledLog;
|
|
28
|
+
private readonly isScreenReaderEnabled;
|
|
29
|
+
private isUnmounted;
|
|
30
|
+
private lastOutput;
|
|
31
|
+
private lastOutputHeight;
|
|
32
|
+
private lastTerminalWidth;
|
|
33
|
+
private readonly container;
|
|
34
|
+
private readonly rootNode;
|
|
35
|
+
private fullStaticOutput;
|
|
36
|
+
private exitPromise?;
|
|
37
|
+
private restoreConsole?;
|
|
38
|
+
private readonly unsubscribeResize?;
|
|
39
|
+
constructor(options: Options);
|
|
40
|
+
getTerminalWidth: () => number;
|
|
41
|
+
resized: () => void;
|
|
42
|
+
resolveExitPromise: () => void;
|
|
43
|
+
rejectExitPromise: (reason?: Error) => void;
|
|
44
|
+
unsubscribeExit: () => void;
|
|
45
|
+
calculateLayout: () => void;
|
|
46
|
+
onRender: () => void;
|
|
47
|
+
render(node: ReactNode): void;
|
|
48
|
+
writeToStdout(data: string): void;
|
|
49
|
+
writeToStderr(data: string): void;
|
|
50
|
+
unmount(error?: Error | number | null): void;
|
|
51
|
+
waitUntilExit(): Promise<void>;
|
|
52
|
+
clear(): void;
|
|
53
|
+
patchConsole(): void;
|
|
54
|
+
}
|
package/build/ink.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
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
|
+
lastTerminalWidth;
|
|
30
|
+
container;
|
|
31
|
+
rootNode;
|
|
32
|
+
// This variable is used only in debug mode to store full static output
|
|
33
|
+
// so that it's rerendered every time, not just new static parts, like in non-debug mode
|
|
34
|
+
fullStaticOutput;
|
|
35
|
+
exitPromise;
|
|
36
|
+
restoreConsole;
|
|
37
|
+
unsubscribeResize;
|
|
38
|
+
constructor(options) {
|
|
39
|
+
autoBind(this);
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.rootNode = dom.createNode('ink-root');
|
|
42
|
+
this.rootNode.onComputeLayout = this.calculateLayout;
|
|
43
|
+
this.isScreenReaderEnabled =
|
|
44
|
+
options.isScreenReaderEnabled ??
|
|
45
|
+
process.env['INK_SCREEN_READER'] === 'true';
|
|
46
|
+
const unthrottled = options.debug || this.isScreenReaderEnabled;
|
|
47
|
+
const maxFps = options.maxFps ?? 30;
|
|
48
|
+
const renderThrottleMs = maxFps > 0 ? Math.max(1, Math.ceil(1000 / maxFps)) : 0;
|
|
49
|
+
this.rootNode.onRender = unthrottled
|
|
50
|
+
? this.onRender
|
|
51
|
+
: throttle(this.onRender, renderThrottleMs, {
|
|
52
|
+
leading: true,
|
|
53
|
+
trailing: true,
|
|
54
|
+
});
|
|
55
|
+
this.rootNode.onImmediateRender = this.onRender;
|
|
56
|
+
this.log = logUpdate.create(options.stdout, {
|
|
57
|
+
incremental: options.incrementalRendering,
|
|
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.lastTerminalWidth = this.getTerminalWidth();
|
|
71
|
+
// This variable is used only in debug mode to store full static output
|
|
72
|
+
// so that it's rerendered every time, not just new static parts, like in non-debug mode
|
|
73
|
+
this.fullStaticOutput = '';
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
75
|
+
this.container = reconciler.createContainer(this.rootNode, LegacyRoot, null, false, null, 'id', () => { }, () => { }, () => { }, () => { }, null);
|
|
76
|
+
// Unmount when process exits
|
|
77
|
+
this.unsubscribeExit = signalExit(this.unmount, { alwaysLast: false });
|
|
78
|
+
if (process.env['DEV'] === 'true') {
|
|
79
|
+
reconciler.injectIntoDevTools({
|
|
80
|
+
bundleType: 0,
|
|
81
|
+
// Reporting React DOM's version, not Ink's
|
|
82
|
+
// See https://github.com/facebook/react/issues/16666#issuecomment-532639905
|
|
83
|
+
version: '16.13.1',
|
|
84
|
+
rendererPackageName: 'ink',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (options.patchConsole) {
|
|
88
|
+
this.patchConsole();
|
|
89
|
+
}
|
|
90
|
+
if (!isInCi) {
|
|
91
|
+
options.stdout.on('resize', this.resized);
|
|
92
|
+
this.unsubscribeResize = () => {
|
|
93
|
+
options.stdout.off('resize', this.resized);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
getTerminalWidth = () => {
|
|
98
|
+
// The 'columns' property can be undefined or 0 when not using a TTY.
|
|
99
|
+
// In that case we fall back to 80.
|
|
100
|
+
return this.options.stdout.columns || 80;
|
|
101
|
+
};
|
|
102
|
+
resized = () => {
|
|
103
|
+
const currentWidth = this.getTerminalWidth();
|
|
104
|
+
if (currentWidth < this.lastTerminalWidth) {
|
|
105
|
+
// We clear the screen when decreasing terminal width to prevent duplicate overlapping re-renders.
|
|
106
|
+
this.log.clear();
|
|
107
|
+
this.lastOutput = '';
|
|
108
|
+
}
|
|
109
|
+
this.calculateLayout();
|
|
110
|
+
this.onRender();
|
|
111
|
+
this.lastTerminalWidth = currentWidth;
|
|
112
|
+
};
|
|
113
|
+
resolveExitPromise = () => { };
|
|
114
|
+
rejectExitPromise = () => { };
|
|
115
|
+
unsubscribeExit = () => { };
|
|
116
|
+
calculateLayout = () => {
|
|
117
|
+
const terminalWidth = this.getTerminalWidth();
|
|
118
|
+
this.rootNode.yogaNode.setWidth(terminalWidth);
|
|
119
|
+
this.rootNode.yogaNode.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
|
|
120
|
+
};
|
|
121
|
+
onRender = () => {
|
|
122
|
+
if (this.isUnmounted) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const startTime = performance.now();
|
|
126
|
+
const { output, outputHeight, staticOutput } = render(this.rootNode, this.isScreenReaderEnabled);
|
|
127
|
+
this.options.onRender?.({ renderTime: performance.now() - startTime });
|
|
128
|
+
// If <Static> output isn't empty, it means new children have been added to it
|
|
129
|
+
const hasStaticOutput = staticOutput && staticOutput !== '\n';
|
|
130
|
+
if (this.options.debug) {
|
|
131
|
+
if (hasStaticOutput) {
|
|
132
|
+
this.fullStaticOutput += staticOutput;
|
|
133
|
+
}
|
|
134
|
+
this.options.stdout.write(this.fullStaticOutput + output);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (isInCi) {
|
|
138
|
+
if (hasStaticOutput) {
|
|
139
|
+
this.options.stdout.write(staticOutput);
|
|
140
|
+
}
|
|
141
|
+
this.lastOutput = output;
|
|
142
|
+
this.lastOutputHeight = outputHeight;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (this.isScreenReaderEnabled) {
|
|
146
|
+
if (hasStaticOutput) {
|
|
147
|
+
// We need to erase the main output before writing new static output
|
|
148
|
+
const erase = this.lastOutputHeight > 0
|
|
149
|
+
? ansiEscapes.eraseLines(this.lastOutputHeight)
|
|
150
|
+
: '';
|
|
151
|
+
this.options.stdout.write(erase + staticOutput);
|
|
152
|
+
// After erasing, the last output is gone, so we should reset its height
|
|
153
|
+
this.lastOutputHeight = 0;
|
|
154
|
+
}
|
|
155
|
+
if (output === this.lastOutput && !hasStaticOutput) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const terminalWidth = this.options.stdout.columns || 80;
|
|
159
|
+
const wrappedOutput = wrapAnsi(output, terminalWidth, {
|
|
160
|
+
trim: false,
|
|
161
|
+
hard: true,
|
|
162
|
+
});
|
|
163
|
+
// If we haven't erased yet, do it now.
|
|
164
|
+
if (hasStaticOutput) {
|
|
165
|
+
this.options.stdout.write(wrappedOutput);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const erase = this.lastOutputHeight > 0
|
|
169
|
+
? ansiEscapes.eraseLines(this.lastOutputHeight)
|
|
170
|
+
: '';
|
|
171
|
+
this.options.stdout.write(erase + wrappedOutput);
|
|
172
|
+
}
|
|
173
|
+
this.lastOutput = output;
|
|
174
|
+
this.lastOutputHeight =
|
|
175
|
+
wrappedOutput === '' ? 0 : wrappedOutput.split('\n').length;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (hasStaticOutput) {
|
|
179
|
+
this.fullStaticOutput += staticOutput;
|
|
180
|
+
}
|
|
181
|
+
if (this.lastOutputHeight >= this.options.stdout.rows) {
|
|
182
|
+
this.options.stdout.write(ansiEscapes.clearTerminal + this.fullStaticOutput + output + '\n');
|
|
183
|
+
this.lastOutput = output;
|
|
184
|
+
this.lastOutputHeight = outputHeight;
|
|
185
|
+
this.log.sync(output);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// To ensure static output is cleanly rendered before main output, clear main output first
|
|
189
|
+
if (hasStaticOutput) {
|
|
190
|
+
this.log.clear();
|
|
191
|
+
this.options.stdout.write(staticOutput);
|
|
192
|
+
this.log(output);
|
|
193
|
+
}
|
|
194
|
+
if (!hasStaticOutput && output !== this.lastOutput) {
|
|
195
|
+
this.throttledLog(output);
|
|
196
|
+
}
|
|
197
|
+
this.lastOutput = output;
|
|
198
|
+
this.lastOutputHeight = outputHeight;
|
|
199
|
+
};
|
|
200
|
+
render(node) {
|
|
201
|
+
const tree = (React.createElement(AccessibilityContext.Provider, { value: { isScreenReaderEnabled: this.isScreenReaderEnabled } },
|
|
202
|
+
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)));
|
|
203
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
205
|
+
reconciler.updateContainerSync(tree, this.container, null, noop);
|
|
206
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
207
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
208
|
+
reconciler.flushSyncWork();
|
|
209
|
+
}
|
|
210
|
+
writeToStdout(data) {
|
|
211
|
+
if (this.isUnmounted) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (this.options.debug) {
|
|
215
|
+
this.options.stdout.write(data + this.fullStaticOutput + this.lastOutput);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (isInCi) {
|
|
219
|
+
this.options.stdout.write(data);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.log.clear();
|
|
223
|
+
this.options.stdout.write(data);
|
|
224
|
+
this.log(this.lastOutput);
|
|
225
|
+
}
|
|
226
|
+
writeToStderr(data) {
|
|
227
|
+
if (this.isUnmounted) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (this.options.debug) {
|
|
231
|
+
this.options.stderr.write(data);
|
|
232
|
+
this.options.stdout.write(this.fullStaticOutput + this.lastOutput);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (isInCi) {
|
|
236
|
+
this.options.stderr.write(data);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
this.log.clear();
|
|
240
|
+
this.options.stderr.write(data);
|
|
241
|
+
this.log(this.lastOutput);
|
|
242
|
+
}
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
244
|
+
unmount(error) {
|
|
245
|
+
if (this.isUnmounted) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
this.calculateLayout();
|
|
249
|
+
this.onRender();
|
|
250
|
+
this.unsubscribeExit();
|
|
251
|
+
if (typeof this.restoreConsole === 'function') {
|
|
252
|
+
this.restoreConsole();
|
|
253
|
+
}
|
|
254
|
+
if (typeof this.unsubscribeResize === 'function') {
|
|
255
|
+
this.unsubscribeResize();
|
|
256
|
+
}
|
|
257
|
+
// CIs don't handle erasing ansi escapes well, so it's better to
|
|
258
|
+
// only render last frame of non-static output
|
|
259
|
+
if (isInCi) {
|
|
260
|
+
this.options.stdout.write(this.lastOutput + '\n');
|
|
261
|
+
}
|
|
262
|
+
else if (!this.options.debug) {
|
|
263
|
+
this.log.done();
|
|
264
|
+
}
|
|
265
|
+
this.isUnmounted = true;
|
|
266
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
268
|
+
reconciler.updateContainerSync(null, this.container, null, noop);
|
|
269
|
+
// @ts-expect-error the types for `react-reconciler` are not up to date with the library.
|
|
270
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
271
|
+
reconciler.flushSyncWork();
|
|
272
|
+
instances.delete(this.options.stdout);
|
|
273
|
+
if (error instanceof Error) {
|
|
274
|
+
this.rejectExitPromise(error);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
this.resolveExitPromise();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
async waitUntilExit() {
|
|
281
|
+
this.exitPromise ||= new Promise((resolve, reject) => {
|
|
282
|
+
this.resolveExitPromise = resolve;
|
|
283
|
+
this.rejectExitPromise = reject;
|
|
284
|
+
});
|
|
285
|
+
return this.exitPromise;
|
|
286
|
+
}
|
|
287
|
+
clear() {
|
|
288
|
+
if (!isInCi && !this.options.debug) {
|
|
289
|
+
this.log.clear();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
patchConsole() {
|
|
293
|
+
if (this.options.debug) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
this.restoreConsole = patchConsole((stream, data) => {
|
|
297
|
+
if (stream === 'stdout') {
|
|
298
|
+
this.writeToStdout(data);
|
|
299
|
+
}
|
|
300
|
+
if (stream === 'stderr') {
|
|
301
|
+
const isReactMessage = data.startsWith('The above error occurred');
|
|
302
|
+
if (!isReactMessage) {
|
|
303
|
+
this.writeToStderr(data);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
//# 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;AACjC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,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AAG,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,49 @@
|
|
|
1
|
+
export type LogToFileOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* File path to write logs to
|
|
4
|
+
*/
|
|
5
|
+
filePath: string;
|
|
6
|
+
/**
|
|
7
|
+
* Whether to append to existing file or overwrite
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
append?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to include timestamps in log entries
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
includeTimestamp?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to create parent directories if they don't exist
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
createDirs?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare class LogToFile {
|
|
23
|
+
private filePath;
|
|
24
|
+
private append;
|
|
25
|
+
private includeTimestamp;
|
|
26
|
+
private initialized;
|
|
27
|
+
constructor(options: LogToFileOptions);
|
|
28
|
+
/**
|
|
29
|
+
* Write a log entry to the file
|
|
30
|
+
*/
|
|
31
|
+
log(...args: any[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Write a separator line to the file
|
|
34
|
+
*/
|
|
35
|
+
separator(char?: string, length?: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Clear the log file
|
|
38
|
+
*/
|
|
39
|
+
clear(): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a simple logger instance
|
|
43
|
+
*/
|
|
44
|
+
export declare function createLogger(filePath: string, options?: Omit<LogToFileOptions, 'filePath'>): LogToFile;
|
|
45
|
+
/**
|
|
46
|
+
* Quick logging function for debugging
|
|
47
|
+
* Creates a logger at /tmp/debug.log by default
|
|
48
|
+
*/
|
|
49
|
+
export declare function debugLog(...args: any[]): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
export class LogToFile {
|
|
4
|
+
filePath;
|
|
5
|
+
append;
|
|
6
|
+
includeTimestamp;
|
|
7
|
+
initialized = false;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.filePath = options.filePath;
|
|
10
|
+
this.append = options.append ?? true;
|
|
11
|
+
this.includeTimestamp = options.includeTimestamp ?? true;
|
|
12
|
+
if (options.createDirs ?? true) {
|
|
13
|
+
const dir = dirname(this.filePath);
|
|
14
|
+
if (!existsSync(dir)) {
|
|
15
|
+
mkdirSync(dir, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Write a log entry to the file
|
|
21
|
+
*/
|
|
22
|
+
log(...args) {
|
|
23
|
+
const message = args
|
|
24
|
+
.map(arg => {
|
|
25
|
+
if (typeof arg === 'string') {
|
|
26
|
+
return arg;
|
|
27
|
+
}
|
|
28
|
+
if (arg instanceof Error) {
|
|
29
|
+
return `${arg.message}\n${arg.stack}`;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return JSON.stringify(arg, null, 2);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return String(arg);
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
.join(' ');
|
|
39
|
+
const timestamp = this.includeTimestamp
|
|
40
|
+
? `[${new Date().toISOString()}] `
|
|
41
|
+
: '';
|
|
42
|
+
const entry = `${timestamp}${message}\n`;
|
|
43
|
+
if (!this.initialized && !this.append) {
|
|
44
|
+
writeFileSync(this.filePath, entry, 'utf8');
|
|
45
|
+
this.initialized = true;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
appendFileSync(this.filePath, entry, 'utf8');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Write a separator line to the file
|
|
53
|
+
*/
|
|
54
|
+
separator(char = '-', length = 80) {
|
|
55
|
+
this.log(char.repeat(length));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Clear the log file
|
|
59
|
+
*/
|
|
60
|
+
clear() {
|
|
61
|
+
writeFileSync(this.filePath, '', 'utf8');
|
|
62
|
+
this.initialized = false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a simple logger instance
|
|
67
|
+
*/
|
|
68
|
+
export function createLogger(filePath, options) {
|
|
69
|
+
return new LogToFile({ filePath, ...options });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Quick logging function for debugging
|
|
73
|
+
* Creates a logger at /tmp/debug.log by default
|
|
74
|
+
*/
|
|
75
|
+
export function debugLog(...args) {
|
|
76
|
+
const logger = new LogToFile({
|
|
77
|
+
filePath: '/tmp/debug.log',
|
|
78
|
+
append: true,
|
|
79
|
+
includeTimestamp: true,
|
|
80
|
+
});
|
|
81
|
+
logger.log(...args);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=log-to-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-to-file.js","sourceRoot":"","sources":["../src/log-to-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AA2BlC,MAAM,OAAO,SAAS;IACb,QAAQ,CAAS;IACjB,MAAM,CAAU;IAChB,gBAAgB,CAAU;IAC1B,WAAW,GAAG,KAAK,CAAC;IAE5B,YAAY,OAAyB;QACpC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;QACrC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,IAAI,CAAC;QAEzD,IAAI,OAAO,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;YAChC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,SAAS,CAAC,GAAG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AAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK;QACJ,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC1B,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAC3B,QAAgB,EAChB,OAA4C;IAE5C,OAAO,IAAI,SAAS,CAAC,EAAC,QAAQ,EAAE,GAAG,OAAO,EAAC,CAAC,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAW;IACtC,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC5B,QAAQ,EAAE,gBAAgB;QAC1B,MAAM,EAAE,IAAI;QACZ,gBAAgB,EAAE,IAAI;KACtB,CAAC,CAAC;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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, incremental }?: {
|
|
10
|
+
showCursor?: boolean | undefined;
|
|
11
|
+
incremental?: boolean | undefined;
|
|
12
|
+
}) => LogUpdate;
|
|
13
|
+
};
|
|
14
|
+
export default logUpdate;
|