ink 6.7.0 → 7.0.0

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.
Files changed (132) hide show
  1. package/build/ansi-tokenizer.d.ts +38 -0
  2. package/build/ansi-tokenizer.js +316 -0
  3. package/build/ansi-tokenizer.js.map +1 -0
  4. package/build/components/AnimationContext.d.ts +9 -0
  5. package/build/components/AnimationContext.js +13 -0
  6. package/build/components/AnimationContext.js.map +1 -0
  7. package/build/components/App.d.ts +5 -2
  8. package/build/components/App.js +192 -41
  9. package/build/components/App.js.map +1 -1
  10. package/build/components/AppContext.d.ts +33 -3
  11. package/build/components/AppContext.js +2 -1
  12. package/build/components/AppContext.js.map +1 -1
  13. package/build/components/Box.d.ts +16 -3
  14. package/build/components/ErrorBoundary.d.ts +2 -2
  15. package/build/components/ErrorOverview.js +6 -6
  16. package/build/components/ErrorOverview.js.map +1 -1
  17. package/build/components/Static.js.map +1 -1
  18. package/build/components/StdinContext.d.ts +7 -1
  19. package/build/components/StdinContext.js +1 -0
  20. package/build/components/StdinContext.js.map +1 -1
  21. package/build/components/Text.d.ts +1 -1
  22. package/build/components/Text.js +1 -1
  23. package/build/components/Text.js.map +1 -1
  24. package/build/components/Transform.d.ts +1 -1
  25. package/build/devtools-window-polyfill.js +7 -4
  26. package/build/devtools-window-polyfill.js.map +1 -1
  27. package/build/devtools.js +31 -6
  28. package/build/devtools.js.map +1 -1
  29. package/build/dom.d.ts +5 -1
  30. package/build/dom.js +25 -5
  31. package/build/dom.js.map +1 -1
  32. package/build/hooks/use-animation.d.ts +49 -0
  33. package/build/hooks/use-animation.js +87 -0
  34. package/build/hooks/use-animation.js.map +1 -0
  35. package/build/hooks/use-app.d.ts +5 -2
  36. package/build/hooks/use-app.js +1 -1
  37. package/build/hooks/use-box-metrics.d.ts +59 -0
  38. package/build/hooks/use-box-metrics.js +88 -0
  39. package/build/hooks/use-box-metrics.js.map +1 -0
  40. package/build/hooks/use-cursor.d.ts +1 -1
  41. package/build/hooks/use-cursor.js +1 -1
  42. package/build/hooks/use-focus-manager.d.ts +17 -2
  43. package/build/hooks/use-focus-manager.js +2 -1
  44. package/build/hooks/use-focus-manager.js.map +1 -1
  45. package/build/hooks/use-focus.d.ts +2 -1
  46. package/build/hooks/use-focus.js +5 -4
  47. package/build/hooks/use-focus.js.map +1 -1
  48. package/build/hooks/use-input.d.ts +2 -1
  49. package/build/hooks/use-input.js +82 -80
  50. package/build/hooks/use-input.js.map +1 -1
  51. package/build/hooks/use-is-screen-reader-enabled.d.ts +2 -1
  52. package/build/hooks/use-is-screen-reader-enabled.js +2 -1
  53. package/build/hooks/use-is-screen-reader-enabled.js.map +1 -1
  54. package/build/hooks/use-paste.d.ts +35 -0
  55. package/build/hooks/use-paste.js +62 -0
  56. package/build/hooks/use-paste.js.map +1 -0
  57. package/build/hooks/use-stderr.d.ts +1 -1
  58. package/build/hooks/use-stderr.js +1 -1
  59. package/build/hooks/use-stdin.d.ts +4 -2
  60. package/build/hooks/use-stdin.js +2 -1
  61. package/build/hooks/use-stdin.js.map +1 -1
  62. package/build/hooks/use-stdout.d.ts +1 -1
  63. package/build/hooks/use-stdout.js +1 -1
  64. package/build/hooks/use-window-size.d.ts +18 -0
  65. package/build/hooks/use-window-size.js +22 -0
  66. package/build/hooks/use-window-size.js.map +1 -0
  67. package/build/index.d.ts +10 -1
  68. package/build/index.js +5 -0
  69. package/build/index.js.map +1 -1
  70. package/build/ink.d.ts +55 -6
  71. package/build/ink.js +433 -162
  72. package/build/ink.js.map +1 -1
  73. package/build/input-parser.d.ts +10 -0
  74. package/build/input-parser.js +194 -0
  75. package/build/input-parser.js.map +1 -0
  76. package/build/log-update.d.ts +1 -0
  77. package/build/log-update.js +13 -1
  78. package/build/log-update.js.map +1 -1
  79. package/build/measure-element.d.ts +4 -0
  80. package/build/measure-element.js +4 -0
  81. package/build/measure-element.js.map +1 -1
  82. package/build/output.d.ts +1 -0
  83. package/build/output.js +63 -5
  84. package/build/output.js.map +1 -1
  85. package/build/parse-keypress.d.ts +1 -3
  86. package/build/parse-keypress.js +19 -17
  87. package/build/parse-keypress.js.map +1 -1
  88. package/build/reconciler.js +48 -19
  89. package/build/reconciler.js.map +1 -1
  90. package/build/render-border.js +29 -18
  91. package/build/render-border.js.map +1 -1
  92. package/build/render-to-string.d.ts +38 -0
  93. package/build/render-to-string.js +116 -0
  94. package/build/render-to-string.js.map +1 -0
  95. package/build/render.d.ts +69 -3
  96. package/build/render.js +18 -11
  97. package/build/render.js.map +1 -1
  98. package/build/sanitize-ansi.d.ts +2 -0
  99. package/build/sanitize-ansi.js +27 -0
  100. package/build/sanitize-ansi.js.map +1 -0
  101. package/build/squash-text-nodes.js +2 -1
  102. package/build/squash-text-nodes.js.map +1 -1
  103. package/build/styles.d.ts +78 -16
  104. package/build/styles.js +102 -31
  105. package/build/styles.js.map +1 -1
  106. package/build/utils.d.ts +9 -0
  107. package/build/utils.js +19 -0
  108. package/build/utils.js.map +1 -0
  109. package/build/wrap-text.js +7 -0
  110. package/build/wrap-text.js.map +1 -1
  111. package/build/write-synchronized.d.ts +1 -1
  112. package/build/write-synchronized.js +4 -2
  113. package/build/write-synchronized.js.map +1 -1
  114. package/package.json +40 -101
  115. package/readme.md +674 -56
  116. package/build/apply-styles.js +0 -175
  117. package/build/build-layout.js +0 -77
  118. package/build/calculate-wrapped-text.js +0 -53
  119. package/build/components/Color.js +0 -62
  120. package/build/experimental/apply-style.js +0 -140
  121. package/build/experimental/dom.js +0 -123
  122. package/build/experimental/output.js +0 -91
  123. package/build/experimental/reconciler.js +0 -141
  124. package/build/experimental/renderer.js +0 -81
  125. package/build/hooks/useInput.js +0 -38
  126. package/build/instance.js +0 -205
  127. package/build/options.d.ts +0 -52
  128. package/build/options.js +0 -2
  129. package/build/options.js.map +0 -1
  130. package/build/screen-reader-update.d.ts +0 -13
  131. package/build/screen-reader-update.js +0 -38
  132. package/build/screen-reader-update.js.map +0 -1
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _stringLength = _interopRequireDefault(require("string-length"));
9
-
10
- var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * "Virtual" output class
16
- *
17
- * Handles the positioning and saving of the output of each node in the tree.
18
- * Also responsible for applying transformations to each character of the output.
19
- *
20
- * Used to generate the final output of all nodes before writing it to actual output stream (e.g. stdout)
21
- */
22
- class Output {
23
- constructor({
24
- width,
25
- height
26
- }) {
27
- this.width = width;
28
- this.height = height;
29
- this.writes = []; // Initialize output array with a specific set of rows, so that margin/padding at the bottom is preserved
30
- }
31
-
32
- write(x, y, text, {
33
- transformers
34
- }) {
35
- if (!text) {
36
- return;
37
- }
38
-
39
- this.writes.push({
40
- x,
41
- y,
42
- text,
43
- transformers
44
- });
45
- }
46
-
47
- get() {
48
- const output = [];
49
-
50
- for (let y = 0; y < this.height; y++) {
51
- output.push(' '.repeat(this.width));
52
- }
53
-
54
- for (const write of this.writes) {
55
- const {
56
- x,
57
- y,
58
- text,
59
- transformers
60
- } = write;
61
- const lines = text.split('\n');
62
- let offsetY = 0;
63
-
64
- for (let line of lines) {
65
- const currentLine = output[y + offsetY]; // Line can be missing if `text` is taller than height of pre-initialized `this.output`
66
-
67
- if (!currentLine) {
68
- continue;
69
- }
70
-
71
- const length = (0, _stringLength.default)(line);
72
-
73
- for (const transformer of transformers) {
74
- line = transformer(line);
75
- }
76
-
77
- output[y + offsetY] = (0, _sliceAnsi.default)(currentLine, 0, x) + line + (0, _sliceAnsi.default)(currentLine, x + length);
78
- offsetY++;
79
- }
80
- }
81
-
82
- const generatedOutput = output.map(line => line.trimRight()).join('\n');
83
- return {
84
- output: generatedOutput,
85
- height: output.length
86
- };
87
- }
88
-
89
- }
90
-
91
- exports.default = Output;
@@ -1,141 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _scheduler = require("scheduler");
9
-
10
- var _reactReconciler = _interopRequireDefault(require("react-reconciler"));
11
-
12
- var _dom = require("./dom");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const NO_CONTEXT = true;
17
- const hostConfig = {
18
- schedulePassiveEffects: _scheduler.unstable_scheduleCallback,
19
- cancelPassiveEffects: _scheduler.unstable_cancelCallback,
20
- now: Date.now,
21
- getRootHostContext: () => NO_CONTEXT,
22
- prepareForCommit: () => {},
23
- resetAfterCommit: rootNode => {
24
- // Since renders are throttled at the instance level and <Static> component children
25
- // are rendered only once and then get deleted, we need an escape hatch to
26
- // trigger an immediate render to ensure <Static> children are written to output before they get erased
27
- if (rootNode.isStaticDirty) {
28
- rootNode.isStaticDirty = false;
29
- rootNode.onImmediateRender();
30
- return;
31
- }
32
-
33
- rootNode.onRender();
34
- },
35
- getChildHostContext: () => NO_CONTEXT,
36
- shouldSetTextContent: (type, props) => {
37
- return typeof props.children === 'string' || typeof props.children === 'number';
38
- },
39
- createInstance: (type, newProps) => {
40
- const node = (0, _dom.createNode)(type);
41
-
42
- for (const [key, value] of Object.entries(newProps)) {
43
- if (key === 'children') {
44
- if (typeof value === 'string' || typeof value === 'number') {
45
- if (type === 'div') {
46
- // Text node must be wrapped in another node, so that text can be aligned within container
47
- const textNode = (0, _dom.createNode)('div');
48
- (0, _dom.setTextContent)(textNode, value);
49
- (0, _dom.appendChildNode)(node, textNode);
50
- }
51
-
52
- if (type === 'span') {
53
- (0, _dom.setTextContent)(node, value);
54
- }
55
- }
56
- } else if (key === 'style') {
57
- (0, _dom.setStyle)(node, value);
58
- } else if (key === 'unstable__transformChildren') {
59
- node.unstable__transformChildren = value; // eslint-disable-line camelcase
60
- } else if (key === 'unstable__static') {
61
- node.unstable__static = true; // eslint-disable-line camelcase
62
- } else {
63
- (0, _dom.setAttribute)(node, key, value);
64
- }
65
- }
66
-
67
- return node;
68
- },
69
- createTextInstance: _dom.createTextNode,
70
- resetTextContent: node => {
71
- if (node.textContent) {
72
- node.textContent = '';
73
- }
74
-
75
- if (node.childNodes.length > 0) {
76
- for (const childNode of node.childNodes) {
77
- (0, _dom.removeChildNode)(node, childNode);
78
- }
79
- }
80
- },
81
- getPublicInstance: instance => instance,
82
- appendInitialChild: _dom.appendChildNode,
83
- appendChild: _dom.appendChildNode,
84
- insertBefore: _dom.insertBeforeNode,
85
- finalizeInitialChildren: (node, type, props, rootNode) => {
86
- if (node.unstable__static) {
87
- rootNode.isStaticDirty = true;
88
- }
89
- },
90
- supportsMutation: true,
91
- appendChildToContainer: _dom.appendChildNode,
92
- insertInContainerBefore: _dom.insertBeforeNode,
93
- removeChildFromContainer: _dom.removeChildNode,
94
- prepareUpdate: (node, type, oldProps, newProps, rootNode) => {
95
- if (node.unstable__static) {
96
- rootNode.isStaticDirty = true;
97
- }
98
-
99
- return true;
100
- },
101
- commitUpdate: (node, updatePayload, type, oldProps, newProps) => {
102
- for (const [key, value] of Object.entries(newProps)) {
103
- if (key === 'children') {
104
- if (typeof value === 'string' || typeof value === 'number') {
105
- if (type === 'div') {
106
- // Text node must be wrapped in another node, so that text can be aligned within container
107
- // If there's no such node, a new one must be created
108
- if (node.childNodes.length === 0) {
109
- const textNode = (0, _dom.createNode)('div');
110
- (0, _dom.setTextContent)(textNode, value);
111
- (0, _dom.appendChildNode)(node, textNode);
112
- } else {
113
- (0, _dom.setTextContent)(node.childNodes[0], value);
114
- }
115
- }
116
-
117
- if (type === 'span') {
118
- (0, _dom.setTextContent)(node, value);
119
- }
120
- }
121
- } else if (key === 'style') {
122
- (0, _dom.setStyle)(node, value);
123
- } else if (key === 'unstable__transformChildren') {
124
- node.unstable__transformChildren = value; // eslint-disable-line camelcase
125
- } else if (key === 'unstable__static') {
126
- node.unstable__static = true; // eslint-disable-line camelcase
127
- } else {
128
- (0, _dom.setAttribute)(node, key, value);
129
- }
130
- }
131
- },
132
- commitTextUpdate: (node, oldText, newText) => {
133
- (0, _dom.setTextContent)(node, newText);
134
- },
135
- removeChild: _dom.removeChildNode
136
- };
137
-
138
- var _default = (0, _reactReconciler.default)(hostConfig); // eslint-disable-line new-cap
139
-
140
-
141
- exports.default = _default;
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _yogaLayoutPrebuilt = _interopRequireDefault(require("yoga-layout-prebuilt"));
9
-
10
- var _renderNodeToOutput = _interopRequireDefault(require("../render-node-to-output"));
11
-
12
- var _calculateWrappedText = _interopRequireDefault(require("../calculate-wrapped-text"));
13
-
14
- var _output = _interopRequireDefault(require("./output"));
15
-
16
- var _dom = require("./dom");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- // Since <Static> components can be placed anywhere in the tree, this helper finds and returns them
21
- const findStaticNode = node => {
22
- if (node.unstable__static) {
23
- return node;
24
- }
25
-
26
- for (const childNode of node.childNodes) {
27
- if (childNode.unstable__static) {
28
- return childNode;
29
- }
30
-
31
- if (Array.isArray(childNode.childNodes) && childNode.childNodes.length > 0) {
32
- return findStaticNode(childNode);
33
- }
34
- }
35
- };
36
-
37
- var _default = ({
38
- terminalWidth = 100
39
- }) => {
40
- return node => {
41
- (0, _dom.setStyle)(node, {
42
- width: terminalWidth
43
- });
44
- node.yogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR);
45
- (0, _calculateWrappedText.default)(node);
46
- node.yogaNode.calculateLayout(_yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.UNDEFINED, _yogaLayoutPrebuilt.default.DIRECTION_LTR);
47
- const output = new _output.default({
48
- width: node.yogaNode.getComputedWidth(),
49
- height: node.yogaNode.getComputedHeight()
50
- });
51
- (0, _renderNodeToOutput.default)(node, output, {
52
- skipStaticElements: true
53
- });
54
- const staticNode = findStaticNode(node);
55
- let staticOutput;
56
-
57
- if (staticNode) {
58
- staticOutput = new _output.default({
59
- width: staticNode.yogaNode.getComputedWidth(),
60
- height: staticNode.yogaNode.getComputedHeight()
61
- });
62
- (0, _renderNodeToOutput.default)(staticNode, staticOutput, {
63
- skipStaticElements: false
64
- });
65
- }
66
-
67
- const {
68
- output: generatedOutput,
69
- height: outputHeight
70
- } = output.get();
71
- return {
72
- output: generatedOutput,
73
- outputHeight,
74
- // Newline at the end is needed, because static output doesn't have one, so
75
- // interactive output will override last line of static output
76
- staticOutput: staticOutput ? `${staticOutput.get().output}\n` : undefined
77
- };
78
- };
79
- };
80
-
81
- exports.default = _default;
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = require("react");
9
-
10
- var _ = require("..");
11
-
12
- var _default = inputHandler => {
13
- const {
14
- stdin,
15
- setRawMode
16
- } = (0, _react.useContext)(_.StdinContext);
17
- (0, _react.useLayoutEffect)(() => {
18
- setRawMode(true);
19
- return () => setRawMode(false);
20
- }, [setRawMode]);
21
- (0, _react.useLayoutEffect)(() => {
22
- const handleData = data => {
23
- const input = String(data);
24
- const meta = {
25
- up: input === '\u001B[A',
26
- down: input === '\u001B[B',
27
- left: input === '\u001B[D',
28
- right: input === '\u001B[C'
29
- };
30
- inputHandler(input, meta);
31
- };
32
-
33
- stdin.on('data', handleData);
34
- return () => stdin.off('data', handleData);
35
- }, [stdin, inputHandler]);
36
- };
37
-
38
- exports.default = _default;
package/build/instance.js DELETED
@@ -1,205 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _lodash = _interopRequireDefault(require("lodash.throttle"));
11
-
12
- var _autoBind = _interopRequireDefault(require("auto-bind"));
13
-
14
- var _logUpdate = _interopRequireDefault(require("log-update"));
15
-
16
- var _isCi = _interopRequireDefault(require("is-ci"));
17
-
18
- var _signalExit = _interopRequireDefault(require("signal-exit"));
19
-
20
- var _ansiEscapes = _interopRequireDefault(require("ansi-escapes"));
21
-
22
- var _reconciler = _interopRequireDefault(require("./reconciler"));
23
-
24
- var _reconciler2 = _interopRequireDefault(require("./experimental/reconciler"));
25
-
26
- var _renderer = _interopRequireDefault(require("./renderer"));
27
-
28
- var _renderer2 = _interopRequireDefault(require("./experimental/renderer"));
29
-
30
- var dom = _interopRequireWildcard(require("./dom"));
31
-
32
- var experimentalDom = _interopRequireWildcard(require("./experimental/dom"));
33
-
34
- var _instances = _interopRequireDefault(require("./instances"));
35
-
36
- var _App = _interopRequireDefault(require("./components/App"));
37
-
38
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
39
-
40
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
41
-
42
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
-
44
- class Instance {
45
- constructor(options) {
46
- (0, _autoBind.default)(this);
47
- this.options = options;
48
-
49
- if (options.experimental) {
50
- this.rootNode = experimentalDom.createNode('root');
51
- this.rootNode.onRender = options.debug ? this.onRender : (0, _lodash.default)(this.onRender, 16, {
52
- leading: true,
53
- trailing: true
54
- });
55
- this.rootNode.onImmediateRender = this.onRender;
56
- this.renderer = (0, _renderer2.default)({
57
- terminalWidth: options.stdout.columns
58
- });
59
- } else {
60
- this.rootNode = dom.createNode('root');
61
- this.rootNode.onRender = this.onRender;
62
- this.renderer = (0, _renderer.default)({
63
- terminalWidth: options.stdout.columns
64
- });
65
- }
66
-
67
- this.log = _logUpdate.default.create(options.stdout);
68
- this.throttledLog = options.debug ? this.log : (0, _lodash.default)(this.log, {
69
- leading: true,
70
- trailing: true
71
- }); // Ignore last render after unmounting a tree to prevent empty output before exit
72
-
73
- this.isUnmounted = false; // Store last output to only rerender when needed
74
-
75
- this.lastOutput = ''; // This variable is used only in debug mode to store full static output
76
- // so that it's rerendered every time, not just new static parts, like in non-debug mode
77
-
78
- this.fullStaticOutput = '';
79
-
80
- if (options.experimental) {
81
- this.container = _reconciler2.default.createContainer(this.rootNode, false, false);
82
- } else {
83
- this.container = _reconciler.default.createContainer(this.rootNode, false, false);
84
- }
85
-
86
- this.exitPromise = new Promise((resolve, reject) => {
87
- this.resolveExitPromise = resolve;
88
- this.rejectExitPromise = reject;
89
- }); // Unmount when process exits
90
-
91
- this.unsubscribeExit = (0, _signalExit.default)(this.unmount, {
92
- alwaysLast: false
93
- });
94
- }
95
-
96
- onRender() {
97
- if (this.isUnmounted) {
98
- return;
99
- }
100
-
101
- const {
102
- output,
103
- outputHeight,
104
- staticOutput
105
- } = this.renderer(this.rootNode); // If <Static> output isn't empty, it means new children have been added to it
106
-
107
- const hasStaticOutput = staticOutput && staticOutput !== '\n';
108
-
109
- if (this.options.debug) {
110
- if (hasStaticOutput) {
111
- this.fullStaticOutput += staticOutput;
112
- }
113
-
114
- this.options.stdout.write(this.fullStaticOutput + output);
115
- return;
116
- }
117
-
118
- if (_isCi.default) {
119
- if (hasStaticOutput) {
120
- this.options.stdout.write(staticOutput);
121
- }
122
-
123
- this.lastOutput = output;
124
- return;
125
- }
126
-
127
- if (hasStaticOutput) {
128
- this.fullStaticOutput += staticOutput;
129
- }
130
-
131
- if (this.options.experimental && outputHeight >= this.options.stdout.rows) {
132
- this.options.stdout.write(_ansiEscapes.default.clearTerminal + this.fullStaticOutput + output);
133
- this.lastOutput = output;
134
- return;
135
- } // To ensure static output is cleanly rendered before main output, clear main output first
136
-
137
-
138
- if (hasStaticOutput) {
139
- this.log.clear();
140
- this.options.stdout.write(staticOutput);
141
- }
142
-
143
- if (output !== this.lastOutput) {
144
- if (this.options.experimental) {
145
- this.throttledLog(output);
146
- } else {
147
- this.log(output);
148
- }
149
- }
150
- }
151
-
152
- render(node) {
153
- const tree = _react.default.createElement(_App.default, {
154
- stdin: this.options.stdin,
155
- stdout: this.options.stdout,
156
- exitOnCtrlC: this.options.exitOnCtrlC,
157
- onExit: this.unmount
158
- }, node);
159
-
160
- if (this.options.experimental) {
161
- _reconciler2.default.updateContainer(tree, this.container);
162
- } else {
163
- _reconciler.default.updateContainer(tree, this.container);
164
- }
165
- }
166
-
167
- unmount(error) {
168
- if (this.isUnmounted) {
169
- return;
170
- }
171
-
172
- this.onRender();
173
- this.unsubscribeExit(); // CIs don't handle erasing ansi escapes well, so it's better to
174
- // only render last frame of non-static output
175
-
176
- if (_isCi.default) {
177
- this.options.stdout.write(this.lastOutput + '\n');
178
- } else if (!this.options.debug) {
179
- this.log.done();
180
- }
181
-
182
- this.isUnmounted = true;
183
-
184
- if (this.options.experimental) {
185
- _reconciler2.default.updateContainer(null, this.container);
186
- } else {
187
- _reconciler.default.updateContainer(null, this.container);
188
- }
189
-
190
- _instances.default.delete(this.options.stdout);
191
-
192
- if (error instanceof Error) {
193
- this.rejectExitPromise(error);
194
- } else {
195
- this.resolveExitPromise();
196
- }
197
- }
198
-
199
- waitUntilExit() {
200
- return this.exitPromise;
201
- }
202
-
203
- }
204
-
205
- exports.default = Instance;
@@ -1,52 +0,0 @@
1
- export type CommonOptions = {
2
- /**
3
- * Output stream where app will be rendered.
4
- *
5
- * @default process.stdout
6
- */
7
- stdout?: NodeJS.WriteStream;
8
- /**
9
- * Input stream where app will listen for input.
10
- *
11
- * @default process.stdin
12
- */
13
- stdin?: NodeJS.ReadStream;
14
- /**
15
- * Error stream.
16
- * @default process.stderr
17
- */
18
- stderr?: NodeJS.WriteStream;
19
- /**
20
- * If true, each update will be rendered as a separate output, without replacing the previous one.
21
- *
22
- * @default false
23
- */
24
- debug?: boolean;
25
- /**
26
- * Configure whether Ink should listen to Ctrl+C keyboard input and exit the app. This is needed in case `process.stdin` is in raw mode, because then Ctrl+C is ignored by default and process is expected to handle it manually.
27
- *
28
- * @default true
29
- */
30
- exitOnCtrlC?: boolean;
31
- /**
32
- * Patch console methods to ensure console output doesn't mix with Ink output.
33
- *
34
- * @default true
35
- */
36
- patchConsole?: boolean;
37
- /**
38
- * Enable screen reader support.
39
- * See https://github.com/vadimdemedes/ink/blob/master/readme.md#screen-reader-support
40
- *
41
- * @default process.env['INK_SCREEN_READER'] === 'true'
42
- */
43
- isScreenReaderEnabled?: boolean;
44
- /**
45
- * Maximum frames per second for render updates.
46
- * This controls how frequently the UI can update to prevent excessive re-rendering.
47
- * Higher values allow more frequent updates but may impact performance.
48
- *
49
- * @default 30
50
- */
51
- maxFps?: number;
52
- };
package/build/options.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":""}
@@ -1,13 +0,0 @@
1
- import { type WriteStream } from 'node:tty';
2
- declare class ScreenReaderUpdate {
3
- private readonly stdout;
4
- private readonly stderr;
5
- private previousOutput;
6
- private previousLineCount;
7
- constructor(stdout: WriteStream, stderr: WriteStream);
8
- private wrap;
9
- render(output: string): void;
10
- writeStdout(data: string): void;
11
- writeStderr(data: string): void;
12
- }
13
- export default ScreenReaderUpdate;
@@ -1,38 +0,0 @@
1
- import ansiEscapes from 'ansi-escapes';
2
- import wrapAnsi from 'wrap-ansi';
3
- class ScreenReaderUpdate {
4
- stdout;
5
- stderr;
6
- previousOutput = '';
7
- previousLineCount = 0;
8
- constructor(stdout, stderr) {
9
- this.stdout = stdout;
10
- this.stderr = stderr;
11
- }
12
- wrap(output) {
13
- const width = this.stdout.columns || 80;
14
- return wrapAnsi(output, width, { trim: false, hard: true });
15
- }
16
- render(output) {
17
- const wrapped = this.wrap(output);
18
- if (wrapped === this.previousOutput) {
19
- return;
20
- }
21
- const erase = this.previousLineCount > 0 ? ansiEscapes.eraseLines(this.previousLineCount) : '';
22
- this.stdout.write(erase + wrapped);
23
- this.previousOutput = wrapped;
24
- this.previousLineCount = wrapped === '' ? 0 : wrapped.split('\n').length;
25
- }
26
- writeStdout(data) {
27
- const erase = this.previousLineCount > 0 ? ansiEscapes.eraseLines(this.previousLineCount) : '';
28
- this.stdout.write(erase + data + this.previousOutput);
29
- }
30
- writeStderr(data) {
31
- const erase = this.previousLineCount > 0 ? ansiEscapes.eraseLines(this.previousLineCount) : '';
32
- this.stdout.write(erase);
33
- this.stderr.write(data);
34
- this.stdout.write(this.previousOutput);
35
- }
36
- }
37
- export default ScreenReaderUpdate;
38
- //# sourceMappingURL=screen-reader-update.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"screen-reader-update.js","sourceRoot":"","sources":["../src/screen-reader-update.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,MAAM,kBAAkB;IAKH;IACA;IALX,cAAc,GAAG,EAAE,CAAC;IACpB,iBAAiB,GAAG,CAAC,CAAC;IAE9B,YACmB,MAAmB,EACnB,MAAmB;QADnB,WAAM,GAAN,MAAM,CAAa;QACnB,WAAM,GAAN,MAAM,CAAa;IACnC,CAAC;IAEI,IAAI,CAAC,MAAc;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;QACxC,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,MAAc;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,OAAO,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;YACpC,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC;QAEnC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;QAC9B,IAAI,CAAC,iBAAiB,GAAG,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAC3E,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;IACxD,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACzC,CAAC;CACF;AAED,eAAe,kBAAkB,CAAC"}