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
package/build/ink.d.ts CHANGED
@@ -19,7 +19,7 @@ export type Options = {
19
19
  patchConsole: boolean;
20
20
  onRender?: (metrics: RenderMetrics) => void;
21
21
  isScreenReaderEnabled?: boolean;
22
- waitUntilExit?: () => Promise<void>;
22
+ waitUntilExit?: () => Promise<unknown>;
23
23
  maxFps?: number;
24
24
  incrementalRendering?: boolean;
25
25
  /**
@@ -30,13 +30,45 @@ export type Options = {
30
30
  - `useTransition` and `useDeferredValue` are fully functional
31
31
  - Updates can be interrupted for higher priority work
32
32
 
33
- Note: Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates. The `concurrent` option only takes effect on the first render for a given stdout. If you need to change the rendering mode, call `unmount()` first.
33
+ Note: Concurrent mode changes the timing of renders. Some tests may need to use `act()` to properly await updates. Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change the rendering mode or create a fresh instance.
34
34
 
35
35
  @default false
36
36
  @experimental
37
37
  */
38
38
  concurrent?: boolean;
39
39
  kittyKeyboard?: KittyKeyboardOptions;
40
+ /**
41
+ Override automatic interactive mode detection.
42
+
43
+ By default, Ink detects whether the environment is interactive based on CI detection (via [`is-in-ci`](https://github.com/sindresorhus/is-in-ci)) and `stdout.isTTY`. Most users should not need to set this.
44
+
45
+ When non-interactive, Ink disables ANSI erase sequences, cursor manipulation, synchronized output, resize handling, and kitty keyboard auto-detection, writing only the final frame at unmount.
46
+
47
+ Set to `false` to force non-interactive mode or `true` to force interactive mode when the automatic detection doesn't suit your use case.
48
+
49
+ Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
50
+
51
+ @default true (false if in CI or `stdout.isTTY` is falsy)
52
+
53
+ @see {@link RenderOptions.interactive}
54
+ */
55
+ interactive?: boolean;
56
+ /**
57
+ Render the app in the terminal's alternate screen buffer. When enabled, the app renders on a separate screen, and the original terminal content is restored when the app exits. This is the same mechanism used by programs like vim, htop, and less.
58
+
59
+ Note: The terminal's scrollback buffer is not available while in the alternate screen. This is standard terminal behavior; programs like vim use the alternate screen specifically to avoid polluting the user's scrollback history.
60
+
61
+ Note: Ink intentionally treats alternate-screen teardown output as disposable. It does not preserve or replay teardown-time frames, hook writes, or `console.*` output after restoring the primary screen.
62
+
63
+ Only works in interactive mode. Ignored when `interactive` is `false` or in a non-interactive environment (CI, piped stdout).
64
+
65
+ Note: Reusing the same stdout across multiple `render()` calls without unmounting is unsupported. Call `unmount()` first if you need to change this option or create a fresh instance.
66
+
67
+ @default false
68
+
69
+ @see {@link RenderOptions.alternateScreen}
70
+ */
71
+ alternateScreen?: boolean;
40
72
  };
41
73
  export default class Ink {
42
74
  /**
@@ -48,7 +80,11 @@ export default class Ink {
48
80
  private cursorPosition;
49
81
  private readonly throttledLog;
50
82
  private readonly isScreenReaderEnabled;
83
+ private readonly interactive;
84
+ private readonly renderThrottleMs;
85
+ private alternateScreen;
51
86
  private isUnmounted;
87
+ private isUnmounting;
52
88
  private lastOutput;
53
89
  private lastOutputToRender;
54
90
  private lastOutputHeight;
@@ -56,19 +92,22 @@ export default class Ink {
56
92
  private readonly container;
57
93
  private readonly rootNode;
58
94
  private fullStaticOutput;
59
- private exitPromise?;
95
+ private readonly exitPromise;
96
+ private exitResult;
60
97
  private beforeExitHandler?;
61
98
  private restoreConsole?;
62
99
  private readonly unsubscribeResize?;
63
100
  private readonly throttledOnRender?;
101
+ private hasPendingThrottledRender;
64
102
  private kittyProtocolEnabled;
65
103
  private cancelKittyDetection?;
104
+ private nextRenderCommit?;
66
105
  constructor(options: Options);
67
- getTerminalWidth: () => number;
68
106
  resized: () => void;
69
- resolveExitPromise: () => void;
107
+ resolveExitPromise: (result?: unknown) => void;
70
108
  rejectExitPromise: (reason?: Error) => void;
71
109
  unsubscribeExit: () => void;
110
+ handleAppExit: (errorOrResult?: unknown) => void;
72
111
  setCursorPosition: (position: CursorPosition | undefined) => void;
73
112
  restoreLastOutput: () => void;
74
113
  calculateLayout: () => void;
@@ -77,9 +116,19 @@ export default class Ink {
77
116
  writeToStdout(data: string): void;
78
117
  writeToStderr(data: string): void;
79
118
  unmount(error?: Error | number | null): void;
80
- waitUntilExit(): Promise<void>;
119
+ waitUntilExit(): Promise<unknown>;
120
+ waitUntilRenderFlush(): Promise<void>;
81
121
  clear(): void;
82
122
  patchConsole(): void;
123
+ private setAlternateScreen;
124
+ private resolveInteractiveOption;
125
+ private resolveAlternateScreenOption;
126
+ private shouldSync;
127
+ private writeBestEffort;
128
+ private awaitExit;
129
+ private hasPendingConcurrentWork;
130
+ private awaitNextRender;
131
+ private renderInteractiveFrame;
83
132
  private initKittyKeyboard;
84
133
  private confirmKittySupport;
85
134
  private enableKittyProtocol;