@reliverse/relinka 1.1.4 → 1.1.6

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 (118) hide show
  1. package/dist-npm/components/anykey/index.js +77 -57
  2. package/dist-npm/components/block/block.js +61 -48
  3. package/dist-npm/components/checkbox/index.js +211 -178
  4. package/dist-npm/components/confirm/confirm-main.js +122 -86
  5. package/dist-npm/components/confirm/confirm-three.js +27 -24
  6. package/dist-npm/components/confirm/index.js +45 -36
  7. package/dist-npm/components/core/Separator.js +17 -15
  8. package/dist-npm/components/core/create-prompt.js +124 -101
  9. package/dist-npm/components/core/errors.js +15 -19
  10. package/dist-npm/components/core/hook-engine.js +120 -91
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +6 -16
  13. package/dist-npm/components/core/lines.js +54 -45
  14. package/dist-npm/components/core/make-theme.js +30 -21
  15. package/dist-npm/components/core/position.js +23 -27
  16. package/dist-npm/components/core/promise-polyfill.js +14 -11
  17. package/dist-npm/components/core/screen-manager.js +74 -59
  18. package/dist-npm/components/core/theme.js +32 -22
  19. package/dist-npm/components/core/use-effect.js +15 -9
  20. package/dist-npm/components/core/use-keypress.js +23 -19
  21. package/dist-npm/components/core/use-memo.js +16 -10
  22. package/dist-npm/components/core/use-pagination.js +32 -33
  23. package/dist-npm/components/core/use-prefix.js +38 -40
  24. package/dist-npm/components/core/use-ref.js +5 -2
  25. package/dist-npm/components/core/use-state.js +23 -15
  26. package/dist-npm/components/core/useKeyPress.js +17 -14
  27. package/dist-npm/components/core/usePromptState.js +14 -8
  28. package/dist-npm/components/core/utils.js +16 -7
  29. package/dist-npm/components/date/date.js +204 -168
  30. package/dist-npm/components/editor/index.js +92 -71
  31. package/dist-npm/components/expand/index.js +124 -96
  32. package/dist-npm/components/figures/index.js +294 -283
  33. package/dist-npm/components/input/index.js +87 -61
  34. package/dist-npm/components/input/text-main.js +124 -86
  35. package/dist-npm/components/input/text.js +28 -24
  36. package/dist-npm/components/instance/basic.js +25 -17
  37. package/dist-npm/components/instance/browser.js +18 -14
  38. package/dist-npm/components/instance/reporter/basic.js +65 -46
  39. package/dist-npm/components/instance/reporter/browser.js +47 -44
  40. package/dist-npm/components/instance/reporter/fancy.js +96 -83
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +62 -52
  43. package/dist-npm/components/mono/monoTwo.js +49 -35
  44. package/dist-npm/components/multiselect/group-multiselect.js +71 -55
  45. package/dist-npm/components/multiselect/multi-select-two.js +130 -98
  46. package/dist-npm/components/multiselect/multi-select.js +49 -43
  47. package/dist-npm/components/multiselect/multiselect-main.js +146 -120
  48. package/dist-npm/components/multiselect/num-multi-select.js +130 -98
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -24
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -96
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -120
  55. package/dist-npm/components/password/password-three.js +30 -26
  56. package/dist-npm/components/progressbar/ProgressBar.js +64 -45
  57. package/dist-npm/components/progressbar/helper.js +40 -33
  58. package/dist-npm/components/progressbar/index.js +1 -1
  59. package/dist-npm/components/prompts/create.js +44 -29
  60. package/dist-npm/components/prompts/index.js +45 -45
  61. package/dist-npm/components/prompts/prompt.js +260 -211
  62. package/dist-npm/components/prompts/promptTwo.js +605 -561
  63. package/dist-npm/components/prompts/relinka.js +295 -237
  64. package/dist-npm/components/range/range.js +294 -247
  65. package/dist-npm/components/rawlist/index.js +107 -87
  66. package/dist-npm/components/results/results.js +37 -31
  67. package/dist-npm/components/search/index.js +193 -148
  68. package/dist-npm/components/select/index.js +186 -148
  69. package/dist-npm/components/select/num-select-main.js +27 -27
  70. package/dist-npm/components/select/num-select.js +5 -125
  71. package/dist-npm/components/select/select-key.js +25 -24
  72. package/dist-npm/components/select/select-main.js +133 -109
  73. package/dist-npm/components/select/select-three.js +36 -32
  74. package/dist-npm/components/select/select-two.js +87 -95
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.d.ts +1 -1
  77. package/dist-npm/components/st-end/end.js +26 -35
  78. package/dist-npm/components/st-end/start.d.ts +1 -1
  79. package/dist-npm/components/st-end/start.js +15 -30
  80. package/dist-npm/components/toggle/index.js +137 -113
  81. package/dist-npm/components/visual/animate/animate.js +10 -53
  82. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  83. package/dist-npm/mod.js +2 -1
  84. package/dist-npm/testing/index.js +83 -58
  85. package/dist-npm/types/general.d.ts +2 -1
  86. package/dist-npm/types/general.js +1 -0
  87. package/dist-npm/types/index.js +3 -2
  88. package/dist-npm/types/keypress.js +36 -35
  89. package/dist-npm/types/readline.js +1 -0
  90. package/dist-npm/types/relinka.js +1 -0
  91. package/dist-npm/types/utils.js +1 -0
  92. package/dist-npm/utils/box.js +137 -135
  93. package/dist-npm/utils/color.js +74 -65
  94. package/dist-npm/utils/colorize.js +156 -124
  95. package/dist-npm/utils/component.js +657 -532
  96. package/dist-npm/utils/constants.js +63 -64
  97. package/dist-npm/utils/core.js +3 -2
  98. package/dist-npm/utils/decoder.js +223 -244
  99. package/dist-npm/utils/error.js +9 -4
  100. package/dist-npm/utils/errors.js +4 -14
  101. package/dist-npm/utils/format.js +24 -19
  102. package/dist-npm/utils/keypress.js +414 -316
  103. package/dist-npm/utils/log.js +15 -11
  104. package/dist-npm/utils/mapping.js +52 -45
  105. package/dist-npm/utils/messages.js +183 -183
  106. package/dist-npm/utils/platforms.js +20 -16
  107. package/dist-npm/utils/prompt-tmp.js +286 -235
  108. package/dist-npm/utils/prompt-two.js +286 -235
  109. package/dist-npm/utils/readline.js +7 -5
  110. package/dist-npm/utils/skeleton.js +170 -130
  111. package/dist-npm/utils/stream.js +2 -2
  112. package/dist-npm/utils/string.js +58 -44
  113. package/dist-npm/utils/terminal.js +34 -23
  114. package/dist-npm/utils/tree.js +41 -30
  115. package/dist-npm/utils/types.js +1 -0
  116. package/dist-npm/utils/utils.js +8 -8
  117. package/dist-npm/utils/variants.js +44 -36
  118. package/package.json +20 -28
@@ -1,67 +1,82 @@
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() ?? "";
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
+
6
10
  function cursorDown(n) {
7
- return n > 0 ? ansiEscapes.cursorDown(n) : "";
11
+ return n > 0 ? ansiEscapes.cursorDown(n) : '';
8
12
  }
13
+
9
14
  export default class ScreenManager {
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);
15
+ constructor(rl) {
16
+ this.rl = rl;
17
+ this.rl = rl;
18
+ this.cursorPos = rl.getCursorPos();
30
19
  }
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";
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();
38
28
  }
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);
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);
44
62
  }
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;
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();
57
81
  }
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
- }
67
82
  }
@@ -1,24 +1,34 @@
1
- import colors from "picocolors";
2
- import figures from "../../components/figures/index.js";
1
+ import colors from 'picocolors';
2
+ import figures from '../../components/figures/index.js';
3
+
3
4
  export const defaultTheme = {
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
- }
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
+ },
24
34
  };
@@ -1,11 +1,17 @@
1
- import { withPointer, effectScheduler } from "./hook-engine.js";
1
+ import {
2
+ withPointer,
3
+ effectScheduler,
4
+ } from './hook-engine.js';
5
+
2
6
  export function useEffect(cb, depArray) {
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
- });
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
+ });
11
17
  }
@@ -1,21 +1,25 @@
1
- import { withUpdates } from "./hook-engine.js";
2
- import { useEffect } from "./use-effect.js";
3
- import { useRef } from "./use-ref.js";
1
+ import {withUpdates} from './hook-engine.js';
2
+ import {useEffect} from './use-effect.js';
3
+ import {useRef} from './use-ref.js';
4
+
4
5
  export function useKeypress(userHandler) {
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
- }, []);
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
+ }, []);
21
25
  }
@@ -1,12 +1,18 @@
1
- import { withPointer } from "./hook-engine.js";
1
+ import {withPointer} from './hook-engine.js';
2
+
2
3
  export function useMemo(fn, dependencies) {
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
- });
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
+ });
12
18
  }
@@ -1,34 +1,33 @@
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");
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');
34
33
  }
@@ -1,42 +1,40 @@
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);
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];
35
35
  }
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;
36
+
37
+ const iconName = status === 'loading' ? 'idle' : status;
38
+
39
+ return isString(prefix) ? prefix : prefix[iconName] ?? prefix.idle;
42
40
  }
@@ -1,4 +1,7 @@
1
- import { useState } from "./use-state.js";
1
+ import {useState} from './use-state.js';
2
+
2
3
  export function useRef(val) {
3
- return useState({ current: val })[0];
4
+ return useState({
5
+ current: val,
6
+ })[0];
4
7
  }
@@ -1,17 +1,25 @@
1
- import { withPointer, handleChange } from "./hook-engine.js";
1
+ import {withPointer, handleChange} from './hook-engine.js';
2
+
3
+ const isFn = (a) => typeof a === 'function';
4
+
2
5
  export function useState(defaultValue) {
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
- });
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
+ });
17
25
  }
@@ -1,16 +1,19 @@
1
- import { stdin } from "node:process";
2
- import readline from "node:readline";
1
+ import {stdin} from 'node:process';
2
+ import readline from 'node:readline';
3
+
3
4
  export function useKeyPress(callback) {
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
- };
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
+ };
16
19
  }
@@ -1,10 +1,16 @@
1
- import { useEffect } from "../../components/core/use-effect.js";
2
- import { useState } from "../../components/core/use-state.js";
1
+ import {useEffect} from '../../components/core/use-effect.js';
2
+ import {useState} from '../../components/core/use-state.js';
3
+
3
4
  export function usePromptState(initialState) {
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 };
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
+ };
10
16
  }
@@ -1,11 +1,20 @@
1
- import cliWidth from "cli-width";
2
- import wrapAnsi from "wrap-ansi";
3
- import { readline } from "./hook-engine.js";
1
+ import cliWidth from 'cli-width';
2
+ import wrapAnsi from 'wrap-ansi';
3
+ import {readline} from './hook-engine.js';
4
+
4
5
  export function breakLines(content, width) {
5
- return content.split("\n").flatMap(
6
- (line) => wrapAnsi(line, width, { trim: false, hard: true }).split("\n").map((str) => str.trimEnd())
7
- ).join("\n");
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');
8
13
  }
14
+
9
15
  export function readlineWidth() {
10
- return cliWidth({ defaultWidth: 80, output: readline().output });
16
+ return cliWidth({
17
+ defaultWidth: 80,
18
+ output: readline().output,
19
+ });
11
20
  }