@reliverse/relinka 1.1.7 → 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,124 +1,104 @@
1
- import colors from 'picocolors';
1
+ import colors from "picocolors";
2
2
  import {
3
- createPrompt,
4
- useMemo,
5
- useState,
6
- useKeypress,
7
- usePrefix,
8
- isEnterKey,
9
- Separator,
10
- makeTheme,
11
- } from '../../components/core/index.js';
12
-
13
- const isString = (a) => typeof a === 'string';
14
-
3
+ createPrompt,
4
+ useMemo,
5
+ useState,
6
+ useKeypress,
7
+ usePrefix,
8
+ isEnterKey,
9
+ Separator,
10
+ makeTheme
11
+ } from "../../components/core/index.js";
15
12
  const numberRegex = /\d+/;
16
-
17
13
  function isSelectableChoice(choice) {
18
- return choice != null && !Separator.isSeparator(choice);
14
+ return choice != null && !Separator.isSeparator(choice);
19
15
  }
20
-
21
16
  function normalizeChoices(choices) {
22
- let index = 0;
23
-
24
- return choices.map((choice) => {
25
- if (Separator.isSeparator(choice)) {
26
- return choice;
27
- }
28
-
29
- ++index;
30
- if (isString(choice)) {
31
- return {
32
- value: choice,
33
- name: choice,
34
- short: choice,
35
- key: String(index),
36
- };
37
- }
38
-
39
- const name = choice.name ?? String(choice.value);
40
-
41
- return {
42
- value: choice.value,
43
- name,
44
-
45
- short: choice.short ?? name,
46
-
47
- key: choice.key ?? String(index),
48
- };
49
- });
17
+ let index = 0;
18
+ return choices.map((choice) => {
19
+ if (Separator.isSeparator(choice)) {
20
+ return choice;
21
+ }
22
+ index += 1;
23
+ if (typeof choice === "string") {
24
+ return {
25
+ value: choice,
26
+ name: choice,
27
+ short: choice,
28
+ key: String(index)
29
+ };
30
+ }
31
+ const name = choice.name ?? String(choice.value);
32
+ return {
33
+
34
+ value: choice.value,
35
+ name,
36
+
37
+ short: choice.short ?? name,
38
+
39
+ key: choice.key ?? String(index)
40
+ };
41
+ });
50
42
  }
51
-
52
- const rawlist = createPrompt((config, done) => {
53
- const choices = useMemo(() => normalizeChoices(config.choices), [config.choices]);
54
-
55
- const [status, setStatus] = useState('idle');
56
- const [value, setValue] = useState('');
43
+ const rawlist = createPrompt(
44
+ (config, done) => {
45
+ const choices = useMemo(
46
+ () => normalizeChoices(config.choices),
47
+ [config.choices]
48
+ );
49
+ const [status, setStatus] = useState("idle");
50
+ const [value, setValue] = useState("");
57
51
  const [errorMsg, setError] = useState();
58
52
  const theme = makeTheme(config.theme);
59
- const prefix = usePrefix({
60
- status,
61
- theme,
62
- });
63
-
53
+ const prefix = usePrefix({ status, theme });
64
54
  useKeypress((key, rl) => {
65
- if (isEnterKey(key)) {
66
- let selectedChoice;
67
-
68
- if (numberRegex.test(value)) {
69
- const answer = Number.parseInt(value, 10) - 1;
70
- selectedChoice = choices.filter(isSelectableChoice)[answer];
71
- } else {
72
- selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === value);
73
- }
74
-
75
- if (isSelectableChoice(selectedChoice)) {
76
- setValue(selectedChoice.short);
77
- setStatus('done');
78
- done(selectedChoice.value);
79
- } else if (value === '') {
80
- setError('Please input a value');
81
- } else {
82
- setError(`"${colors.red(value)}" isn't an available option`);
83
- }
55
+ if (isEnterKey(key)) {
56
+ let selectedChoice;
57
+ if (numberRegex.test(value)) {
58
+ const answer = Number.parseInt(value, 10) - 1;
59
+ selectedChoice = choices.filter(isSelectableChoice)[answer];
60
+ } else {
61
+ selectedChoice = choices.find(
62
+ (choice) => isSelectableChoice(choice) && choice.key === value
63
+ );
64
+ }
65
+ if (isSelectableChoice(selectedChoice)) {
66
+ setValue(selectedChoice.short);
67
+ setStatus("done");
68
+ done(selectedChoice.value);
69
+ } else if (value === "") {
70
+ setError("Please input a value");
84
71
  } else {
85
- setValue(rl.line);
86
- setError(void 0);
72
+ setError(`"${colors.red(value)}" isn't an available option`);
87
73
  }
74
+ } else {
75
+ setValue(rl.line);
76
+ setError(void 0);
77
+ }
88
78
  });
89
79
  const message = theme.style.message(config.message, status);
90
-
91
- if (status === 'done') {
92
- return `${prefix} ${message} ${theme.style.answer(value)}`;
80
+ if (status === "done") {
81
+ return `${prefix} ${message} ${theme.style.answer(value)}`;
93
82
  }
94
-
95
- const choicesStr = choices
96
- .map((choice) => {
97
- if (Separator.isSeparator(choice)) {
98
- return ` ${choice.separator}`;
99
- }
100
-
101
- const line = ` ${choice.key}) ${choice.name}`;
102
-
103
- if (choice.key === value.toLowerCase()) {
104
- return theme.style.highlight(line);
105
- }
106
-
107
- return line;
108
- })
109
- .join('\n');
110
-
111
- let error = '';
112
-
83
+ const choicesStr = choices.map((choice) => {
84
+ if (Separator.isSeparator(choice)) {
85
+ return ` ${choice.separator}`;
86
+ }
87
+ const line = ` ${choice.key}) ${choice.name}`;
88
+ if (choice.key === value.toLowerCase()) {
89
+ return theme.style.highlight(line);
90
+ }
91
+ return line;
92
+ }).join("\n");
93
+ let error = "";
113
94
  if (errorMsg) {
114
- error = theme.style.error(errorMsg);
95
+ error = theme.style.error(errorMsg);
115
96
  }
116
-
117
- return [`${prefix} ${message} ${value}`, [choicesStr, error]
118
- .filter(Boolean)
119
- .join('\n')];
120
- });
121
-
97
+ return [
98
+ `${prefix} ${message} ${value}`,
99
+ [choicesStr, error].filter(Boolean).join("\n")
100
+ ];
101
+ }
102
+ );
122
103
  export default rawlist;
123
-
124
- export {Separator} from '../../components/core/index.js';
104
+ export { Separator } from "../../components/core/index.js";
@@ -1,40 +1,34 @@
1
- import {Type} from '@sinclair/typebox';
2
- import {Value} from '@sinclair/typebox/value';
3
- import {msg} from '../../utils/messages.js';
4
-
1
+ import { Type } from "@sinclair/typebox";
2
+ import { Value } from "@sinclair/typebox/value";
3
+ import { msg } from "../../utils/messages.js";
5
4
  const ResultsSchema = Type.Object({
6
- username: Type.String(),
5
+ username: Type.String()
7
6
  });
8
-
9
- export async function promptsDisplayResults({results, inline = true}) {
10
- if (!Value.Check(ResultsSchema, results)) {
11
- throw Error('Invalid results structure.');
12
- }
13
-
14
- const title = 'Your input results:';
15
-
16
- if (inline) {
17
- const formattedResults = Object
18
- .entries(results)
19
- .map(([key, value]) => `${key}: ${value}`)
20
- .join(', ');
21
-
22
- msg({
23
- type: 'M_INFO',
24
- title,
25
- content: formattedResults,
26
- titleColor: 'cyan',
27
- contentColor: 'dim',
28
- });
29
- } else {
30
- const formattedResults = JSON.stringify(results, null, 2);
31
-
32
- msg({
33
- type: 'M_INFO',
34
- title,
35
- content: formattedResults,
36
- titleColor: 'cyan',
37
- contentColor: 'dim',
38
- });
39
- }
7
+ export async function promptsDisplayResults({
8
+ results,
9
+ inline = true
10
+ }) {
11
+ if (!Value.Check(ResultsSchema, results)) {
12
+ throw new Error("Invalid results structure.");
13
+ }
14
+ const title = "Your input results:";
15
+ if (inline) {
16
+ const formattedResults = Object.entries(results).map(([key, value]) => `${key}: ${value}`).join(", ");
17
+ msg({
18
+ type: "M_INFO",
19
+ title,
20
+ content: formattedResults,
21
+ titleColor: "cyan",
22
+ contentColor: "dim"
23
+ });
24
+ } else {
25
+ const formattedResults = JSON.stringify(results, null, 2);
26
+ msg({
27
+ type: "M_INFO",
28
+ title,
29
+ content: formattedResults,
30
+ titleColor: "cyan",
31
+ contentColor: "dim"
32
+ });
33
+ }
40
34
  }
@@ -1,231 +1,186 @@
1
- import colors from 'picocolors';
1
+ import colors from "picocolors";
2
2
  import {
3
- createPrompt,
4
- useState,
5
- useKeypress,
6
- usePrefix,
7
- usePagination,
8
- useRef,
9
- useEffect,
10
- useMemo,
11
- isEnterKey,
12
- Separator,
13
- makeTheme,
14
- } from '../../components/core/index.js';
15
- import figures from '../../components/figures/index.js';
16
-
17
- const isString = (a) => typeof a === 'string';
18
-
3
+ createPrompt,
4
+ useState,
5
+ useKeypress,
6
+ usePrefix,
7
+ usePagination,
8
+ useRef,
9
+ useEffect,
10
+ useMemo,
11
+ isEnterKey,
12
+ Separator,
13
+ makeTheme
14
+ } from "../../components/core/index.js";
15
+ import figures from "../../components/figures/index.js";
19
16
  const searchTheme = {
20
- icon: {
21
- cursor: figures.pointer,
22
- },
23
- style: {
24
- disabled: (text) => colors.dim(`- ${text}`),
25
- searchTerm: (text) => colors.cyan(text),
26
- description: (text) => colors.cyan(text),
27
- },
28
- helpMode: 'auto',
17
+ icon: { cursor: figures.pointer },
18
+ style: {
19
+ disabled: (text) => colors.dim(`- ${text}`),
20
+ searchTerm: (text) => colors.cyan(text),
21
+ description: (text) => colors.cyan(text)
22
+ },
23
+ helpMode: "auto"
29
24
  };
30
-
31
25
  function isSelectable(item) {
32
- return !Separator.isSeparator(item) && !item.disabled;
26
+ return !Separator.isSeparator(item) && !item.disabled;
33
27
  }
34
-
35
28
  function normalizeChoices(choices) {
36
- return choices.map((choice) => {
37
- if (Separator.isSeparator(choice)) {
38
- return choice;
39
- }
40
-
41
- if (isString(choice)) {
42
- return {
43
- value: choice,
44
- name: choice,
45
- short: choice,
46
- disabled: false,
47
- };
48
- }
49
-
50
- const name = choice.name ?? String(choice.value);
51
-
52
- return {
53
- value: choice.value,
54
- name,
55
-
56
- description: choice.description,
57
-
58
- short: choice.short ?? name,
59
-
60
- disabled: choice.disabled ?? false,
61
- };
62
- });
29
+ return choices.map((choice) => {
30
+ if (Separator.isSeparator(choice)) {
31
+ return choice;
32
+ }
33
+ if (typeof choice === "string") {
34
+ return {
35
+ value: choice,
36
+ name: choice,
37
+ short: choice,
38
+ disabled: false
39
+ };
40
+ }
41
+ const name = choice.name ?? String(choice.value);
42
+ return {
43
+
44
+ value: choice.value,
45
+ name,
46
+
47
+ description: choice.description,
48
+
49
+ short: choice.short ?? name,
50
+
51
+ disabled: choice.disabled ?? false
52
+ };
53
+ });
63
54
  }
64
-
65
- const search = createPrompt((config, done) => {
66
- const {pageSize = 7, validate = () => true} = config;
55
+ const search = createPrompt(
56
+ (config, done) => {
57
+ const { pageSize = 7, validate = () => true } = config;
67
58
  const theme = makeTheme(searchTheme, config.theme);
68
59
  const firstRender = useRef(true);
69
- const [status, setStatus] = useState('loading');
70
- const [searchTerm, setSearchTerm] = useState('');
71
-
72
- const [searchResults, setSearchResults] = useState([]);
73
-
60
+ const [status, setStatus] = useState("loading");
61
+ const [searchTerm, setSearchTerm] = useState("");
62
+ const [searchResults, setSearchResults] = useState(
63
+ []
64
+ );
74
65
  const [searchError, setSearchError] = useState();
75
- const prefix = usePrefix({
76
- status,
77
- theme,
78
- });
79
-
66
+ const prefix = usePrefix({ status, theme });
80
67
  const bounds = useMemo(() => {
81
- const first = searchResults.findIndex(isSelectable);
82
- const last = searchResults.findLastIndex(isSelectable);
83
-
84
- return {
85
- first,
86
- last,
87
- };
68
+ const first = searchResults.findIndex(isSelectable);
69
+ const last = searchResults.findLastIndex(isSelectable);
70
+ return { first, last };
88
71
  }, [searchResults]);
89
-
90
72
  const [active = bounds.first, setActive] = useState();
91
-
92
73
  useEffect(() => {
93
- const controller = new AbortController();
94
- setStatus('loading');
95
- setSearchError(void 0);
96
- const fetchResults = async () => {
97
- try {
98
- const results = await config.source(searchTerm || void 0, {
99
- signal: controller.signal,
100
- });
101
-
102
- if (!controller.signal.aborted) {
103
- setActive(void 0);
104
- setSearchError(void 0);
105
- setSearchResults(normalizeChoices(results));
106
- setStatus('idle');
107
- }
108
- } catch(error2) {
109
- if (!controller.signal.aborted && error2 instanceof Error) {
110
- setSearchError(error2.message);
111
- }
112
- }
113
- };
114
-
115
- void fetchResults();
116
- return () => {
117
- controller.abort();
118
- };
74
+ const controller = new AbortController();
75
+ setStatus("loading");
76
+ setSearchError(void 0);
77
+ const fetchResults = async () => {
78
+ try {
79
+ const results = await config.source(searchTerm || void 0, {
80
+ signal: controller.signal
81
+ });
82
+ if (!controller.signal.aborted) {
83
+ setActive(void 0);
84
+ setSearchError(void 0);
85
+ setSearchResults(normalizeChoices(results));
86
+ setStatus("idle");
87
+ }
88
+ } catch (error2) {
89
+ if (!controller.signal.aborted && error2 instanceof Error) {
90
+ setSearchError(error2.message);
91
+ }
92
+ }
93
+ };
94
+ void fetchResults();
95
+ return () => {
96
+ controller.abort();
97
+ };
119
98
  }, [searchTerm]);
120
99
  const selectedChoice = searchResults[active];
121
-
122
100
  useKeypress(async (key, rl) => {
123
- if (isEnterKey(key)) {
124
- if (selectedChoice) {
125
- setStatus('loading');
126
- const isValid = await validate(selectedChoice.value);
127
- setStatus('idle');
128
- if (isValid) {
129
- setStatus('done');
130
- done(selectedChoice.value);
131
- } else if (selectedChoice.name === searchTerm) {
132
- setSearchError(isValid || 'You must provide a valid value');
133
- } else {
134
- rl.write(selectedChoice.name);
135
- setSearchTerm(selectedChoice.name);
136
- }
137
- } else {
138
- rl.write(searchTerm);
139
- }
140
- } else if (key.name === 'tab' && selectedChoice) {
141
- rl.clearLine(0);
101
+ if (isEnterKey(key)) {
102
+ if (selectedChoice) {
103
+ setStatus("loading");
104
+ const isValid = await validate(selectedChoice.value);
105
+ setStatus("idle");
106
+ if (isValid === true) {
107
+ setStatus("done");
108
+ done(selectedChoice.value);
109
+ } else if (selectedChoice.name === searchTerm) {
110
+ setSearchError(isValid || "You must provide a valid value");
111
+ } else {
142
112
  rl.write(selectedChoice.name);
143
113
  setSearchTerm(selectedChoice.name);
144
- } else if (status !== 'loading' && (key.name === 'up' || key.name === 'down')) {
145
- rl.clearLine(0);
146
- if (key.name === 'up' && active !== bounds.first || key.name === 'down' && active !== bounds.last) {
147
- const offset = key.name === 'up' ? -1 : 1;
148
- let next = active;
149
-
150
- do {
151
- next = (next + offset + searchResults.length) % searchResults.length;
152
- } while (!isSelectable(searchResults[next]))
153
- setActive(next);
154
- }
114
+ }
155
115
  } else {
156
- setSearchTerm(rl.line);
116
+ rl.write(searchTerm);
117
+ }
118
+ } else if (key.name === "tab" && selectedChoice) {
119
+ rl.clearLine(0);
120
+ rl.write(selectedChoice.name);
121
+ setSearchTerm(selectedChoice.name);
122
+ } else if (status !== "loading" && (key.name === "up" || key.name === "down")) {
123
+ rl.clearLine(0);
124
+ if (key.name === "up" && active !== bounds.first || key.name === "down" && active !== bounds.last) {
125
+ const offset = key.name === "up" ? -1 : 1;
126
+ let next = active;
127
+ do {
128
+ next = (next + offset + searchResults.length) % searchResults.length;
129
+ } while (!isSelectable(searchResults[next]));
130
+ setActive(next);
157
131
  }
158
-
132
+ } else {
133
+ setSearchTerm(rl.line);
134
+ }
159
135
  });
160
136
  const message = theme.style.message(config.message, status);
161
-
162
137
  if (active > 0) {
163
- firstRender.current = false;
138
+ firstRender.current = false;
164
139
  }
165
-
166
- let helpTip = '';
167
-
168
- if (searchResults.length > 1 && (theme.helpMode === 'always' || theme.helpMode === 'auto' && firstRender.current)) {
169
- helpTip = searchResults.length > pageSize ? `
170
- ${theme.style.help('(Use arrow keys to reveal more choices)')}` : `
171
- ${theme.style.help('(Use arrow keys)')}`;
140
+ let helpTip = "";
141
+ if (searchResults.length > 1 && (theme.helpMode === "always" || theme.helpMode === "auto" && firstRender.current)) {
142
+ helpTip = searchResults.length > pageSize ? `
143
+ ${theme.style.help("(Use arrow keys to reveal more choices)")}` : `
144
+ ${theme.style.help("(Use arrow keys)")}`;
172
145
  }
173
-
174
146
  const page = usePagination({
175
- items: searchResults,
176
- active,
177
- renderItem({item, isActive}) {
178
- if (Separator.isSeparator(item)) {
179
- return ` ${item.separator}`;
180
- }
181
-
182
- if (item.disabled) {
183
- const disabledLabel = isString(item.disabled) ? item.disabled : '(disabled)';
184
- return theme.style.disabled(`${item.name} ${disabledLabel}`);
185
- }
186
-
187
- const color = isActive ? theme.style.highlight : (x) => x;
188
- const cursor = isActive ? theme.icon.cursor : ` `;
189
-
190
- return color(`${cursor} ${item.name}`);
191
- },
192
- pageSize,
193
- loop: false,
147
+ items: searchResults,
148
+ active,
149
+ renderItem({ item, isActive }) {
150
+ if (Separator.isSeparator(item)) {
151
+ return ` ${item.separator}`;
152
+ }
153
+ if (item.disabled) {
154
+ const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
155
+ return theme.style.disabled(`${item.name} ${disabledLabel}`);
156
+ }
157
+ const color = isActive ? theme.style.highlight : (x) => x;
158
+ const cursor = isActive ? theme.icon.cursor : ` `;
159
+ return color(`${cursor} ${item.name}`);
160
+ },
161
+ pageSize,
162
+ loop: false
194
163
  });
195
-
196
164
  let error;
197
-
198
165
  if (searchError) {
199
- error = theme.style.error(searchError);
200
- } else if (!searchResults.length && searchTerm !== '' && status === 'idle') {
201
- error = theme.style.error('No results found');
166
+ error = theme.style.error(searchError);
167
+ } else if (searchResults.length === 0 && searchTerm !== "" && status === "idle") {
168
+ error = theme.style.error("No results found");
202
169
  }
203
-
204
-
205
170
  let searchStr;
206
-
207
- if (status === 'done' && selectedChoice) {
208
- const answer = selectedChoice.short;
209
- return `${prefix} ${message} ${theme.style.answer(answer)}`;
171
+ if (status === "done" && selectedChoice) {
172
+ const answer = selectedChoice.short;
173
+ return `${prefix} ${message} ${theme.style.answer(answer)}`;
174
+ } else {
175
+ searchStr = theme.style.searchTerm(searchTerm);
210
176
  }
211
-
212
- searchStr = theme.style.searchTerm(searchTerm);
213
-
214
177
  const choiceDescription = selectedChoice?.description ? `
215
178
  ${theme.style.description(selectedChoice.description)}` : ``;
216
-
217
179
  return [
218
- [
219
- prefix,
220
- message,
221
- searchStr,
222
- ]
223
- .filter(Boolean)
224
- .join(' '),
225
- `${error ?? page}${helpTip}${choiceDescription}`,
180
+ [prefix, message, searchStr].filter(Boolean).join(" "),
181
+ `${error ?? page}${helpTip}${choiceDescription}`
226
182
  ];
227
- });
228
-
183
+ }
184
+ );
229
185
  export default search;
230
-
231
- export {Separator} from '../../components/core/index.js';
186
+ export { Separator } from "../../components/core/index.js";