@elench/testkit 0.1.114 → 0.1.115

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 (184) hide show
  1. package/lib/cli/assistant/app.mjs +4 -2
  2. package/lib/cli/assistant/session.mjs +5 -1
  3. package/lib/cli/assistant/state.mjs +1 -2
  4. package/lib/cli/components/blocks/run-tree.mjs +7 -2
  5. package/lib/cli/components/hooks/use-element-layout.mjs +63 -0
  6. package/lib/cli/components/hooks/use-spinner-frame.mjs +26 -0
  7. package/node_modules/@alcalzone/ansi-tokenize/README.md +0 -5
  8. package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.d.ts +8 -0
  9. package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.js +10 -8
  10. package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.js.map +1 -1
  11. package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.d.ts +1 -5
  12. package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.js +9 -45
  13. package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.js.map +1 -1
  14. package/node_modules/@alcalzone/ansi-tokenize/package.json +1 -1
  15. package/node_modules/@elench/next-analysis/package.json +1 -1
  16. package/node_modules/@elench/testkit-bridge/package.json +2 -2
  17. package/node_modules/@elench/testkit-protocol/package.json +1 -1
  18. package/node_modules/@elench/ts-analysis/package.json +1 -1
  19. package/node_modules/cli-boxes/index.d.ts +95 -90
  20. package/node_modules/cli-boxes/index.js +5 -2
  21. package/node_modules/cli-boxes/package.json +6 -13
  22. package/node_modules/cli-boxes/readme.md +15 -3
  23. package/node_modules/cli-truncate/index.d.ts +1 -1
  24. package/node_modules/cli-truncate/package.json +4 -4
  25. package/node_modules/cli-truncate/readme.md +1 -0
  26. package/node_modules/ink/build/apply-styles.js +175 -0
  27. package/node_modules/ink/build/build-layout.js +77 -0
  28. package/node_modules/ink/build/calculate-wrapped-text.js +53 -0
  29. package/node_modules/ink/build/components/App.d.ts +1 -4
  30. package/node_modules/ink/build/components/App.js +22 -142
  31. package/node_modules/ink/build/components/App.js.map +1 -1
  32. package/node_modules/ink/build/components/AppContext.d.ts +3 -23
  33. package/node_modules/ink/build/components/AppContext.js +4 -7
  34. package/node_modules/ink/build/components/AppContext.js.map +1 -1
  35. package/node_modules/ink/build/components/Box.d.ts +3 -16
  36. package/node_modules/ink/build/components/Color.js +62 -0
  37. package/node_modules/ink/build/components/Cursor.d.ts +83 -0
  38. package/node_modules/ink/build/components/Cursor.js +53 -0
  39. package/node_modules/ink/build/components/Cursor.js.map +1 -0
  40. package/node_modules/ink/build/components/ErrorBoundary.d.ts +2 -2
  41. package/node_modules/ink/build/components/ErrorOverview.js +6 -6
  42. package/node_modules/ink/build/components/ErrorOverview.js.map +1 -1
  43. package/node_modules/ink/build/components/Static.js.map +1 -1
  44. package/node_modules/ink/build/components/StdinContext.d.ts +1 -7
  45. package/node_modules/ink/build/components/StdinContext.js +0 -1
  46. package/node_modules/ink/build/components/StdinContext.js.map +1 -1
  47. package/node_modules/ink/build/components/Text.d.ts +1 -1
  48. package/node_modules/ink/build/components/Text.js +1 -1
  49. package/node_modules/ink/build/components/Text.js.map +1 -1
  50. package/node_modules/ink/build/components/Transform.d.ts +1 -1
  51. package/node_modules/ink/build/devtools-window-polyfill.js +4 -7
  52. package/node_modules/ink/build/devtools-window-polyfill.js.map +1 -1
  53. package/node_modules/ink/build/devtools.js +6 -31
  54. package/node_modules/ink/build/devtools.js.map +1 -1
  55. package/node_modules/ink/build/dom.d.ts +1 -5
  56. package/node_modules/ink/build/dom.js +1 -20
  57. package/node_modules/ink/build/dom.js.map +1 -1
  58. package/node_modules/ink/build/experimental/apply-style.js +140 -0
  59. package/node_modules/ink/build/experimental/dom.js +123 -0
  60. package/node_modules/ink/build/experimental/output.js +91 -0
  61. package/node_modules/ink/build/experimental/reconciler.js +141 -0
  62. package/node_modules/ink/build/experimental/renderer.js +81 -0
  63. package/node_modules/ink/build/hooks/use-app.d.ts +1 -1
  64. package/node_modules/ink/build/hooks/use-app.js +1 -1
  65. package/node_modules/ink/build/hooks/use-cursor.d.ts +1 -1
  66. package/node_modules/ink/build/hooks/use-cursor.js +1 -1
  67. package/node_modules/ink/build/hooks/use-focus-manager.d.ts +2 -17
  68. package/node_modules/ink/build/hooks/use-focus-manager.js +1 -2
  69. package/node_modules/ink/build/hooks/use-focus-manager.js.map +1 -1
  70. package/node_modules/ink/build/hooks/use-focus.d.ts +1 -2
  71. package/node_modules/ink/build/hooks/use-focus.js +4 -5
  72. package/node_modules/ink/build/hooks/use-focus.js.map +1 -1
  73. package/node_modules/ink/build/hooks/use-input.d.ts +1 -2
  74. package/node_modules/ink/build/hooks/use-input.js +80 -82
  75. package/node_modules/ink/build/hooks/use-input.js.map +1 -1
  76. package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.d.ts +1 -2
  77. package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.js +1 -2
  78. package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.js.map +1 -1
  79. package/node_modules/ink/build/hooks/use-stderr.d.ts +1 -1
  80. package/node_modules/ink/build/hooks/use-stderr.js +1 -1
  81. package/node_modules/ink/build/hooks/use-stdin.d.ts +2 -4
  82. package/node_modules/ink/build/hooks/use-stdin.js +1 -2
  83. package/node_modules/ink/build/hooks/use-stdin.js.map +1 -1
  84. package/node_modules/ink/build/hooks/use-stdout.d.ts +1 -1
  85. package/node_modules/ink/build/hooks/use-stdout.js +1 -1
  86. package/node_modules/ink/build/hooks/useInput.js +38 -0
  87. package/node_modules/ink/build/index.d.ts +1 -8
  88. package/node_modules/ink/build/index.js +0 -4
  89. package/node_modules/ink/build/index.js.map +1 -1
  90. package/node_modules/ink/build/ink.d.ts +3 -48
  91. package/node_modules/ink/build/ink.js +155 -325
  92. package/node_modules/ink/build/ink.js.map +1 -1
  93. package/node_modules/ink/build/input-parser.d.ts +1 -4
  94. package/node_modules/ink/build/input-parser.js +30 -70
  95. package/node_modules/ink/build/input-parser.js.map +1 -1
  96. package/node_modules/ink/build/instance.js +205 -0
  97. package/node_modules/ink/build/layout.d.ts +7 -0
  98. package/node_modules/ink/build/layout.js +33 -0
  99. package/node_modules/ink/build/layout.js.map +1 -0
  100. package/node_modules/ink/build/log-update.d.ts +0 -1
  101. package/node_modules/ink/build/log-update.js +1 -13
  102. package/node_modules/ink/build/log-update.js.map +1 -1
  103. package/node_modules/ink/build/measure-element.d.ts +0 -4
  104. package/node_modules/ink/build/measure-element.js +0 -4
  105. package/node_modules/ink/build/measure-element.js.map +1 -1
  106. package/node_modules/ink/build/options.d.ts +52 -0
  107. package/node_modules/ink/build/options.js +2 -0
  108. package/node_modules/ink/build/options.js.map +1 -0
  109. package/node_modules/ink/build/output.js +0 -25
  110. package/node_modules/ink/build/output.js.map +1 -1
  111. package/node_modules/ink/build/parse-keypress.d.ts +3 -1
  112. package/node_modules/ink/build/parse-keypress.js +17 -19
  113. package/node_modules/ink/build/parse-keypress.js.map +1 -1
  114. package/node_modules/ink/build/reconciler.js +27 -46
  115. package/node_modules/ink/build/reconciler.js.map +1 -1
  116. package/node_modules/ink/build/render-border.js +18 -29
  117. package/node_modules/ink/build/render-border.js.map +1 -1
  118. package/node_modules/ink/build/render-to-string.js +1 -2
  119. package/node_modules/ink/build/render-to-string.js.map +1 -1
  120. package/node_modules/ink/build/render.d.ts +2 -57
  121. package/node_modules/ink/build/render.js +11 -18
  122. package/node_modules/ink/build/render.js.map +1 -1
  123. package/node_modules/ink/build/screen-reader-update.d.ts +13 -0
  124. package/node_modules/ink/build/screen-reader-update.js +38 -0
  125. package/node_modules/ink/build/screen-reader-update.js.map +1 -0
  126. package/node_modules/ink/build/styles.d.ts +16 -78
  127. package/node_modules/ink/build/styles.js +31 -102
  128. package/node_modules/ink/build/styles.js.map +1 -1
  129. package/node_modules/ink/build/utils.d.ts +2 -9
  130. package/node_modules/ink/build/utils.js +3 -18
  131. package/node_modules/ink/build/utils.js.map +1 -1
  132. package/node_modules/ink/build/wrap-text.js +0 -7
  133. package/node_modules/ink/build/wrap-text.js.map +1 -1
  134. package/node_modules/ink/build/write-synchronized.d.ts +1 -1
  135. package/node_modules/ink/build/write-synchronized.js +2 -4
  136. package/node_modules/ink/build/write-synchronized.js.map +1 -1
  137. package/node_modules/ink/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
  138. package/node_modules/ink/node_modules/emoji-regex/README.md +107 -0
  139. package/node_modules/ink/node_modules/emoji-regex/index.d.ts +3 -0
  140. package/node_modules/ink/node_modules/emoji-regex/index.js +4 -0
  141. package/node_modules/ink/node_modules/emoji-regex/index.mjs +4 -0
  142. package/node_modules/ink/node_modules/emoji-regex/package.json +45 -0
  143. package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/index.d.ts +1 -1
  144. package/node_modules/ink/node_modules/wrap-ansi/index.js +222 -0
  145. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/index.d.ts +39 -0
  146. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/index.js +82 -0
  147. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/license +9 -0
  148. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/package.json +64 -0
  149. package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/readme.md +66 -0
  150. package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/package.json +11 -11
  151. package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/readme.md +0 -2
  152. package/node_modules/ink/package.json +98 -34
  153. package/node_modules/ink/readme.md +48 -554
  154. package/node_modules/slice-ansi/index.d.ts +1 -1
  155. package/node_modules/slice-ansi/index.js +89 -146
  156. package/node_modules/slice-ansi/package.json +5 -5
  157. package/node_modules/slice-ansi/readme.md +0 -1
  158. package/node_modules/slice-ansi/tokenize-ansi.js +1 -1
  159. package/package.json +11 -10
  160. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.d.ts +188 -0
  161. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.d.ts.map +1 -0
  162. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.js +293 -0
  163. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.js.map +1 -0
  164. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/package.json +25 -0
  165. package/node_modules/@alcalzone/ansi-tokenize/build/consts.d.ts +0 -17
  166. package/node_modules/@alcalzone/ansi-tokenize/build/consts.js +0 -28
  167. package/node_modules/@alcalzone/ansi-tokenize/build/consts.js.map +0 -1
  168. package/node_modules/ink/build/components/AnimationContext.d.ts +0 -9
  169. package/node_modules/ink/build/components/AnimationContext.js +0 -13
  170. package/node_modules/ink/build/components/AnimationContext.js.map +0 -1
  171. package/node_modules/ink/build/hooks/use-animation.d.ts +0 -49
  172. package/node_modules/ink/build/hooks/use-animation.js +0 -87
  173. package/node_modules/ink/build/hooks/use-animation.js.map +0 -1
  174. package/node_modules/ink/build/hooks/use-box-metrics.d.ts +0 -59
  175. package/node_modules/ink/build/hooks/use-box-metrics.js +0 -88
  176. package/node_modules/ink/build/hooks/use-box-metrics.js.map +0 -1
  177. package/node_modules/ink/build/hooks/use-paste.d.ts +0 -35
  178. package/node_modules/ink/build/hooks/use-paste.js +0 -62
  179. package/node_modules/ink/build/hooks/use-paste.js.map +0 -1
  180. package/node_modules/ink/build/hooks/use-window-size.d.ts +0 -18
  181. package/node_modules/ink/build/hooks/use-window-size.js +0 -22
  182. package/node_modules/ink/build/hooks/use-window-size.js.map +0 -1
  183. package/node_modules/wrap-ansi/index.js +0 -468
  184. /package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/license +0 -0
@@ -1,88 +0,0 @@
1
- import { useState, useEffect, useCallback, useMemo } from 'react';
2
- import { addLayoutListener } from '../dom.js';
3
- import useStdout from './use-stdout.js';
4
- const emptyMetrics = {
5
- width: 0,
6
- height: 0,
7
- left: 0,
8
- top: 0,
9
- };
10
- const findRootNode = (node) => {
11
- if (!node) {
12
- return undefined;
13
- }
14
- if (!node.parentNode) {
15
- return node.nodeName === 'ink-root' ? node : undefined;
16
- }
17
- return findRootNode(node.parentNode);
18
- };
19
- /**
20
- A React hook that returns the current layout metrics for a tracked box element.
21
- It updates when layout changes (for example terminal resize, sibling/content changes, or position changes).
22
-
23
- The hook returns `{width: 0, height: 0, left: 0, top: 0}` until the first layout pass completes. It also returns zeros when the tracked ref is detached.
24
-
25
- Use `hasMeasured` to detect when the currently tracked element has been measured.
26
-
27
- @example
28
- ```tsx
29
- import {useRef} from 'react';
30
- import {Box, Text, useBoxMetrics} from 'ink';
31
-
32
- const Example = () => {
33
- const ref = useRef(null);
34
- const {width, height, left, top, hasMeasured} = useBoxMetrics(ref);
35
- return (
36
- <Box ref={ref}>
37
- <Text>
38
- {hasMeasured ? `${width}x${height} at ${left},${top}` : 'Measuring...'}
39
- </Text>
40
- </Box>
41
- );
42
- };
43
- ```
44
- */
45
- const useBoxMetrics = (ref) => {
46
- const [metrics, setMetrics] = useState(emptyMetrics);
47
- const [hasMeasured, setHasMeasured] = useState(false);
48
- const { stdout } = useStdout();
49
- const updateMetrics = useCallback(() => {
50
- const layout = ref.current?.yogaNode?.getComputedLayout() ?? emptyMetrics;
51
- setMetrics(previousMetrics => {
52
- const hasChanged = previousMetrics.width !== layout.width ||
53
- previousMetrics.height !== layout.height ||
54
- previousMetrics.left !== layout.left ||
55
- previousMetrics.top !== layout.top;
56
- return hasChanged ? layout : previousMetrics;
57
- });
58
- setHasMeasured(Boolean(ref.current));
59
- }, [ref]);
60
- // Runs after every render of this component.
61
- // This keeps metrics fresh when local state/props in this subtree change.
62
- useEffect(updateMetrics);
63
- // Subscribe to root layout commits so memoized components still receive
64
- // sibling-driven position/size updates, even when they skip re-rendering.
65
- useEffect(() => {
66
- const rootNode = findRootNode(ref.current);
67
- if (!rootNode) {
68
- return;
69
- }
70
- return addLayoutListener(rootNode, updateMetrics);
71
- });
72
- // Terminal resize events do not go through React's render cycle. Ink
73
- // recalculates Yoga layout in its own resize handler — registered in the
74
- // Ink constructor, before this hook mounts — so by the time the resize
75
- // callback runs, Yoga has already computed the post-resize metrics.
76
- useEffect(() => {
77
- stdout.on('resize', updateMetrics);
78
- return () => {
79
- stdout.off('resize', updateMetrics);
80
- };
81
- }, [stdout, updateMetrics]);
82
- return useMemo(() => ({
83
- ...metrics,
84
- hasMeasured,
85
- }), [metrics, hasMeasured]);
86
- };
87
- export default useBoxMetrics;
88
- //# sourceMappingURL=use-box-metrics.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-box-metrics.js","sourceRoot":"","sources":["../../src/hooks/use-box-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAChF,OAAO,EAAkB,iBAAiB,EAAC,MAAM,WAAW,CAAC;AAC7D,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAqCxC,MAAM,YAAY,GAAe;IAChC,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;CACN,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,IAAiB,EAA0B,EAAE;IAClE,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACxD,CAAC;IAED,OAAO,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;EAyBE;AACF,MAAM,aAAa,GAAG,CAAC,GAA0B,EAAuB,EAAE;IACzE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;IACrD,MAAM,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GAAG,EAAE;YACX,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QACrC,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;IAE5B,OAAO,OAAO,CACb,GAAG,EAAE,CAAC,CAAC;QACN,GAAG,OAAO;QACV,WAAW;KACX,CAAC,EACF,CAAC,OAAO,EAAE,WAAW,CAAC,CACtB,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,35 +0,0 @@
1
- type Options = {
2
- /**
3
- Enable or disable the paste handler. Useful when multiple components use `usePaste` and only one should be active at a time.
4
-
5
- @default true
6
- */
7
- isActive?: boolean;
8
- };
9
- /**
10
- A React hook that calls `handler` whenever the user pastes text in the terminal. Bracketed paste mode (`\x1b[?2004h`) is automatically enabled while the hook is active, so pasted text arrives as a single string rather than being misinterpreted as individual key presses.
11
-
12
- `usePaste` and `useInput` can be used together in the same component. They operate on separate event channels, so paste content is never forwarded to `useInput` handlers when `usePaste` is active.
13
-
14
- ```
15
- import {useInput, usePaste} from 'ink';
16
-
17
- const MyInput = () => {
18
- useInput((input, key) => {
19
- // Only receives typed characters and key events, not pasted text.
20
- if (key.return) {
21
- // Submit
22
- }
23
- });
24
-
25
- usePaste((text) => {
26
- // Receives the full pasted string, including newlines.
27
- console.log('Pasted:', text);
28
- });
29
-
30
- return …
31
- };
32
- ```
33
- */
34
- declare const usePaste: (handler: (text: string) => void, options?: Options) => void;
35
- export default usePaste;
@@ -1,62 +0,0 @@
1
- import { useEffect, useEffectEvent } from 'react';
2
- import reconciler from '../reconciler.js';
3
- import { useStdinContext } from './use-stdin.js';
4
- /**
5
- A React hook that calls `handler` whenever the user pastes text in the terminal. Bracketed paste mode (`\x1b[?2004h`) is automatically enabled while the hook is active, so pasted text arrives as a single string rather than being misinterpreted as individual key presses.
6
-
7
- `usePaste` and `useInput` can be used together in the same component. They operate on separate event channels, so paste content is never forwarded to `useInput` handlers when `usePaste` is active.
8
-
9
- ```
10
- import {useInput, usePaste} from 'ink';
11
-
12
- const MyInput = () => {
13
- useInput((input, key) => {
14
- // Only receives typed characters and key events, not pasted text.
15
- if (key.return) {
16
- // Submit
17
- }
18
- });
19
-
20
- usePaste((text) => {
21
- // Receives the full pasted string, including newlines.
22
- console.log('Pasted:', text);
23
- });
24
-
25
- return …
26
- };
27
- ```
28
- */
29
- const usePaste = (handler, options = {}) => {
30
- // eslint-disable-next-line @typescript-eslint/naming-convention
31
- const { setRawMode, setBracketedPasteMode, internal_eventEmitter } = useStdinContext();
32
- useEffect(() => {
33
- if (options.isActive === false) {
34
- return;
35
- }
36
- setRawMode(true);
37
- setBracketedPasteMode(true);
38
- return () => {
39
- setRawMode(false);
40
- setBracketedPasteMode(false);
41
- };
42
- }, [options.isActive, setRawMode, setBracketedPasteMode]);
43
- const handlePaste = useEffectEvent((text) => {
44
- // Use discreteUpdates to assign DiscreteEventPriority to state
45
- // updates triggered by paste, matching the priority of useInput.
46
- // @ts-expect-error Types require 5 arguments (fn, a, b, c, d) but only fn is needed at runtime.
47
- reconciler.discreteUpdates(() => {
48
- handler(text);
49
- });
50
- });
51
- useEffect(() => {
52
- if (options.isActive === false) {
53
- return;
54
- }
55
- internal_eventEmitter.on('paste', handlePaste);
56
- return () => {
57
- internal_eventEmitter.removeListener('paste', handlePaste);
58
- };
59
- }, [options.isActive, internal_eventEmitter]);
60
- };
61
- export default usePaste;
62
- //# sourceMappingURL=use-paste.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-paste.js","sourceRoot":"","sources":["../../src/hooks/use-paste.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,cAAc,EAAC,MAAM,OAAO,CAAC;AAChD,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAW/C;;;;;;;;;;;;;;;;;;;;;;;;EAwBE;AACF,MAAM,QAAQ,GA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**
6
- Number of columns (horizontal character cells).
7
- */
8
- readonly columns: number;
9
- /**
10
- Number of rows (vertical character cells).
11
- */
12
- readonly rows: number;
13
- };
14
- /**
15
- A React hook that returns the current terminal window dimensions and re-renders the component whenever the terminal is resized.
16
- */
17
- declare const useWindowSize: () => WindowSize;
18
- export default useWindowSize;
@@ -1,22 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import { getWindowSize } from '../utils.js';
3
- import useStdout from './use-stdout.js';
4
- /**
5
- A React hook that returns the current terminal window dimensions and re-renders the component whenever the terminal is resized.
6
- */
7
- const useWindowSize = () => {
8
- const { stdout } = useStdout();
9
- const [size, setSize] = useState(() => getWindowSize(stdout));
10
- useEffect(() => {
11
- const onResize = () => {
12
- setSize(getWindowSize(stdout));
13
- };
14
- stdout.on('resize', onResize);
15
- return () => {
16
- stdout.off('resize', onResize);
17
- };
18
- }, [stdout]);
19
- return size;
20
- };
21
- export default useWindowSize;
22
- //# sourceMappingURL=use-window-size.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-window-size.js","sourceRoot":"","sources":["../../src/hooks/use-window-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAiBxC;;EAEE;AACF,MAAM,aAAa,GAAG,GAAe,EAAE;IACtC,MAAM,EAAC,MAAM,EAAC,GAAG,SAAS,EAAE,CAAC;IAC7B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAa,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAE1E,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,QAAQ,GAAG,GAAG,EAAE;YACrB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QAChC,CAAC,CAAC;QAEF,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAE9B,OAAO,GAAG,EAAE;YACX,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}