@reliverse/relinka 1.1.5 → 1.1.7

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 (115) 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 -85
  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 -167
  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 -97
  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 -97
  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 -97
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -23
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -95
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -119
  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 -124
  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 -94
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.js +26 -34
  77. package/dist-npm/components/st-end/start.js +15 -29
  78. package/dist-npm/components/toggle/index.js +137 -113
  79. package/dist-npm/components/visual/animate/animate.js +10 -53
  80. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  81. package/dist-npm/mod.js +2 -1
  82. package/dist-npm/testing/index.js +83 -58
  83. package/dist-npm/types/general.js +1 -0
  84. package/dist-npm/types/index.js +3 -2
  85. package/dist-npm/types/keypress.js +36 -35
  86. package/dist-npm/types/readline.js +1 -0
  87. package/dist-npm/types/relinka.js +1 -0
  88. package/dist-npm/types/utils.js +1 -0
  89. package/dist-npm/utils/box.js +137 -135
  90. package/dist-npm/utils/color.js +74 -65
  91. package/dist-npm/utils/colorize.js +156 -124
  92. package/dist-npm/utils/component.js +657 -532
  93. package/dist-npm/utils/constants.js +63 -64
  94. package/dist-npm/utils/core.js +3 -2
  95. package/dist-npm/utils/decoder.js +223 -244
  96. package/dist-npm/utils/error.js +9 -4
  97. package/dist-npm/utils/errors.js +4 -14
  98. package/dist-npm/utils/format.js +24 -19
  99. package/dist-npm/utils/keypress.js +414 -316
  100. package/dist-npm/utils/log.js +15 -11
  101. package/dist-npm/utils/mapping.js +52 -45
  102. package/dist-npm/utils/messages.js +183 -183
  103. package/dist-npm/utils/platforms.js +20 -16
  104. package/dist-npm/utils/prompt-tmp.js +286 -235
  105. package/dist-npm/utils/prompt-two.js +286 -235
  106. package/dist-npm/utils/readline.js +7 -5
  107. package/dist-npm/utils/skeleton.js +170 -130
  108. package/dist-npm/utils/stream.js +2 -2
  109. package/dist-npm/utils/string.js +58 -44
  110. package/dist-npm/utils/terminal.js +34 -23
  111. package/dist-npm/utils/tree.js +41 -30
  112. package/dist-npm/utils/types.js +1 -0
  113. package/dist-npm/utils/utils.js +8 -8
  114. package/dist-npm/utils/variants.js +44 -36
  115. package/package.json +20 -28
@@ -1,104 +1,124 @@
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";
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
+
12
15
  const numberRegex = /\d+/;
16
+
13
17
  function isSelectableChoice(choice) {
14
- return choice != null && !Separator.isSeparator(choice);
18
+ return choice != null && !Separator.isSeparator(choice);
15
19
  }
20
+
16
21
  function normalizeChoices(choices) {
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
- });
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
+ });
42
50
  }
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("");
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('');
51
57
  const [errorMsg, setError] = useState();
52
58
  const theme = makeTheme(config.theme);
53
- const prefix = usePrefix({ status, theme });
59
+ const prefix = usePrefix({
60
+ status,
61
+ theme,
62
+ });
63
+
54
64
  useKeypress((key, rl) => {
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");
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
+ }
71
84
  } else {
72
- setError(`"${colors.red(value)}" isn't an available option`);
85
+ setValue(rl.line);
86
+ setError(void 0);
73
87
  }
74
- } else {
75
- setValue(rl.line);
76
- setError(void 0);
77
- }
78
88
  });
79
89
  const message = theme.style.message(config.message, status);
80
- if (status === "done") {
81
- return `${prefix} ${message} ${theme.style.answer(value)}`;
90
+
91
+ if (status === 'done') {
92
+ return `${prefix} ${message} ${theme.style.answer(value)}`;
82
93
  }
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 = "";
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
+
94
113
  if (errorMsg) {
95
- error = theme.style.error(errorMsg);
114
+ error = theme.style.error(errorMsg);
96
115
  }
97
- return [
98
- `${prefix} ${message} ${value}`,
99
- [choicesStr, error].filter(Boolean).join("\n")
100
- ];
101
- }
102
- );
116
+
117
+ return [`${prefix} ${message} ${value}`, [choicesStr, error]
118
+ .filter(Boolean)
119
+ .join('\n')];
120
+ });
121
+
103
122
  export default rawlist;
104
- export { Separator } from "../../components/core/index.js";
123
+
124
+ export {Separator} from '../../components/core/index.js';
@@ -1,34 +1,40 @@
1
- import { Type } from "@sinclair/typebox";
2
- import { Value } from "@sinclair/typebox/value";
3
- import { msg } from "../../utils/messages.js";
1
+ import {Type} from '@sinclair/typebox';
2
+ import {Value} from '@sinclair/typebox/value';
3
+ import {msg} from '../../utils/messages.js';
4
+
4
5
  const ResultsSchema = Type.Object({
5
- username: Type.String()
6
+ username: Type.String(),
6
7
  });
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
- }
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
+ }
34
40
  }
@@ -1,186 +1,231 @@
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";
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
+
16
19
  const searchTheme = {
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"
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',
24
29
  };
30
+
25
31
  function isSelectable(item) {
26
- return !Separator.isSeparator(item) && !item.disabled;
32
+ return !Separator.isSeparator(item) && !item.disabled;
27
33
  }
34
+
28
35
  function normalizeChoices(choices) {
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
- });
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
+ });
54
63
  }
55
- const search = createPrompt(
56
- (config, done) => {
57
- const { pageSize = 7, validate = () => true } = config;
64
+
65
+ const search = createPrompt((config, done) => {
66
+ const {pageSize = 7, validate = () => true} = config;
58
67
  const theme = makeTheme(searchTheme, config.theme);
59
68
  const firstRender = useRef(true);
60
- const [status, setStatus] = useState("loading");
61
- const [searchTerm, setSearchTerm] = useState("");
62
- const [searchResults, setSearchResults] = useState(
63
- []
64
- );
69
+ const [status, setStatus] = useState('loading');
70
+ const [searchTerm, setSearchTerm] = useState('');
71
+
72
+ const [searchResults, setSearchResults] = useState([]);
73
+
65
74
  const [searchError, setSearchError] = useState();
66
- const prefix = usePrefix({ status, theme });
75
+ const prefix = usePrefix({
76
+ status,
77
+ theme,
78
+ });
79
+
67
80
  const bounds = useMemo(() => {
68
- const first = searchResults.findIndex(isSelectable);
69
- const last = searchResults.findLastIndex(isSelectable);
70
- return { first, last };
81
+ const first = searchResults.findIndex(isSelectable);
82
+ const last = searchResults.findLastIndex(isSelectable);
83
+
84
+ return {
85
+ first,
86
+ last,
87
+ };
71
88
  }, [searchResults]);
89
+
72
90
  const [active = bounds.first, setActive] = useState();
91
+
73
92
  useEffect(() => {
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
- };
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
+ };
98
119
  }, [searchTerm]);
99
120
  const selectedChoice = searchResults[active];
121
+
100
122
  useKeypress(async (key, rl) => {
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 {
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);
112
142
  rl.write(selectedChoice.name);
113
143
  setSearchTerm(selectedChoice.name);
114
- }
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
+ }
115
155
  } else {
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);
156
+ setSearchTerm(rl.line);
131
157
  }
132
- } else {
133
- setSearchTerm(rl.line);
134
- }
158
+
135
159
  });
136
160
  const message = theme.style.message(config.message, status);
161
+
137
162
  if (active > 0) {
138
- firstRender.current = false;
163
+ firstRender.current = false;
139
164
  }
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)")}`;
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)')}`;
145
172
  }
173
+
146
174
  const page = usePagination({
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
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,
163
194
  });
195
+
164
196
  let error;
197
+
165
198
  if (searchError) {
166
- error = theme.style.error(searchError);
167
- } else if (searchResults.length === 0 && searchTerm !== "" && status === "idle") {
168
- error = theme.style.error("No results found");
199
+ error = theme.style.error(searchError);
200
+ } else if (!searchResults.length && searchTerm !== '' && status === 'idle') {
201
+ error = theme.style.error('No results found');
169
202
  }
203
+
204
+
170
205
  let searchStr;
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);
206
+
207
+ if (status === 'done' && selectedChoice) {
208
+ const answer = selectedChoice.short;
209
+ return `${prefix} ${message} ${theme.style.answer(answer)}`;
176
210
  }
211
+
212
+ searchStr = theme.style.searchTerm(searchTerm);
213
+
177
214
  const choiceDescription = selectedChoice?.description ? `
178
215
  ${theme.style.description(selectedChoice.description)}` : ``;
216
+
179
217
  return [
180
- [prefix, message, searchStr].filter(Boolean).join(" "),
181
- `${error ?? page}${helpTip}${choiceDescription}`
218
+ [
219
+ prefix,
220
+ message,
221
+ searchStr,
222
+ ]
223
+ .filter(Boolean)
224
+ .join(' '),
225
+ `${error ?? page}${helpTip}${choiceDescription}`,
182
226
  ];
183
- }
184
- );
227
+ });
228
+
185
229
  export default search;
186
- export { Separator } from "../../components/core/index.js";
230
+
231
+ export {Separator} from '../../components/core/index.js';