@reliverse/relinka 1.1.6 → 1.1.8

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 (121) hide show
  1. package/dist-npm/components/anykey/index.js +57 -77
  2. package/dist-npm/components/block/block.js +48 -61
  3. package/dist-npm/components/checkbox/index.js +178 -211
  4. package/dist-npm/components/confirm/confirm-main.js +85 -122
  5. package/dist-npm/components/confirm/confirm-three.js +24 -27
  6. package/dist-npm/components/confirm/index.js +36 -45
  7. package/dist-npm/components/core/Separator.js +15 -17
  8. package/dist-npm/components/core/create-prompt.js +101 -124
  9. package/dist-npm/components/core/errors.js +19 -15
  10. package/dist-npm/components/core/hook-engine.js +91 -120
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +16 -6
  13. package/dist-npm/components/core/lines.js +45 -54
  14. package/dist-npm/components/core/make-theme.js +21 -30
  15. package/dist-npm/components/core/position.js +27 -23
  16. package/dist-npm/components/core/promise-polyfill.js +11 -14
  17. package/dist-npm/components/core/screen-manager.js +59 -74
  18. package/dist-npm/components/core/theme.js +22 -32
  19. package/dist-npm/components/core/use-effect.js +9 -15
  20. package/dist-npm/components/core/use-keypress.js +19 -23
  21. package/dist-npm/components/core/use-memo.js +10 -16
  22. package/dist-npm/components/core/use-pagination.js +33 -32
  23. package/dist-npm/components/core/use-prefix.js +40 -38
  24. package/dist-npm/components/core/use-ref.js +2 -5
  25. package/dist-npm/components/core/use-state.js +15 -23
  26. package/dist-npm/components/core/useKeyPress.js +14 -17
  27. package/dist-npm/components/core/usePromptState.js +8 -14
  28. package/dist-npm/components/core/utils.js +7 -16
  29. package/dist-npm/components/date/date.js +173 -204
  30. package/dist-npm/components/editor/index.js +71 -92
  31. package/dist-npm/components/expand/index.js +96 -124
  32. package/dist-npm/components/figures/index.js +283 -294
  33. package/dist-npm/components/input/index.js +61 -87
  34. package/dist-npm/components/input/text-main.js +97 -124
  35. package/dist-npm/components/input/text.js +24 -28
  36. package/dist-npm/components/instance/basic.js +17 -25
  37. package/dist-npm/components/instance/browser.js +14 -18
  38. package/dist-npm/components/instance/reporter/basic.js +46 -65
  39. package/dist-npm/components/instance/reporter/browser.js +44 -47
  40. package/dist-npm/components/instance/reporter/fancy.js +83 -96
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +52 -62
  43. package/dist-npm/components/mono/monoTwo.js +35 -49
  44. package/dist-npm/components/multiselect/group-multiselect.js +55 -71
  45. package/dist-npm/components/multiselect/multi-select-two.js +97 -130
  46. package/dist-npm/components/multiselect/multi-select.js +43 -49
  47. package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
  48. package/dist-npm/components/multiselect/multiselect-main.js +158 -145
  49. package/dist-npm/components/multiselect/num-multi-select.js +97 -130
  50. package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
  51. package/dist-npm/components/next-steps/next-steps.js +23 -25
  52. package/dist-npm/components/number/index.js +78 -112
  53. package/dist-npm/components/number/number-main.js +95 -2
  54. package/dist-npm/components/password/index.js +54 -73
  55. package/dist-npm/components/password/password-main.js +119 -2
  56. package/dist-npm/components/password/password-three.js +26 -30
  57. package/dist-npm/components/progressbar/ProgressBar.js +45 -64
  58. package/dist-npm/components/progressbar/helper.js +33 -40
  59. package/dist-npm/components/progressbar/index.js +1 -1
  60. package/dist-npm/components/prompts/create.js +29 -44
  61. package/dist-npm/components/prompts/index.d.ts +1 -0
  62. package/dist-npm/components/prompts/index.js +46 -45
  63. package/dist-npm/components/prompts/prompt.js +211 -260
  64. package/dist-npm/components/prompts/promptTwo.js +561 -605
  65. package/dist-npm/components/prompts/relinka.js +237 -295
  66. package/dist-npm/components/range/range.js +247 -294
  67. package/dist-npm/components/rawlist/index.js +87 -107
  68. package/dist-npm/components/results/results.js +31 -37
  69. package/dist-npm/components/search/index.js +148 -193
  70. package/dist-npm/components/select/index.js +148 -186
  71. package/dist-npm/components/select/num-select-main.js +27 -27
  72. package/dist-npm/components/select/num-select.js +124 -5
  73. package/dist-npm/components/select/select-key.js +24 -25
  74. package/dist-npm/components/select/select-main.d.ts +1 -0
  75. package/dist-npm/components/select/select-main.js +143 -133
  76. package/dist-npm/components/select/select-three.js +32 -36
  77. package/dist-npm/components/select/select-two.js +94 -87
  78. package/dist-npm/components/spinner/index.js +107 -136
  79. package/dist-npm/components/st-end/end.js +34 -26
  80. package/dist-npm/components/st-end/start.js +29 -15
  81. package/dist-npm/components/toggle/index.js +113 -137
  82. package/dist-npm/components/visual/animate/animate.js +53 -10
  83. package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
  84. package/dist-npm/main.js +1 -0
  85. package/dist-npm/testing/index.js +58 -83
  86. package/dist-npm/types/general.d.ts +1 -1
  87. package/dist-npm/types/general.js +0 -1
  88. package/dist-npm/types/index.js +2 -3
  89. package/dist-npm/types/keypress.js +35 -36
  90. package/dist-npm/types/readline.js +0 -1
  91. package/dist-npm/types/relinka.js +0 -1
  92. package/dist-npm/types/utils.js +0 -1
  93. package/dist-npm/utils/box.js +135 -137
  94. package/dist-npm/utils/color.js +65 -74
  95. package/dist-npm/utils/colorize.js +124 -156
  96. package/dist-npm/utils/component.js +532 -657
  97. package/dist-npm/utils/constants.js +64 -63
  98. package/dist-npm/utils/core.js +2 -3
  99. package/dist-npm/utils/decoder.js +244 -223
  100. package/dist-npm/utils/error.js +4 -9
  101. package/dist-npm/utils/errors.js +14 -4
  102. package/dist-npm/utils/format.js +19 -24
  103. package/dist-npm/utils/keypress.js +316 -414
  104. package/dist-npm/utils/log.js +11 -15
  105. package/dist-npm/utils/mapping.js +45 -52
  106. package/dist-npm/utils/messages.js +196 -183
  107. package/dist-npm/utils/platforms.js +16 -20
  108. package/dist-npm/utils/prompt-tmp.js +235 -286
  109. package/dist-npm/utils/prompt-two.js +235 -286
  110. package/dist-npm/utils/readline.js +5 -7
  111. package/dist-npm/utils/skeleton.js +130 -170
  112. package/dist-npm/utils/stream.js +2 -2
  113. package/dist-npm/utils/string.js +44 -58
  114. package/dist-npm/utils/terminal.js +23 -34
  115. package/dist-npm/utils/tree.js +30 -41
  116. package/dist-npm/utils/types.js +0 -1
  117. package/dist-npm/utils/utils.js +8 -8
  118. package/dist-npm/utils/variants.js +36 -44
  119. package/package.json +14 -14
  120. package/dist-npm/mod.js +0 -2
  121. /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
@@ -1,82 +1,67 @@
1
- import ansiEscapes from 'ansi-escapes';
2
- import stripAnsi from 'strip-ansi';
3
- import {breakLines, readlineWidth} from './utils.js';
4
-
5
- const height = (content) => content.split('\n').length;
6
- const lastLine = (content) => content
7
- .split('\n')
8
- .pop() ?? '';
9
-
1
+ import ansiEscapes from "ansi-escapes";
2
+ import stripAnsi from "strip-ansi";
3
+ import { breakLines, readlineWidth } from "./utils.js";
4
+ const height = (content) => content.split("\n").length;
5
+ const lastLine = (content) => content.split("\n").pop() ?? "";
10
6
  function cursorDown(n) {
11
- return n > 0 ? ansiEscapes.cursorDown(n) : '';
7
+ return n > 0 ? ansiEscapes.cursorDown(n) : "";
12
8
  }
13
-
14
9
  export default class ScreenManager {
15
- constructor(rl) {
16
- this.rl = rl;
17
- this.rl = rl;
18
- this.cursorPos = rl.getCursorPos();
10
+ constructor(rl) {
11
+ this.rl = rl;
12
+ this.rl = rl;
13
+ this.cursorPos = rl.getCursorPos();
14
+ }
15
+ // These variables are keeping information to allow correct prompt re-rendering
16
+ height = 0;
17
+ extraLinesUnderPrompt = 0;
18
+ cursorPos;
19
+ write(content) {
20
+ this.rl.output.unmute();
21
+ this.rl.output.write(content);
22
+ this.rl.output.mute();
23
+ }
24
+ render(content, bottomContent = "") {
25
+ const promptLine = lastLine(content);
26
+ const rawPromptLine = stripAnsi(promptLine);
27
+ let prompt = rawPromptLine;
28
+ if (this.rl.line.length > 0) {
29
+ prompt = prompt.slice(0, -this.rl.line.length);
19
30
  }
20
- // These variables are keeping information to allow correct prompt re-rendering
21
- height = 0;
22
- extraLinesUnderPrompt = 0;
23
- cursorPos;
24
- write(content) {
25
- this.rl.output.unmute();
26
- this.rl.output.write(content);
27
- this.rl.output.mute();
31
+ this.rl.setPrompt(prompt);
32
+ this.cursorPos = this.rl.getCursorPos();
33
+ const width = readlineWidth();
34
+ content = breakLines(content, width);
35
+ bottomContent = breakLines(bottomContent, width);
36
+ if (rawPromptLine.length % width === 0) {
37
+ content += "\n";
28
38
  }
29
-
30
- render(content, bottomContent = '') {
31
- const promptLine = lastLine(content);
32
- const rawPromptLine = stripAnsi(promptLine);
33
- let prompt = rawPromptLine;
34
-
35
- if (this.rl.line.length > 0) {
36
- prompt = prompt.slice(0, -this.rl.line.length);
37
- }
38
-
39
- this.rl.setPrompt(prompt);
40
- this.cursorPos = this.rl.getCursorPos();
41
- const width = readlineWidth();
42
-
43
- content = breakLines(content, width);
44
- bottomContent = breakLines(bottomContent, width);
45
- if (!(rawPromptLine.length % width)) {
46
- content += '\n';
47
- }
48
-
49
- let output = content + (bottomContent ? `
50
- ${bottomContent}` : '');
51
- const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
52
- const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
53
-
54
- if (bottomContentHeight > 0) {
55
- output += ansiEscapes.cursorUp(bottomContentHeight);
56
- }
57
-
58
- output += ansiEscapes.cursorTo(this.cursorPos.cols);
59
- this.write(cursorDown(this.extraLinesUnderPrompt) + ansiEscapes.eraseLines(this.height) + output);
60
- this.extraLinesUnderPrompt = bottomContentHeight;
61
- this.height = height(output);
39
+ let output = content + (bottomContent ? "\n" + bottomContent : "");
40
+ const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
41
+ const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
42
+ if (bottomContentHeight > 0) {
43
+ output += ansiEscapes.cursorUp(bottomContentHeight);
62
44
  }
63
-
64
- checkCursorPos() {
65
- const cursorPos = this.rl.getCursorPos();
66
-
67
- if (cursorPos.cols !== this.cursorPos.cols) {
68
- this.write(ansiEscapes.cursorTo(cursorPos.cols));
69
- this.cursorPos = cursorPos;
70
- }
71
- }
72
-
73
- done({clearContent}) {
74
- this.rl.setPrompt('');
75
- let output = cursorDown(this.extraLinesUnderPrompt);
76
-
77
- output += clearContent ? ansiEscapes.eraseLines(this.height) : '\n';
78
- output += ansiEscapes.cursorShow;
79
- this.write(output);
80
- this.rl.close();
45
+ output += ansiEscapes.cursorTo(this.cursorPos.cols);
46
+ this.write(
47
+ cursorDown(this.extraLinesUnderPrompt) + ansiEscapes.eraseLines(this.height) + output
48
+ );
49
+ this.extraLinesUnderPrompt = bottomContentHeight;
50
+ this.height = height(output);
51
+ }
52
+ checkCursorPos() {
53
+ const cursorPos = this.rl.getCursorPos();
54
+ if (cursorPos.cols !== this.cursorPos.cols) {
55
+ this.write(ansiEscapes.cursorTo(cursorPos.cols));
56
+ this.cursorPos = cursorPos;
81
57
  }
58
+ }
59
+ done({ clearContent }) {
60
+ this.rl.setPrompt("");
61
+ let output = cursorDown(this.extraLinesUnderPrompt);
62
+ output += clearContent ? ansiEscapes.eraseLines(this.height) : "\n";
63
+ output += ansiEscapes.cursorShow;
64
+ this.write(output);
65
+ this.rl.close();
66
+ }
82
67
  }
@@ -1,34 +1,24 @@
1
- import colors from 'picocolors';
2
- import figures from '../../components/figures/index.js';
3
-
1
+ import colors from "picocolors";
2
+ import figures from "../../components/figures/index.js";
4
3
  export const defaultTheme = {
5
- prefix: {
6
- idle: colors.blue('?'),
7
-
8
- done: colors.green(figures.tick),
9
- },
10
- spinner: {
11
- interval: 80,
12
- frames: [
13
- '\u280B',
14
- '\u2819',
15
- '\u2839',
16
- '\u2838',
17
- '\u283C',
18
- '\u2834',
19
- '\u2826',
20
- '\u2827',
21
- '\u2807',
22
- '\u280F',
23
- ].map((frame) => colors.yellow(frame)),
24
- },
25
- style: {
26
- answer: colors.cyan,
27
- message: colors.bold,
28
- error: (text) => colors.red(`> ${text}`),
29
- defaultAnswer: (text) => colors.dim(`(${text})`),
30
- help: colors.dim,
31
- highlight: colors.cyan,
32
- key: (text) => colors.cyan(colors.bold(`<${text}>`)),
33
- },
4
+ prefix: {
5
+ idle: colors.blue("?"),
6
+
7
+ done: colors.green(figures.tick)
8
+ },
9
+ spinner: {
10
+ interval: 80,
11
+ frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"].map(
12
+ (frame) => colors.yellow(frame)
13
+ )
14
+ },
15
+ style: {
16
+ answer: colors.cyan,
17
+ message: colors.bold,
18
+ error: (text) => colors.red(`> ${text}`),
19
+ defaultAnswer: (text) => colors.dim(`(${text})`),
20
+ help: colors.dim,
21
+ highlight: colors.cyan,
22
+ key: (text) => colors.cyan(colors.bold(`<${text}>`))
23
+ }
34
24
  };
@@ -1,17 +1,11 @@
1
- import {
2
- withPointer,
3
- effectScheduler,
4
- } from './hook-engine.js';
5
-
1
+ import { withPointer, effectScheduler } from "./hook-engine.js";
6
2
  export function useEffect(cb, depArray) {
7
- withPointer((pointer) => {
8
- const oldDeps = pointer.get();
9
- const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
10
-
11
- if (hasChanged) {
12
- effectScheduler.queue(cb);
13
- }
14
-
15
- pointer.set(depArray);
16
- });
3
+ withPointer((pointer) => {
4
+ const oldDeps = pointer.get();
5
+ const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
6
+ if (hasChanged) {
7
+ effectScheduler.queue(cb);
8
+ }
9
+ pointer.set(depArray);
10
+ });
17
11
  }
@@ -1,25 +1,21 @@
1
- import {withUpdates} from './hook-engine.js';
2
- import {useEffect} from './use-effect.js';
3
- import {useRef} from './use-ref.js';
4
-
1
+ import { withUpdates } from "./hook-engine.js";
2
+ import { useEffect } from "./use-effect.js";
3
+ import { useRef } from "./use-ref.js";
5
4
  export function useKeypress(userHandler) {
6
- const signal = useRef(userHandler);
7
-
8
- signal.current = userHandler;
9
- useEffect((rl) => {
10
- let ignore = false;
11
- const handler = withUpdates((_input, event) => {
12
- if (ignore) {
13
- return;
14
- }
15
-
16
- void signal.current(event, rl);
17
- });
18
-
19
- rl.input.on('keypress', handler);
20
- return () => {
21
- ignore = true;
22
- rl.input.removeListener('keypress', handler);
23
- };
24
- }, []);
5
+ const signal = useRef(userHandler);
6
+ signal.current = userHandler;
7
+ useEffect((rl) => {
8
+ let ignore = false;
9
+ const handler = withUpdates((_input, event) => {
10
+ if (ignore) {
11
+ return;
12
+ }
13
+ void signal.current(event, rl);
14
+ });
15
+ rl.input.on("keypress", handler);
16
+ return () => {
17
+ ignore = true;
18
+ rl.input.removeListener("keypress", handler);
19
+ };
20
+ }, []);
25
21
  }
@@ -1,18 +1,12 @@
1
- import {withPointer} from './hook-engine.js';
2
-
1
+ import { withPointer } from "./hook-engine.js";
3
2
  export function useMemo(fn, dependencies) {
4
- return withPointer((pointer) => {
5
- const prev = pointer.get();
6
-
7
- if (!prev || prev.dependencies.length !== dependencies.length || prev.dependencies.some((dep, i) => dep !== dependencies[i])) {
8
- const value = fn();
9
- pointer.set({
10
- value,
11
- dependencies,
12
- });
13
- return value;
14
- }
15
-
16
- return prev.value;
17
- });
3
+ return withPointer((pointer) => {
4
+ const prev = pointer.get();
5
+ if (!prev || prev.dependencies.length !== dependencies.length || prev.dependencies.some((dep, i) => dep !== dependencies[i])) {
6
+ const value = fn();
7
+ pointer.set({ value, dependencies });
8
+ return value;
9
+ }
10
+ return prev.value;
11
+ });
18
12
  }
@@ -1,33 +1,34 @@
1
- import {lines} from './lines.js';
2
- import {finite, infinite} from './position.js';
3
- import {useRef} from './use-ref.js';
4
- import {readlineWidth} from './utils.js';
5
-
6
- export function usePagination({items, active, renderItem, pageSize, loop = true}) {
7
- const state = useRef({
8
- position: 0,
9
- lastActive: 0,
10
- });
11
- const position = loop ? infinite({
12
- active,
13
- lastActive: state.current.lastActive,
14
- total: items.length,
15
- pageSize,
16
- pointer: state.current.position,
17
- }) : finite({
18
- active,
19
- total: items.length,
20
- pageSize,
21
- });
22
-
23
- state.current.position = position;
24
- state.current.lastActive = active;
25
- return lines({
26
- items,
27
- width: readlineWidth(),
28
- renderItem,
29
- active,
30
- position,
31
- pageSize,
32
- }).join('\n');
1
+ import { lines } from "./lines.js";
2
+ import { finite, infinite } from "./position.js";
3
+ import { useRef } from "./use-ref.js";
4
+ import { readlineWidth } from "./utils.js";
5
+ export function usePagination({
6
+ items,
7
+ active,
8
+ renderItem,
9
+ pageSize,
10
+ loop = true
11
+ }) {
12
+ const state = useRef({ position: 0, lastActive: 0 });
13
+ const position = loop ? infinite({
14
+ active,
15
+ lastActive: state.current.lastActive,
16
+ total: items.length,
17
+ pageSize,
18
+ pointer: state.current.position
19
+ }) : finite({
20
+ active,
21
+ total: items.length,
22
+ pageSize
23
+ });
24
+ state.current.position = position;
25
+ state.current.lastActive = active;
26
+ return lines({
27
+ items,
28
+ width: readlineWidth(),
29
+ renderItem,
30
+ active,
31
+ position,
32
+ pageSize
33
+ }).join("\n");
33
34
  }
@@ -1,40 +1,42 @@
1
- import {AsyncResource} from 'node:async_hooks';
2
- import {makeTheme} from './make-theme.js';
3
- import {useEffect} from './use-effect.js';
4
- import {useState} from './use-state.js';
5
-
6
- const isString = (a) => typeof a === 'string';
7
-
8
- export function usePrefix({status = 'idle', theme}) {
9
- const [showLoader, setShowLoader] = useState(false);
10
- const [tick, setTick] = useState(0);
11
- const {prefix, spinner} = makeTheme(theme);
12
-
13
- useEffect(() => {
14
- if (status === 'loading') {
15
- let tickInterval;
16
- let inc = -1;
17
- const delayTimeout = setTimeout(AsyncResource.bind(() => {
18
- setShowLoader(true);
19
- tickInterval = setInterval(AsyncResource.bind(() => {
20
- ++inc;
21
- setTick(inc % spinner.frames.length);
22
- }), spinner.interval);
23
- }), 300);
24
-
25
- return () => {
26
- clearTimeout(delayTimeout);
27
- clearInterval(tickInterval);
28
- };
29
- }
30
-
31
- setShowLoader(false);
32
- }, [status]);
33
- if (showLoader) {
34
- return spinner.frames[tick];
1
+ import { AsyncResource } from "node:async_hooks";
2
+ import { makeTheme } from "./make-theme.js";
3
+ import { useEffect } from "./use-effect.js";
4
+ import { useState } from "./use-state.js";
5
+ export function usePrefix({
6
+ status = "idle",
7
+ theme
8
+ }) {
9
+ const [showLoader, setShowLoader] = useState(false);
10
+ const [tick, setTick] = useState(0);
11
+ const { prefix, spinner } = makeTheme(theme);
12
+ useEffect(() => {
13
+ if (status === "loading") {
14
+ let tickInterval;
15
+ let inc = -1;
16
+ const delayTimeout = setTimeout(
17
+ AsyncResource.bind(() => {
18
+ setShowLoader(true);
19
+ tickInterval = setInterval(
20
+ AsyncResource.bind(() => {
21
+ inc = inc + 1;
22
+ setTick(inc % spinner.frames.length);
23
+ }),
24
+ spinner.interval
25
+ );
26
+ }),
27
+ 300
28
+ );
29
+ return () => {
30
+ clearTimeout(delayTimeout);
31
+ clearInterval(tickInterval);
32
+ };
33
+ } else {
34
+ setShowLoader(false);
35
35
  }
36
-
37
- const iconName = status === 'loading' ? 'idle' : status;
38
-
39
- return isString(prefix) ? prefix : prefix[iconName] ?? prefix.idle;
36
+ }, [status]);
37
+ if (showLoader) {
38
+ return spinner.frames[tick];
39
+ }
40
+ const iconName = status === "loading" ? "idle" : status;
41
+ return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix.idle;
40
42
  }
@@ -1,7 +1,4 @@
1
- import {useState} from './use-state.js';
2
-
1
+ import { useState } from "./use-state.js";
3
2
  export function useRef(val) {
4
- return useState({
5
- current: val,
6
- })[0];
3
+ return useState({ current: val })[0];
7
4
  }
@@ -1,25 +1,17 @@
1
- import {withPointer, handleChange} from './hook-engine.js';
2
-
3
- const isFn = (a) => typeof a === 'function';
4
-
1
+ import { withPointer, handleChange } from "./hook-engine.js";
5
2
  export function useState(defaultValue) {
6
- return withPointer((pointer) => {
7
- const setFn = (newValue) => {
8
- if (pointer.get() !== newValue) {
9
- pointer.set(newValue);
10
- handleChange();
11
- }
12
- };
13
-
14
- if (pointer.initialized) {
15
- return [
16
- pointer.get(),
17
- setFn,
18
- ];
19
- }
20
-
21
- const value = isFn(defaultValue) ? defaultValue() : defaultValue;
22
- pointer.set(value);
23
- return [value, setFn];
24
- });
3
+ return withPointer((pointer) => {
4
+ const setFn = (newValue) => {
5
+ if (pointer.get() !== newValue) {
6
+ pointer.set(newValue);
7
+ handleChange();
8
+ }
9
+ };
10
+ if (pointer.initialized) {
11
+ return [pointer.get(), setFn];
12
+ }
13
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
14
+ pointer.set(value);
15
+ return [value, setFn];
16
+ });
25
17
  }
@@ -1,19 +1,16 @@
1
- import {stdin} from 'node:process';
2
- import readline from 'node:readline';
3
-
1
+ import { stdin } from "node:process";
2
+ import readline from "node:readline";
4
3
  export function useKeyPress(callback) {
5
- readline.emitKeypressEvents(stdin);
6
- if (stdin.isTTY) {
7
- stdin.setRawMode(true);
8
- }
9
-
10
- const onKeypress = (str, key) => {
11
- callback(str, key);
12
- };
13
-
14
- stdin.on('keypress', onKeypress);
15
- return () => {
16
- stdin.setRawMode(false);
17
- stdin.off('keypress', onKeypress);
18
- };
4
+ readline.emitKeypressEvents(stdin);
5
+ if (stdin.isTTY) {
6
+ stdin.setRawMode(true);
7
+ }
8
+ const onKeypress = (str, key) => {
9
+ callback(str, key);
10
+ };
11
+ stdin.on("keypress", onKeypress);
12
+ return () => {
13
+ stdin.setRawMode(false);
14
+ stdin.off("keypress", onKeypress);
15
+ };
19
16
  }
@@ -1,16 +1,10 @@
1
- import {useEffect} from '../../components/core/use-effect.js';
2
- import {useState} from '../../components/core/use-state.js';
3
-
1
+ import { useEffect } from "../../components/core/use-effect.js";
2
+ import { useState } from "../../components/core/use-state.js";
4
3
  export function usePromptState(initialState) {
5
- const [state, setState] = useState(initialState);
6
- const [figure, setFigure] = useState('\u{1F7E2}');
7
-
8
- useEffect(() => {
9
- setFigure('\u{1F7E2}');
10
- }, [state]);
11
- return {
12
- state,
13
- setState,
14
- figure,
15
- };
4
+ const [state, setState] = useState(initialState);
5
+ const [figure, setFigure] = useState("\u{1F7E2}");
6
+ useEffect(() => {
7
+ setFigure("\u{1F7E2}");
8
+ }, [state]);
9
+ return { state, setState, figure };
16
10
  }
@@ -1,20 +1,11 @@
1
- import cliWidth from 'cli-width';
2
- import wrapAnsi from 'wrap-ansi';
3
- import {readline} from './hook-engine.js';
4
-
1
+ import cliWidth from "cli-width";
2
+ import wrapAnsi from "wrap-ansi";
3
+ import { readline } from "./hook-engine.js";
5
4
  export function breakLines(content, width) {
6
- return content
7
- .split('\n')
8
- .flatMap((line) => wrapAnsi(line, width, {
9
- trim: false,
10
- hard: true,
11
- }).split('\n').map((str) => str.trimEnd()))
12
- .join('\n');
5
+ return content.split("\n").flatMap(
6
+ (line) => wrapAnsi(line, width, { trim: false, hard: true }).split("\n").map((str) => str.trimEnd())
7
+ ).join("\n");
13
8
  }
14
-
15
9
  export function readlineWidth() {
16
- return cliWidth({
17
- defaultWidth: 80,
18
- output: readline().output,
19
- });
10
+ return cliWidth({ defaultWidth: 80, output: readline().output });
20
11
  }