@reliverse/rempts 1.7.44 → 1.7.46

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 (134) hide show
  1. package/README.md +1 -1
  2. package/dist-npm/bin/mod.d.mts +2333 -0
  3. package/dist-npm/bin/mod.mjs +8310 -0
  4. package/package.json +82 -42
  5. package/bin/libs/animate/animate-mod.d.ts +0 -14
  6. package/bin/libs/animate/animate-mod.js +0 -62
  7. package/bin/libs/anykey/anykey-mod.d.ts +0 -12
  8. package/bin/libs/anykey/anykey-mod.js +0 -125
  9. package/bin/libs/cancel/cancel.d.ts +0 -45
  10. package/bin/libs/cancel/cancel.js +0 -72
  11. package/bin/libs/confirm/confirm-alias.d.ts +0 -2
  12. package/bin/libs/confirm/confirm-alias.js +0 -2
  13. package/bin/libs/confirm/confirm-mod.d.ts +0 -5
  14. package/bin/libs/confirm/confirm-mod.js +0 -179
  15. package/bin/libs/date/date.d.ts +0 -2
  16. package/bin/libs/date/date.js +0 -236
  17. package/bin/libs/editor/editor-mod.d.ts +0 -25
  18. package/bin/libs/editor/editor-mod.js +0 -897
  19. package/bin/libs/figures/figures-mod.d.ts +0 -461
  20. package/bin/libs/figures/figures-mod.js +0 -285
  21. package/bin/libs/group/group-mod.d.ts +0 -33
  22. package/bin/libs/group/group-mod.js +0 -93
  23. package/bin/libs/input/input-alias.d.ts +0 -5
  24. package/bin/libs/input/input-alias.js +0 -4
  25. package/bin/libs/input/input-mod.d.ts +0 -16
  26. package/bin/libs/input/input-mod.js +0 -372
  27. package/bin/libs/intro/intro-alias.d.ts +0 -2
  28. package/bin/libs/intro/intro-alias.js +0 -3
  29. package/bin/libs/intro/intro-mod.d.ts +0 -20
  30. package/bin/libs/intro/intro-mod.js +0 -81
  31. package/bin/libs/launcher/command-runner.d.ts +0 -18
  32. package/bin/libs/launcher/command-runner.js +0 -79
  33. package/bin/libs/launcher/command-typed.d.ts +0 -16
  34. package/bin/libs/launcher/command-typed.js +0 -60
  35. package/bin/libs/launcher/launcher-alias.d.ts +0 -2
  36. package/bin/libs/launcher/launcher-alias.js +0 -2
  37. package/bin/libs/launcher/launcher-mod.d.ts +0 -162
  38. package/bin/libs/launcher/launcher-mod.js +0 -1222
  39. package/bin/libs/launcher/launcher-types.d.ts +0 -159
  40. package/bin/libs/launcher/launcher-types.js +0 -0
  41. package/bin/libs/launcher/trpc-orpc-support/completions.d.ts +0 -4
  42. package/bin/libs/launcher/trpc-orpc-support/completions.js +0 -45
  43. package/bin/libs/launcher/trpc-orpc-support/errors.d.ts +0 -11
  44. package/bin/libs/launcher/trpc-orpc-support/errors.js +0 -10
  45. package/bin/libs/launcher/trpc-orpc-support/index.d.ts +0 -34
  46. package/bin/libs/launcher/trpc-orpc-support/index.js +0 -641
  47. package/bin/libs/launcher/trpc-orpc-support/json-schema.d.ts +0 -17
  48. package/bin/libs/launcher/trpc-orpc-support/json-schema.js +0 -168
  49. package/bin/libs/launcher/trpc-orpc-support/json.d.ts +0 -44
  50. package/bin/libs/launcher/trpc-orpc-support/json.js +0 -41
  51. package/bin/libs/launcher/trpc-orpc-support/logging.d.ts +0 -11
  52. package/bin/libs/launcher/trpc-orpc-support/logging.js +0 -26
  53. package/bin/libs/launcher/trpc-orpc-support/parse-procedure.d.ts +0 -2
  54. package/bin/libs/launcher/trpc-orpc-support/parse-procedure.js +0 -486
  55. package/bin/libs/launcher/trpc-orpc-support/prompts.d.ts +0 -18
  56. package/bin/libs/launcher/trpc-orpc-support/prompts.js +0 -534
  57. package/bin/libs/launcher/trpc-orpc-support/standard-schema/contract.d.ts +0 -53
  58. package/bin/libs/launcher/trpc-orpc-support/standard-schema/contract.js +0 -0
  59. package/bin/libs/launcher/trpc-orpc-support/standard-schema/errors.d.ts +0 -9
  60. package/bin/libs/launcher/trpc-orpc-support/standard-schema/errors.js +0 -47
  61. package/bin/libs/launcher/trpc-orpc-support/standard-schema/utils.d.ts +0 -3
  62. package/bin/libs/launcher/trpc-orpc-support/standard-schema/utils.js +0 -6
  63. package/bin/libs/launcher/trpc-orpc-support/trpc-compat.d.ts +0 -71
  64. package/bin/libs/launcher/trpc-orpc-support/trpc-compat.js +0 -11
  65. package/bin/libs/launcher/trpc-orpc-support/types.d.ts +0 -276
  66. package/bin/libs/launcher/trpc-orpc-support/types.js +0 -0
  67. package/bin/libs/launcher/trpc-orpc-support/util.d.ts +0 -9
  68. package/bin/libs/launcher/trpc-orpc-support/util.js +0 -9
  69. package/bin/libs/log/log-alias.d.ts +0 -1
  70. package/bin/libs/log/log-alias.js +0 -2
  71. package/bin/libs/msg-fmt/colors.d.ts +0 -30
  72. package/bin/libs/msg-fmt/colors.js +0 -42
  73. package/bin/libs/msg-fmt/logger.d.ts +0 -17
  74. package/bin/libs/msg-fmt/logger.js +0 -103
  75. package/bin/libs/msg-fmt/mapping.d.ts +0 -3
  76. package/bin/libs/msg-fmt/mapping.js +0 -49
  77. package/bin/libs/msg-fmt/messages.d.ts +0 -35
  78. package/bin/libs/msg-fmt/messages.js +0 -319
  79. package/bin/libs/msg-fmt/terminal.d.ts +0 -15
  80. package/bin/libs/msg-fmt/terminal.js +0 -60
  81. package/bin/libs/msg-fmt/variants.d.ts +0 -11
  82. package/bin/libs/msg-fmt/variants.js +0 -52
  83. package/bin/libs/multiselect/multiselect-alias.d.ts +0 -2
  84. package/bin/libs/multiselect/multiselect-alias.js +0 -2
  85. package/bin/libs/multiselect/multiselect-prompt.d.ts +0 -2
  86. package/bin/libs/multiselect/multiselect-prompt.js +0 -348
  87. package/bin/libs/next-steps/next-steps.d.ts +0 -14
  88. package/bin/libs/next-steps/next-steps.js +0 -24
  89. package/bin/libs/number/number-mod.d.ts +0 -28
  90. package/bin/libs/number/number-mod.js +0 -194
  91. package/bin/libs/outro/outro-alias.d.ts +0 -2
  92. package/bin/libs/outro/outro-alias.js +0 -3
  93. package/bin/libs/outro/outro-mod.d.ts +0 -8
  94. package/bin/libs/outro/outro-mod.js +0 -55
  95. package/bin/libs/results/results.d.ts +0 -7
  96. package/bin/libs/results/results.js +0 -27
  97. package/bin/libs/select/nummultiselect-prompt.d.ts +0 -6
  98. package/bin/libs/select/nummultiselect-prompt.js +0 -105
  99. package/bin/libs/select/numselect-prompt.d.ts +0 -7
  100. package/bin/libs/select/numselect-prompt.js +0 -115
  101. package/bin/libs/select/select-alias.d.ts +0 -9
  102. package/bin/libs/select/select-alias.js +0 -9
  103. package/bin/libs/select/select-prompt.d.ts +0 -5
  104. package/bin/libs/select/select-prompt.js +0 -314
  105. package/bin/libs/select/toggle-prompt.d.ts +0 -5
  106. package/bin/libs/select/toggle-prompt.js +0 -209
  107. package/bin/libs/spinner/spinner-alias.d.ts +0 -1
  108. package/bin/libs/spinner/spinner-alias.js +0 -2
  109. package/bin/libs/spinner/spinner-mod.d.ts +0 -106
  110. package/bin/libs/spinner/spinner-mod.js +0 -265
  111. package/bin/libs/task/progress.d.ts +0 -2
  112. package/bin/libs/task/progress.js +0 -57
  113. package/bin/libs/task/task-spin.d.ts +0 -15
  114. package/bin/libs/task/task-spin.js +0 -110
  115. package/bin/libs/utils/colorize.d.ts +0 -2
  116. package/bin/libs/utils/colorize.js +0 -135
  117. package/bin/libs/utils/errors.d.ts +0 -1
  118. package/bin/libs/utils/errors.js +0 -17
  119. package/bin/libs/utils/prevent.d.ts +0 -8
  120. package/bin/libs/utils/prevent.js +0 -65
  121. package/bin/libs/utils/prompt-end.d.ts +0 -8
  122. package/bin/libs/utils/prompt-end.js +0 -34
  123. package/bin/libs/utils/stream-text.d.ts +0 -18
  124. package/bin/libs/utils/stream-text.js +0 -136
  125. package/bin/libs/utils/system.d.ts +0 -6
  126. package/bin/libs/utils/system.js +0 -7
  127. package/bin/libs/utils/validate.d.ts +0 -21
  128. package/bin/libs/utils/validate.js +0 -17
  129. package/bin/libs/visual/visual-mod.d.ts +0 -6
  130. package/bin/libs/visual/visual-mod.js +0 -13
  131. package/bin/mod.d.ts +0 -69
  132. package/bin/mod.js +0 -159
  133. package/bin/types.d.ts +0 -371
  134. package/bin/types.js +0 -0
@@ -1,27 +0,0 @@
1
- import { msg } from "../msg-fmt/messages.js";
2
- export async function resultPrompt({
3
- results,
4
- inline = true
5
- }) {
6
- const title = "Your input results:";
7
- if (inline) {
8
- const formattedResults = Object.entries(results).map(([key, value]) => `${key}: ${value}`).join(", ");
9
- msg({
10
- type: "M_INFO",
11
- title,
12
- content: formattedResults,
13
- titleColor: "cyan",
14
- contentColor: "dim",
15
- wrapContent: true
16
- });
17
- } else {
18
- const formattedResults = JSON.stringify(results, null, 2);
19
- msg({
20
- type: "M_INFO",
21
- title,
22
- content: formattedResults,
23
- titleColor: "cyan",
24
- contentColor: "dim"
25
- });
26
- }
27
- }
@@ -1,6 +0,0 @@
1
- import type { PromptOptions } from "../../types.js";
2
- type NumMultiSelectPromptOptions = PromptOptions & {
3
- defaultValue?: string[];
4
- };
5
- export declare function numMultiSelectPrompt(opts: NumMultiSelectPromptOptions): Promise<any>;
6
- export {};
@@ -1,105 +0,0 @@
1
- import { re } from "@reliverse/relico";
2
- import { stdin as input, stdout as output } from "node:process";
3
- import readline from "node:readline/promises";
4
- import { bar, fmt, msg } from "../msg-fmt/messages.js";
5
- import {
6
- countLines,
7
- deleteLastLine,
8
- deleteLastLines
9
- } from "../msg-fmt/terminal.js";
10
- export async function numMultiSelectPrompt(opts) {
11
- const {
12
- title = "",
13
- choices,
14
- defaultValue,
15
- titleColor = "cyan",
16
- titleTypography = "none",
17
- titleVariant,
18
- hint,
19
- hintPlaceholderColor = "blue",
20
- content,
21
- contentColor = "dim",
22
- contentTypography = "italic",
23
- contentVariant,
24
- borderColor = "dim",
25
- variantOptions
26
- } = opts;
27
- if (!choices || choices.length === 0) {
28
- throw new Error("Choices are required for multiselect prompt.");
29
- }
30
- const rl = readline.createInterface({ input, output });
31
- const formattedBar = bar({ borderColor });
32
- let linesToDelete = 0;
33
- let errorMessage = "";
34
- try {
35
- while (true) {
36
- if (linesToDelete > 0) {
37
- deleteLastLines(linesToDelete);
38
- }
39
- const { text: question } = fmt({
40
- hintPlaceholderColor,
41
- type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
42
- title: `${title}${defaultValue ? ` [Default: ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}]` : ""}`,
43
- titleColor,
44
- titleTypography,
45
- titleVariant: titleVariant ?? "none",
46
- content: content ?? "",
47
- contentColor: contentColor ?? "dim",
48
- contentTypography: contentTypography ?? "none",
49
- contentVariant: contentVariant ?? "none",
50
- borderColor,
51
- hint: hint ?? "",
52
- variantOptions: variantOptions ?? {},
53
- errorMessage
54
- });
55
- const choicesText = choices.map(
56
- (choice, index) => re.dim(
57
- `${formattedBar} ${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ""}`
58
- )
59
- ).join("\n");
60
- const fullPrompt = `${question}
61
- ${choicesText}
62
- ${formattedBar} ${re.bold(re.blue(`Enter your choices (comma-separated numbers between 1-${choices.length})`))}:
63
- ${formattedBar} `;
64
- const { text: formattedPrompt } = fmt({
65
- hintPlaceholderColor,
66
- type: "M_NULL",
67
- title: fullPrompt
68
- });
69
- const questionLines = countLines(formattedPrompt);
70
- linesToDelete = questionLines + 1;
71
- const answer = (await rl.question(`${formattedPrompt} `)).trim();
72
- if (!answer && defaultValue !== void 0) {
73
- deleteLastLine();
74
- msg({
75
- type: "M_MIDDLE",
76
- title: ` ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}`,
77
- titleColor: "none"
78
- });
79
- msg({ type: "M_BAR", borderColor });
80
- return defaultValue;
81
- }
82
- const selections = answer.split(",").map((s) => s.trim());
83
- const invalidSelections = selections.filter((s) => {
84
- const num = Number(s);
85
- return Number.isNaN(num) || num < 1 || num > choices.length;
86
- });
87
- if (invalidSelections.length > 0) {
88
- errorMessage = `Invalid selections: ${invalidSelections.join(
89
- ", "
90
- )}. Please enter numbers between 1 and ${choices.length}.`;
91
- continue;
92
- }
93
- const selectedValues = selections.map((s) => choices[Number(s) - 1]?.id);
94
- const isValid = true;
95
- errorMessage = "";
96
- if (isValid) {
97
- rl.close();
98
- msg({ type: "M_BAR", borderColor });
99
- return selectedValues;
100
- }
101
- }
102
- } finally {
103
- rl.close();
104
- }
105
- }
@@ -1,7 +0,0 @@
1
- import type { PromptOptions } from "../../types.js";
2
- type NumSelectPromptOptions = PromptOptions & {
3
- inline?: boolean;
4
- defaultValue?: string;
5
- };
6
- export declare function numSelectPrompt(opts: NumSelectPromptOptions): Promise<any>;
7
- export {};
@@ -1,115 +0,0 @@
1
- import { stdin as input, stdout as output } from "node:process";
2
- import readline from "node:readline/promises";
3
- import { bar, fmt, msg } from "../msg-fmt/messages.js";
4
- import {
5
- countLines,
6
- deleteLastLine,
7
- deleteLastLines
8
- } from "../msg-fmt/terminal.js";
9
- import { colorize } from "../../mod.js";
10
- export async function numSelectPrompt(opts) {
11
- const {
12
- title = "",
13
- hint,
14
- hintPlaceholderColor = "blue",
15
- validate,
16
- defaultValue,
17
- titleColor = "cyan",
18
- titleTypography = "none",
19
- titleVariant,
20
- content,
21
- contentColor = "dim",
22
- contentTypography = "italic",
23
- contentVariant,
24
- borderColor = "dim",
25
- variantOptions,
26
- inline = true,
27
- choices
28
- } = opts;
29
- if (!choices || choices.length === 0) {
30
- throw new Error("Choices are required for select prompt.");
31
- }
32
- const rl = readline.createInterface({ input, output });
33
- const formattedBar = bar({ borderColor });
34
- let linesToDelete = 0;
35
- let errorMessage = "";
36
- while (true) {
37
- if (linesToDelete > 0) {
38
- deleteLastLines(linesToDelete);
39
- }
40
- const { text: question } = fmt({
41
- hintPlaceholderColor,
42
- type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
43
- title,
44
- titleColor,
45
- titleTypography,
46
- titleVariant,
47
- content,
48
- contentColor,
49
- contentTypography,
50
- contentVariant,
51
- borderColor,
52
- hint,
53
- variantOptions,
54
- errorMessage
55
- });
56
- let choicesText = "";
57
- if (inline) {
58
- choicesText = choices.map(
59
- (choice, index) => `${index + 1}) ${choice.title}${choice.description ? ` (${choice.description})` : ""}`
60
- ).join(" / ");
61
- } else {
62
- choicesText = choices.map(
63
- (choice, index) => `${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ""}`
64
- ).join(`
65
- ${formattedBar} `);
66
- }
67
- const { text: formattedPrompt } = fmt({
68
- hintPlaceholderColor,
69
- type: "M_NULL",
70
- title: `${question}
71
- ${choicesText}
72
- ${formattedBar} ${colorize(
73
- "Enter your choice:",
74
- contentColor
75
- )}
76
- ${formattedBar} `
77
- });
78
- const questionLines = countLines(formattedPrompt);
79
- linesToDelete = questionLines + 1;
80
- const prompt = await rl.question(formattedPrompt);
81
- const answer = prompt.trim() || defaultValue;
82
- if (!prompt.trim() && defaultValue !== void 0) {
83
- deleteLastLine();
84
- msg({
85
- type: "M_MIDDLE",
86
- title: ` ${defaultValue}`,
87
- titleColor: "none"
88
- });
89
- msg({ type: "M_BAR", borderColor });
90
- }
91
- const num = Number(answer);
92
- if (Number.isNaN(num) || num < 1 || num > choices.length) {
93
- errorMessage = `Please enter a number between 1 and ${choices.length}.`;
94
- continue;
95
- }
96
- const selectedChoice = choices[num - 1];
97
- const selectedValue = selectedChoice?.id ?? num;
98
- let isValid = true;
99
- errorMessage = "";
100
- if (validate && isValid) {
101
- const validation = await validate(selectedValue);
102
- if (validation !== true) {
103
- isValid = false;
104
- errorMessage = typeof validation === "string" ? validation : "Invalid input.";
105
- }
106
- }
107
- if (isValid) {
108
- rl.close();
109
- if (selectedChoice?.action) {
110
- await selectedChoice.action();
111
- }
112
- return selectedValue;
113
- }
114
- }
115
- }
@@ -1,9 +0,0 @@
1
- import type { SelectPromptParams } from "../../types.js";
2
- export declare const select: <T extends string>(params: SelectPromptParams<T>) => Promise<T>;
3
- export declare const selectSimple: <T extends string>(params: Omit<SelectPromptParams<T>, "options"> & {
4
- options: {
5
- value: T;
6
- label?: string;
7
- hint?: string;
8
- }[];
9
- }) => Promise<T>;
@@ -1,9 +0,0 @@
1
- import { selectPrompt } from "./select-prompt.js";
2
- export const select = selectPrompt;
3
- export const selectSimple = (params) => {
4
- return selectPrompt({
5
- ...params,
6
- optionsArray: params.options,
7
- options: void 0
8
- });
9
- };
@@ -1,5 +0,0 @@
1
- import type { SelectPromptParams } from "../../types.js";
2
- /**
3
- * Displays a selectable prompt in the terminal and returns the chosen value.
4
- */
5
- export declare function selectPrompt<T extends string>(params: SelectPromptParams<T>): Promise<T>;
@@ -1,314 +0,0 @@
1
- import { re } from "@reliverse/relico";
2
- import { relinka } from "@reliverse/relinka";
3
- import { stdin as input, stdout as output } from "node:process";
4
- import readline from "node:readline";
5
- import { msg, symbols } from "../msg-fmt/messages.js";
6
- import { deleteLastLine } from "../msg-fmt/terminal.js";
7
- import { completePrompt } from "../utils/prompt-end.js";
8
- import { streamText } from "../utils/stream-text.js";
9
- function isSelectOption(option) {
10
- return !("separator" in option);
11
- }
12
- async function renderPromptUI(params) {
13
- const {
14
- title,
15
- content,
16
- options,
17
- selectedIndex,
18
- errorMessage,
19
- displayInstructions,
20
- allDisabled,
21
- instructions,
22
- titleColor,
23
- contentColor,
24
- contentTypography,
25
- debug,
26
- titleVariant,
27
- titleTypography,
28
- isRerender = false,
29
- shouldStream = false,
30
- streamDelay = 20
31
- } = params;
32
- if (!isRerender) {
33
- if (shouldStream) {
34
- deleteLastLine();
35
- msg({ type: "M_BAR", title: "" });
36
- await streamText({
37
- text: title,
38
- delay: streamDelay,
39
- color: titleColor,
40
- newline: false,
41
- clearLine: true
42
- });
43
- process.stdout.write("\r");
44
- msg({
45
- type: "M_GENERAL",
46
- title,
47
- titleColor,
48
- titleVariant,
49
- titleTypography
50
- });
51
- if (content) {
52
- msg({
53
- type: "M_NULL",
54
- content,
55
- contentColor,
56
- contentTypography
57
- });
58
- }
59
- } else {
60
- msg({ type: "M_GENERAL", title, titleColor });
61
- if (content) {
62
- msg({
63
- type: "M_NULL",
64
- content,
65
- contentColor,
66
- contentTypography
67
- });
68
- }
69
- }
70
- }
71
- let uiLineCount = 0;
72
- if (errorMessage) {
73
- msg({
74
- type: "M_ERROR",
75
- title: `${re.redBright(symbols.step_error)} ${re.redBright(errorMessage)}`
76
- });
77
- uiLineCount++;
78
- } else if (allDisabled) {
79
- msg({ type: "M_ERROR", title: re.redBright("All options are disabled.") });
80
- uiLineCount++;
81
- } else if (displayInstructions && !isRerender) {
82
- msg({ type: "M_NULL", title: re.blue(instructions) });
83
- uiLineCount++;
84
- }
85
- for (let index = 0; index < options.length; index++) {
86
- const option = options[index];
87
- if (!option) continue;
88
- if (!isSelectOption(option)) {
89
- const width = option.width ?? 20;
90
- const symbolKey = option.symbol ?? "line";
91
- const lineSymbol = symbolKey in symbols ? symbols[symbolKey] : "\u2500";
92
- msg({ type: "M_NULL", title: re.dim(lineSymbol.repeat(width)) });
93
- uiLineCount++;
94
- continue;
95
- }
96
- const isSelected = index === selectedIndex;
97
- const isDisabled = option.disabled;
98
- const prefix = isSelected ? re.dim(re.reset("> ")) : " ";
99
- const labelColor = isDisabled ? re.dim(re.reset(option.label)) : isSelected ? re.reset(re.yellow(option.label)) : re.reset(option.label);
100
- const hint = option.hint ? re.reset(
101
- ` (${isDisabled ? re.dim(option.hint) : re.italic(re.dim(option.hint))})`
102
- ) : "";
103
- msg({ type: "M_NULL", title: `${prefix}${labelColor}${hint}` });
104
- uiLineCount++;
105
- }
106
- if (debug) {
107
- relinka("log", "", { optionsCount: options.length });
108
- }
109
- return uiLineCount;
110
- }
111
- export async function selectPrompt(params) {
112
- const {
113
- title = "",
114
- message,
115
- content = "",
116
- options,
117
- optionsArray,
118
- defaultValue,
119
- initialValue,
120
- required = false,
121
- borderColor = "dim",
122
- titleColor = "cyan",
123
- titleTypography = "none",
124
- titleVariant,
125
- contentColor = "dim",
126
- contentTypography = "italic",
127
- border = true,
128
- endTitle = "",
129
- endTitleColor = "dim",
130
- debug = false,
131
- terminalWidth: customTerminalWidth = 90,
132
- displayInstructions = false,
133
- shouldStream = false,
134
- streamDelay = 20
135
- } = params;
136
- const finalTitle = message && title ? `${title}: ${message}` : message ?? title ?? "Select option";
137
- const finalDefaultValue = defaultValue ?? initialValue;
138
- const finalOptions = options ?? optionsArray?.map((opt) => ({
139
- value: opt.value,
140
- label: opt.label ?? opt.value,
141
- hint: opt.hint,
142
- disabled: false
143
- })) ?? [];
144
- let selectedIndex = finalDefaultValue ? finalOptions.findIndex(
145
- (option) => isSelectOption(option) && option.value === finalDefaultValue && !option.disabled
146
- ) : -1;
147
- if (selectedIndex === -1) {
148
- selectedIndex = finalOptions.findIndex(
149
- (option) => isSelectOption(option) && !option.disabled
150
- );
151
- }
152
- if (selectedIndex === -1) {
153
- selectedIndex = 0;
154
- }
155
- const rl = readline.createInterface({ input, output });
156
- readline.emitKeypressEvents(input, rl);
157
- if (typeof input.setRawMode === "function") {
158
- input.setRawMode(true);
159
- }
160
- const instructions = "Use <\u2191/\u2193> or <k/j> to navigate, <Enter> to select, <Ctrl+C> to exit";
161
- let errorMessage = "";
162
- const allDisabled = finalOptions.every(
163
- (option) => isSelectOption(option) && option.disabled
164
- );
165
- let lastUILineCount = 0;
166
- function renderOptions() {
167
- if (lastUILineCount > 0) {
168
- for (let i = 0; i < lastUILineCount; i++) {
169
- process.stdout.write("\x1B[1A\x1B[2K");
170
- }
171
- }
172
- void renderPromptUI({
173
- title: finalTitle,
174
- content,
175
- options: finalOptions,
176
- selectedIndex,
177
- errorMessage,
178
- displayInstructions,
179
- allDisabled,
180
- instructions,
181
- borderColor,
182
- titleColor,
183
- contentColor,
184
- contentTypography,
185
- debug,
186
- titleVariant,
187
- titleTypography,
188
- terminalWidth: customTerminalWidth,
189
- isRerender: true,
190
- shouldStream,
191
- streamDelay
192
- }).then((count) => {
193
- lastUILineCount = count;
194
- });
195
- }
196
- lastUILineCount = await renderPromptUI({
197
- title: finalTitle,
198
- content,
199
- options: finalOptions,
200
- selectedIndex,
201
- errorMessage,
202
- displayInstructions,
203
- allDisabled,
204
- instructions,
205
- borderColor,
206
- titleColor,
207
- contentColor,
208
- contentTypography,
209
- debug,
210
- titleVariant,
211
- titleTypography,
212
- terminalWidth: customTerminalWidth,
213
- isRerender: false,
214
- shouldStream,
215
- streamDelay
216
- });
217
- return new Promise((resolve) => {
218
- function handleKeypress(_str, key) {
219
- if (allDisabled) {
220
- if (key.name === "c" && key.ctrl) {
221
- void endPrompt(true);
222
- return;
223
- }
224
- return;
225
- }
226
- if (key.name === "up" || key.name === "k") {
227
- moveSelectionUp();
228
- } else if (key.name === "down" || key.name === "j") {
229
- moveSelectionDown();
230
- } else if (key.name === "return") {
231
- void confirmSelection();
232
- } else if (key.name === "c" && key.ctrl) {
233
- void endPrompt(true);
234
- }
235
- }
236
- function moveSelectionUp() {
237
- const originalPointer = selectedIndex;
238
- do {
239
- selectedIndex = (selectedIndex - 1 + finalOptions.length) % finalOptions.length;
240
- const option = finalOptions[selectedIndex];
241
- if (option && isSelectOption(option) && !option.disabled) break;
242
- } while (selectedIndex !== originalPointer);
243
- renderOptions();
244
- }
245
- function moveSelectionDown() {
246
- const originalPointer = selectedIndex;
247
- do {
248
- selectedIndex = (selectedIndex + 1) % finalOptions.length;
249
- const option = finalOptions[selectedIndex];
250
- if (option && isSelectOption(option) && !option.disabled) break;
251
- } while (selectedIndex !== originalPointer);
252
- renderOptions();
253
- }
254
- async function confirmSelection() {
255
- const option = finalOptions[selectedIndex];
256
- if (!option || !isSelectOption(option)) {
257
- errorMessage = "This option is not selectable.";
258
- renderOptions();
259
- return;
260
- }
261
- if (option.disabled) {
262
- errorMessage = "This option is disabled";
263
- renderOptions();
264
- return;
265
- }
266
- if (required && (!option.value || option.value === "")) {
267
- errorMessage = "You must select a valid option.";
268
- renderOptions();
269
- return;
270
- }
271
- cleanup();
272
- resolve(option.value);
273
- deleteLastLine();
274
- await completePrompt(
275
- "select",
276
- false,
277
- endTitle,
278
- endTitleColor,
279
- titleTypography,
280
- titleVariant ? titleVariant : void 0,
281
- border,
282
- borderColor,
283
- void 0,
284
- true
285
- );
286
- }
287
- async function endPrompt(isCtrlC = false) {
288
- await completePrompt(
289
- "select",
290
- isCtrlC,
291
- endTitle,
292
- endTitleColor,
293
- titleTypography,
294
- titleVariant ? titleVariant : void 0,
295
- border,
296
- borderColor,
297
- void 0,
298
- false
299
- );
300
- cleanup(isCtrlC);
301
- }
302
- function cleanup(isCtrlC = false) {
303
- if (typeof input.setRawMode === "function") {
304
- input.setRawMode(false);
305
- }
306
- rl.close();
307
- input.removeListener("keypress", handleKeypress);
308
- if (isCtrlC) {
309
- process.exit(0);
310
- }
311
- }
312
- input.on("keypress", handleKeypress);
313
- });
314
- }
@@ -1,5 +0,0 @@
1
- import type { TogglePromptParams } from "../../types.js";
2
- /**
3
- * A toggle prompt that lets the user choose between two options (Yes/No style).
4
- */
5
- export declare function togglePrompt<T extends string>(params: TogglePromptParams<T>): Promise<boolean>;