@reliverse/rempts-core 1.6.1
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.
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/bin/core-impl/anykey/anykey-mod.d.ts +12 -0
- package/bin/core-impl/anykey/anykey-mod.js +125 -0
- package/bin/core-impl/date/date.d.ts +2 -0
- package/bin/core-impl/date/date.js +236 -0
- package/bin/core-impl/editor/editor-mod.d.ts +25 -0
- package/bin/core-impl/editor/editor-mod.js +896 -0
- package/bin/core-impl/figures/figures-mod.d.ts +233 -0
- package/bin/core-impl/figures/figures-mod.js +286 -0
- package/bin/core-impl/figures/figures.test.d.ts +1 -0
- package/bin/core-impl/figures/figures.test.js +474 -0
- package/bin/core-impl/input/confirm-prompt.d.ts +5 -0
- package/bin/core-impl/input/confirm-prompt.js +173 -0
- package/bin/core-impl/input/input-prompt.d.ts +16 -0
- package/bin/core-impl/input/input-prompt.js +370 -0
- package/bin/core-impl/launcher/_parser.d.ts +2 -0
- package/bin/core-impl/launcher/_parser.js +122 -0
- package/bin/core-impl/launcher/_utils.d.ts +8 -0
- package/bin/core-impl/launcher/_utils.js +29 -0
- package/bin/core-impl/launcher/args.d.ts +3 -0
- package/bin/core-impl/launcher/args.js +89 -0
- package/bin/core-impl/launcher/command.d.ts +8 -0
- package/bin/core-impl/launcher/command.js +68 -0
- package/bin/core-impl/launcher/launcher-mod.d.ts +8 -0
- package/bin/core-impl/launcher/launcher-mod.js +34 -0
- package/bin/core-impl/launcher/usage.d.ts +3 -0
- package/bin/core-impl/launcher/usage.js +104 -0
- package/bin/core-impl/msg-fmt/colors.d.ts +30 -0
- package/bin/core-impl/msg-fmt/colors.js +42 -0
- package/bin/core-impl/msg-fmt/logger.d.ts +17 -0
- package/bin/core-impl/msg-fmt/logger.js +106 -0
- package/bin/core-impl/msg-fmt/mapping.d.ts +3 -0
- package/bin/core-impl/msg-fmt/mapping.js +49 -0
- package/bin/core-impl/msg-fmt/messages.d.ts +35 -0
- package/bin/core-impl/msg-fmt/messages.js +314 -0
- package/bin/core-impl/msg-fmt/terminal.d.ts +15 -0
- package/bin/core-impl/msg-fmt/terminal.js +59 -0
- package/bin/core-impl/msg-fmt/variants.d.ts +11 -0
- package/bin/core-impl/msg-fmt/variants.js +52 -0
- package/bin/core-impl/next-steps/next-steps.d.ts +14 -0
- package/bin/core-impl/next-steps/next-steps.js +24 -0
- package/bin/core-impl/number/number-mod.d.ts +28 -0
- package/bin/core-impl/number/number-mod.js +197 -0
- package/bin/core-impl/results/results.d.ts +7 -0
- package/bin/core-impl/results/results.js +27 -0
- package/bin/core-impl/select/multiselect-prompt.d.ts +2 -0
- package/bin/core-impl/select/multiselect-prompt.js +341 -0
- package/bin/core-impl/select/nummultiselect-prompt.d.ts +6 -0
- package/bin/core-impl/select/nummultiselect-prompt.js +105 -0
- package/bin/core-impl/select/numselect-prompt.d.ts +7 -0
- package/bin/core-impl/select/numselect-prompt.js +115 -0
- package/bin/core-impl/select/select-prompt.d.ts +33 -0
- package/bin/core-impl/select/select-prompt.js +302 -0
- package/bin/core-impl/select/toggle-prompt.d.ts +5 -0
- package/bin/core-impl/select/toggle-prompt.js +208 -0
- package/bin/core-impl/st-end/end.d.ts +2 -0
- package/bin/core-impl/st-end/end.js +42 -0
- package/bin/core-impl/st-end/start.d.ts +17 -0
- package/bin/core-impl/st-end/start.js +66 -0
- package/bin/core-impl/task/progress.d.ts +2 -0
- package/bin/core-impl/task/progress.js +57 -0
- package/bin/core-impl/task/spinner.d.ts +15 -0
- package/bin/core-impl/task/spinner.js +110 -0
- package/bin/core-impl/utils/colorize.d.ts +2 -0
- package/bin/core-impl/utils/colorize.js +134 -0
- package/bin/core-impl/utils/errors.d.ts +1 -0
- package/bin/core-impl/utils/errors.js +15 -0
- package/bin/core-impl/utils/prevent.d.ts +10 -0
- package/bin/core-impl/utils/prevent.js +69 -0
- package/bin/core-impl/utils/prompt-end.d.ts +8 -0
- package/bin/core-impl/utils/prompt-end.js +33 -0
- package/bin/core-impl/utils/stream-text.d.ts +18 -0
- package/bin/core-impl/utils/stream-text.js +136 -0
- package/bin/core-impl/utils/system.d.ts +6 -0
- package/bin/core-impl/utils/system.js +7 -0
- package/bin/core-impl/utils/validate.d.ts +22 -0
- package/bin/core-impl/utils/validate.js +17 -0
- package/bin/core-impl/visual/animate/animate.d.ts +14 -0
- package/bin/core-impl/visual/animate/animate.js +64 -0
- package/bin/core-impl/visual/ascii-art/ascii-art.d.ts +6 -0
- package/bin/core-impl/visual/ascii-art/ascii-art.js +12 -0
- package/bin/core-types.d.ts +434 -0
- package/bin/core-types.js +0 -0
- package/bin/main.d.ts +41 -0
- package/bin/main.js +96 -0
- package/package.json +58 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { re } from "@reliverse/relico";
|
|
2
|
+
import { isUnicodeSupported } from "@reliverse/runtime";
|
|
3
|
+
import wrapAnsi from "wrap-ansi";
|
|
4
|
+
import { colorMap, typographyMap } from "./mapping.js";
|
|
5
|
+
import {
|
|
6
|
+
deleteLastLines,
|
|
7
|
+
getExactTerminalWidth,
|
|
8
|
+
getTerminalWidth
|
|
9
|
+
} from "./terminal.js";
|
|
10
|
+
import { isValidVariant, variantMap } from "./variants.js";
|
|
11
|
+
const unicode = isUnicodeSupported();
|
|
12
|
+
const u = (c, fallback) => unicode ? c : fallback;
|
|
13
|
+
export const symbols = {
|
|
14
|
+
pointer: u("\u{1F449}", ">"),
|
|
15
|
+
start: u("\u256D", "*"),
|
|
16
|
+
middle: u("\u2502", "|"),
|
|
17
|
+
end: u("\u2570", "*"),
|
|
18
|
+
line: u("\u2500", "\u2014"),
|
|
19
|
+
corner_top_right: u("\u256D", "*"),
|
|
20
|
+
step_active: u("\u25C6", "\u2666"),
|
|
21
|
+
step_error: u("\u{1F5F4}", "x"),
|
|
22
|
+
info: u("\u2139", "i"),
|
|
23
|
+
success: u("\u2705", "\u2713")
|
|
24
|
+
};
|
|
25
|
+
function wrapThenStyle(input, wrap, typographyName, colorName, variantName, borderColor) {
|
|
26
|
+
if (!input) return "";
|
|
27
|
+
const width = getTerminalWidth();
|
|
28
|
+
const wrappedText = wrap ? wrapAnsi(input, width, { hard: false, trim: true }) : input;
|
|
29
|
+
return wrappedText.split("\n").map(
|
|
30
|
+
(line) => applyStyles(line, colorName, typographyName, variantName, borderColor)
|
|
31
|
+
).join("\n");
|
|
32
|
+
}
|
|
33
|
+
function applyStyles(text, colorName, typographyName, variantName, borderColor) {
|
|
34
|
+
let styledText = text;
|
|
35
|
+
if (variantName && isValidVariant(variantName)) {
|
|
36
|
+
styledText = variantMap[variantName](
|
|
37
|
+
[styledText],
|
|
38
|
+
void 0,
|
|
39
|
+
borderColor
|
|
40
|
+
).toString();
|
|
41
|
+
return styledText;
|
|
42
|
+
}
|
|
43
|
+
if (colorName && colorMap[colorName]) {
|
|
44
|
+
styledText = colorMap[colorName](styledText);
|
|
45
|
+
}
|
|
46
|
+
if (typographyName && typographyMap[typographyName]) {
|
|
47
|
+
styledText = typographyMap[typographyName](styledText);
|
|
48
|
+
}
|
|
49
|
+
return styledText;
|
|
50
|
+
}
|
|
51
|
+
export const bar = ({
|
|
52
|
+
borderColor = "dim"
|
|
53
|
+
} = {}) => {
|
|
54
|
+
if (borderColor.endsWith("Gradient")) {
|
|
55
|
+
console.error(
|
|
56
|
+
"Gradient colors are not supported for bars. Please use a solid color instead."
|
|
57
|
+
);
|
|
58
|
+
return colorMap.dim(symbols.middle);
|
|
59
|
+
}
|
|
60
|
+
return colorMap[borderColor](symbols.middle);
|
|
61
|
+
};
|
|
62
|
+
function countLines(text) {
|
|
63
|
+
return text.split("\n").length;
|
|
64
|
+
}
|
|
65
|
+
function getColoredSymbol(customSymbol, symbolName, symbolColor) {
|
|
66
|
+
if (customSymbol) {
|
|
67
|
+
return symbolColor && colorMap[symbolColor] ? colorMap[symbolColor](customSymbol) : customSymbol;
|
|
68
|
+
}
|
|
69
|
+
if (symbolName && symbols[symbolName]) {
|
|
70
|
+
return symbolColor && colorMap[symbolColor] ? colorMap[symbolColor](symbols[symbolName]) : symbols[symbolName];
|
|
71
|
+
}
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
function formatTitle(opts, borderTwoSpaces, borderError) {
|
|
75
|
+
let formattedTitle = "";
|
|
76
|
+
if (!opts.title) return formattedTitle;
|
|
77
|
+
const wrappedOrStyledTitle = wrapThenStyle(
|
|
78
|
+
opts.title,
|
|
79
|
+
opts.wrapTitle ?? true,
|
|
80
|
+
opts.titleTypography ?? "bold",
|
|
81
|
+
opts.titleColor ?? "cyan",
|
|
82
|
+
opts.titleVariant,
|
|
83
|
+
opts.borderColor
|
|
84
|
+
);
|
|
85
|
+
formattedTitle += wrappedOrStyledTitle;
|
|
86
|
+
if (opts.hint) {
|
|
87
|
+
const hintColor = opts.hintPlaceholderColor ?? "blue";
|
|
88
|
+
const wrappedHint = wrapThenStyle(
|
|
89
|
+
opts.hint,
|
|
90
|
+
opts.wrapTitle ?? true,
|
|
91
|
+
// same wrap logic as title by default
|
|
92
|
+
opts.hintTypography ?? "italic",
|
|
93
|
+
hintColor,
|
|
94
|
+
void 0,
|
|
95
|
+
opts.borderColor
|
|
96
|
+
);
|
|
97
|
+
formattedTitle += `
|
|
98
|
+
${borderTwoSpaces}${wrappedHint}`;
|
|
99
|
+
}
|
|
100
|
+
if (opts.placeholder && opts.type === "M_GENERAL") {
|
|
101
|
+
const placeHolderColor = opts.hintPlaceholderColor ?? "blue";
|
|
102
|
+
formattedTitle += `
|
|
103
|
+
${borderTwoSpaces}${colorMap[placeHolderColor](opts.placeholder)}`;
|
|
104
|
+
}
|
|
105
|
+
if (opts.errorMessage) {
|
|
106
|
+
const formattedError = applyStyles(
|
|
107
|
+
opts.errorMessage,
|
|
108
|
+
"red",
|
|
109
|
+
"bold",
|
|
110
|
+
void 0,
|
|
111
|
+
opts.borderColor
|
|
112
|
+
);
|
|
113
|
+
formattedTitle += `
|
|
114
|
+
${borderError} ${formattedError}`;
|
|
115
|
+
}
|
|
116
|
+
return formattedTitle;
|
|
117
|
+
}
|
|
118
|
+
function formatContent(opts) {
|
|
119
|
+
if (!opts.content) return "";
|
|
120
|
+
return wrapThenStyle(
|
|
121
|
+
opts.content,
|
|
122
|
+
opts.wrapContent ?? true,
|
|
123
|
+
opts.contentTypography ?? "italic",
|
|
124
|
+
opts.contentColor ?? "dim",
|
|
125
|
+
opts.contentVariant,
|
|
126
|
+
opts.borderColor
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
export function fmt(opts) {
|
|
130
|
+
if (!opts.borderColor) {
|
|
131
|
+
opts.borderColor = "dim";
|
|
132
|
+
}
|
|
133
|
+
const borderColored = applyStyles(symbols.middle, opts.borderColor);
|
|
134
|
+
const borderError = applyStyles(symbols.middle, "red");
|
|
135
|
+
const borderTwoSpaces = `${borderColored} `;
|
|
136
|
+
const prefixStartLine = opts.borderColor ? colorMap[opts.borderColor](symbols.start + symbols.line) : symbols.start + symbols.line;
|
|
137
|
+
const prefixEndLine = opts.borderColor ? colorMap[opts.borderColor](symbols.end + symbols.line) : symbols.end + symbols.line;
|
|
138
|
+
const lineLength = opts.horizontalLineLength === 0 ? getExactTerminalWidth() - 3 : opts.horizontalLineLength ?? getExactTerminalWidth() - 3;
|
|
139
|
+
const suffixStartLine = opts.borderColor ? colorMap[opts.borderColor](`${symbols.line.repeat(lineLength)}\u22B1`) : `${symbols.line.repeat(lineLength)}\u22B1`;
|
|
140
|
+
const suffixEndLine = opts.borderColor ? colorMap[opts.borderColor](`${symbols.line.repeat(lineLength)}\u22B1`) : `${symbols.line.repeat(lineLength)}\u22B1`;
|
|
141
|
+
const computedSymbol = getColoredSymbol(opts.customSymbol, opts.symbol, opts.symbolColor) ?? re.green(symbols.step_active);
|
|
142
|
+
const MESSAGE_CONFIG_MAP = {
|
|
143
|
+
M_NULL: {
|
|
144
|
+
symbol: "",
|
|
145
|
+
prefix: borderTwoSpaces,
|
|
146
|
+
suffix: "",
|
|
147
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
148
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
149
|
+
},
|
|
150
|
+
M_BAR: {
|
|
151
|
+
symbol: "",
|
|
152
|
+
prefix: "",
|
|
153
|
+
suffix: "",
|
|
154
|
+
newLineBefore: false,
|
|
155
|
+
newLineAfter: false
|
|
156
|
+
},
|
|
157
|
+
M_INFO_NULL: {
|
|
158
|
+
symbol: "",
|
|
159
|
+
prefix: borderTwoSpaces,
|
|
160
|
+
suffix: "",
|
|
161
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
162
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
163
|
+
},
|
|
164
|
+
M_START: {
|
|
165
|
+
symbol: "",
|
|
166
|
+
prefix: "",
|
|
167
|
+
suffix: `
|
|
168
|
+
${borderTwoSpaces}`,
|
|
169
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
170
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
171
|
+
},
|
|
172
|
+
M_MIDDLE: {
|
|
173
|
+
symbol: "",
|
|
174
|
+
prefix: borderTwoSpaces,
|
|
175
|
+
suffix: "",
|
|
176
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
177
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
178
|
+
},
|
|
179
|
+
M_GENERAL: {
|
|
180
|
+
symbol: computedSymbol,
|
|
181
|
+
prefix: borderTwoSpaces,
|
|
182
|
+
suffix: "",
|
|
183
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
184
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
185
|
+
},
|
|
186
|
+
M_GENERAL_NULL: {
|
|
187
|
+
symbol: "",
|
|
188
|
+
prefix: borderTwoSpaces,
|
|
189
|
+
suffix: opts.placeholder ? colorMap[opts.hintPlaceholderColor ?? "blue"](opts.placeholder) : "",
|
|
190
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
191
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
192
|
+
},
|
|
193
|
+
M_INFO: {
|
|
194
|
+
symbol: computedSymbol || re.green(symbols.info),
|
|
195
|
+
prefix: borderTwoSpaces,
|
|
196
|
+
suffix: "",
|
|
197
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
198
|
+
newLineAfter: opts.addNewLineAfter ?? true
|
|
199
|
+
},
|
|
200
|
+
M_ERROR: {
|
|
201
|
+
symbol: computedSymbol || re.redBright(symbols.step_error),
|
|
202
|
+
prefix: borderTwoSpaces,
|
|
203
|
+
suffix: "",
|
|
204
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
205
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
206
|
+
},
|
|
207
|
+
M_ERROR_NULL: {
|
|
208
|
+
symbol: "",
|
|
209
|
+
prefix: borderTwoSpaces,
|
|
210
|
+
suffix: "",
|
|
211
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
212
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
213
|
+
},
|
|
214
|
+
M_END: {
|
|
215
|
+
symbol: "",
|
|
216
|
+
prefix: "",
|
|
217
|
+
suffix: "",
|
|
218
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
219
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
220
|
+
},
|
|
221
|
+
M_NEWLINE: {
|
|
222
|
+
symbol: "",
|
|
223
|
+
prefix: borderTwoSpaces,
|
|
224
|
+
suffix: "",
|
|
225
|
+
newLineBefore: opts.addNewLineBefore ?? false,
|
|
226
|
+
newLineAfter: opts.addNewLineAfter ?? false
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const config = MESSAGE_CONFIG_MAP[opts.type];
|
|
230
|
+
if (!config) {
|
|
231
|
+
throw new Error(`Invalid message type: ${opts.type}`);
|
|
232
|
+
}
|
|
233
|
+
const { symbol, suffix, newLineBefore, newLineAfter } = config;
|
|
234
|
+
const finalTitle = formatTitle(opts, borderTwoSpaces, borderError);
|
|
235
|
+
const finalContent = formatContent(opts);
|
|
236
|
+
let text = "";
|
|
237
|
+
if (opts.type === "M_BAR") {
|
|
238
|
+
text = bar({ borderColor: opts.borderColor });
|
|
239
|
+
} else {
|
|
240
|
+
text = [finalTitle, finalContent].filter(Boolean).join("\n");
|
|
241
|
+
}
|
|
242
|
+
const fullText = [
|
|
243
|
+
newLineBefore ? `
|
|
244
|
+
${borderTwoSpaces}` : "",
|
|
245
|
+
text,
|
|
246
|
+
newLineAfter ? `
|
|
247
|
+
${borderTwoSpaces}` : "",
|
|
248
|
+
suffix
|
|
249
|
+
].filter(Boolean).join("");
|
|
250
|
+
const lines = fullText.split("\n").map((line, index) => {
|
|
251
|
+
if (opts.type === "M_START") {
|
|
252
|
+
if (index === 0) {
|
|
253
|
+
return `${prefixStartLine} ${line} ${suffixStartLine}`;
|
|
254
|
+
}
|
|
255
|
+
if (index === 1) {
|
|
256
|
+
return borderTwoSpaces;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (opts.type === "M_END" && opts.border && index === 0) {
|
|
260
|
+
if (!opts.title) return "";
|
|
261
|
+
return `${bar({ borderColor: opts.borderColor ?? "dim" })} ${line}`;
|
|
262
|
+
}
|
|
263
|
+
if (!line.trim() || line.includes(symbols.middle)) {
|
|
264
|
+
return line;
|
|
265
|
+
}
|
|
266
|
+
if (index === 0 && symbol) {
|
|
267
|
+
return `${symbol} ${line}`;
|
|
268
|
+
}
|
|
269
|
+
return `${config.prefix}${line}`;
|
|
270
|
+
});
|
|
271
|
+
if (opts.type === "M_END" && opts.border) {
|
|
272
|
+
lines.push(`${prefixEndLine}${suffixEndLine}
|
|
273
|
+
`);
|
|
274
|
+
}
|
|
275
|
+
const finalText = lines.join("\n");
|
|
276
|
+
const lineCount = countLines(finalText);
|
|
277
|
+
return { text: finalText, lineCount };
|
|
278
|
+
}
|
|
279
|
+
const printedLineStack = [];
|
|
280
|
+
export function msg(opts) {
|
|
281
|
+
const { text, lineCount } = fmt(opts);
|
|
282
|
+
if (opts.type === "M_BAR" && opts.noNewLine) {
|
|
283
|
+
process.stdout.write(text);
|
|
284
|
+
} else {
|
|
285
|
+
process.stdout.write(`${text}
|
|
286
|
+
`);
|
|
287
|
+
}
|
|
288
|
+
printedLineStack.push(
|
|
289
|
+
opts.type === "M_BAR" && opts.noNewLine ? lineCount : lineCount + 1
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
export function msgUndo(count = 1) {
|
|
293
|
+
for (let i = 0; i < count; i++) {
|
|
294
|
+
const linesToDelete = printedLineStack.pop();
|
|
295
|
+
if (typeof linesToDelete === "number" && linesToDelete > 0) {
|
|
296
|
+
deleteLastLines(linesToDelete);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
export function msgUndoAll() {
|
|
301
|
+
while (printedLineStack.length > 0) {
|
|
302
|
+
const linesToDelete = printedLineStack.pop();
|
|
303
|
+
if (typeof linesToDelete === "number" && linesToDelete > 0) {
|
|
304
|
+
deleteLastLines(linesToDelete);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
export function printLineBar(text, indent = 2) {
|
|
309
|
+
if (text === "") {
|
|
310
|
+
console.log(re.dim("\u2502"));
|
|
311
|
+
} else {
|
|
312
|
+
console.log(`${re.dim("\u2502")}${" ".repeat(indent)}${text}`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function getTerminalHeight(): number;
|
|
2
|
+
export declare function getExactTerminalWidth(): number;
|
|
3
|
+
export declare function getTerminalWidth(terminalWidth?: number): number;
|
|
4
|
+
/**
|
|
5
|
+
* Force line returns at specific width. This function is ANSI code friendly and it'll
|
|
6
|
+
* ignore invisible codes during width calculation.
|
|
7
|
+
* @param {string} content
|
|
8
|
+
* @return {string}
|
|
9
|
+
*/
|
|
10
|
+
export declare function breakLines(content: string, terminalWidth?: number): string;
|
|
11
|
+
export declare function removeCursor(): void;
|
|
12
|
+
export declare function restoreCursor(): void;
|
|
13
|
+
export declare function deleteLastLine(): void;
|
|
14
|
+
export declare function deleteLastLines(count: number): void;
|
|
15
|
+
export declare function countLines(text: string): number;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import ansiEscapes from "ansi-escapes";
|
|
2
|
+
import { cursor } from "sisteransi";
|
|
3
|
+
import terminalSize from "terminal-size";
|
|
4
|
+
import wrapAnsi from "wrap-ansi";
|
|
5
|
+
export function getTerminalHeight() {
|
|
6
|
+
return terminalSize().rows ?? 24;
|
|
7
|
+
}
|
|
8
|
+
export function getExactTerminalWidth() {
|
|
9
|
+
return terminalSize().columns ?? 80;
|
|
10
|
+
}
|
|
11
|
+
export function getTerminalWidth(terminalWidth = 0) {
|
|
12
|
+
if (terminalWidth === 0) {
|
|
13
|
+
terminalWidth = getExactTerminalWidth();
|
|
14
|
+
}
|
|
15
|
+
if (terminalWidth > 150) {
|
|
16
|
+
return terminalWidth - 40;
|
|
17
|
+
}
|
|
18
|
+
if (terminalWidth > 120) {
|
|
19
|
+
return terminalWidth - 30;
|
|
20
|
+
}
|
|
21
|
+
if (terminalWidth > 100) {
|
|
22
|
+
return terminalWidth - 20;
|
|
23
|
+
}
|
|
24
|
+
return terminalWidth;
|
|
25
|
+
}
|
|
26
|
+
export function breakLines(content, terminalWidth = 0) {
|
|
27
|
+
if (terminalWidth === 0) {
|
|
28
|
+
terminalWidth = getTerminalWidth();
|
|
29
|
+
}
|
|
30
|
+
return content.split("\n").flatMap(
|
|
31
|
+
(line) => wrapAnsi(line, terminalWidth, { trim: false, hard: true }).split("\n").map((str) => str.trimEnd())
|
|
32
|
+
).join("\n");
|
|
33
|
+
}
|
|
34
|
+
export function removeCursor() {
|
|
35
|
+
process.stdout.write(cursor.hide);
|
|
36
|
+
}
|
|
37
|
+
export function restoreCursor() {
|
|
38
|
+
process.stdout.write(cursor.show);
|
|
39
|
+
}
|
|
40
|
+
export function deleteLastLine() {
|
|
41
|
+
process.stdout.write(ansiEscapes.cursorUp(1) + ansiEscapes.eraseLine);
|
|
42
|
+
}
|
|
43
|
+
export function deleteLastLines(count) {
|
|
44
|
+
if (count <= 0) {
|
|
45
|
+
console.error("Count is less than or equal to 0. Nothing to delete.");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
process.stdout.write(ansiEscapes.eraseLines(count));
|
|
49
|
+
}
|
|
50
|
+
export function countLines(text) {
|
|
51
|
+
const adjustedWidth = getTerminalWidth();
|
|
52
|
+
const lines = text.split("\n");
|
|
53
|
+
let lineCount = 0;
|
|
54
|
+
for (const line of lines) {
|
|
55
|
+
const wrapped = wrapAnsi(line, adjustedWidth, { hard: true });
|
|
56
|
+
lineCount += wrapped.split("\n").length;
|
|
57
|
+
}
|
|
58
|
+
return lineCount;
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ColorName, VariantName } from "../../core-types.js";
|
|
2
|
+
export declare const variantMap: {
|
|
3
|
+
doubleBox: typeof createDoubleBox;
|
|
4
|
+
};
|
|
5
|
+
type ValidVariant = keyof typeof variantMap;
|
|
6
|
+
export declare function isValidVariant(variant: string | undefined): variant is ValidVariant;
|
|
7
|
+
export declare function applyVariant(lines: string[] | string, variant?: VariantName, options?: {
|
|
8
|
+
limit?: number;
|
|
9
|
+
}, borderColor?: ColorName): Promise<string>;
|
|
10
|
+
declare function createDoubleBox(lines: string[], limit?: number, borderColor?: ColorName): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { colorMap } from "./mapping.js";
|
|
2
|
+
export const variantMap = {
|
|
3
|
+
// box: createBox,
|
|
4
|
+
doubleBox: createDoubleBox
|
|
5
|
+
// banner: createBanner,
|
|
6
|
+
// underline: createUnderline,
|
|
7
|
+
};
|
|
8
|
+
export function isValidVariant(variant) {
|
|
9
|
+
return variant !== void 0 && variant !== "none" && variant in variantMap;
|
|
10
|
+
}
|
|
11
|
+
export async function applyVariant(lines, variant, options, borderColor) {
|
|
12
|
+
const linesArray = Array.isArray(lines) ? lines : [lines];
|
|
13
|
+
switch (variant) {
|
|
14
|
+
// case "box":
|
|
15
|
+
// return createBox(linesArray, options?.limit);
|
|
16
|
+
case "doubleBox":
|
|
17
|
+
return createDoubleBox(linesArray, options?.limit, borderColor);
|
|
18
|
+
// case "banner":
|
|
19
|
+
// return createBanner(linesArray);
|
|
20
|
+
// case "underline":
|
|
21
|
+
// return createUnderline(linesArray);
|
|
22
|
+
default:
|
|
23
|
+
return linesArray.join("\n");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function createDoubleBox(lines, limit, borderColor) {
|
|
27
|
+
const processedLines = processLines(lines, limit);
|
|
28
|
+
const maxLength = Math.max(...processedLines.map((line) => line.length));
|
|
29
|
+
const indentation = "";
|
|
30
|
+
if (borderColor === void 0) {
|
|
31
|
+
borderColor = "dim";
|
|
32
|
+
}
|
|
33
|
+
const topBorder = borderColor ? colorMap[borderColor](`${"\u2550".repeat(maxLength)}\u2557`) : `${"\u2550".repeat(maxLength)}\u2557`;
|
|
34
|
+
const bottomBorder = borderColor ? colorMap[borderColor](`${indentation}\u255A${"\u2550".repeat(maxLength + 2)}\u255D`) : `${indentation}\u255A${"\u2550".repeat(maxLength + 2)}\u255D`;
|
|
35
|
+
const middle = processedLines.map((line, index) => {
|
|
36
|
+
const lineIndentation = index === 0 ? indentation : `${indentation} `;
|
|
37
|
+
return `${lineIndentation}${borderColor ? colorMap[borderColor]("\u2551") : "\u2551"} ${colorMap[borderColor](line.padEnd(maxLength))} ${borderColor ? colorMap[borderColor]("\u2551") : "\u2551"}`;
|
|
38
|
+
}).join("\n");
|
|
39
|
+
return `${topBorder}
|
|
40
|
+
${middle}
|
|
41
|
+
${bottomBorder}`;
|
|
42
|
+
}
|
|
43
|
+
function processLines(lines, limit) {
|
|
44
|
+
const linesArray = Array.isArray(lines) ? lines : [lines];
|
|
45
|
+
return linesArray.map((line) => {
|
|
46
|
+
let truncatedLine = line;
|
|
47
|
+
if (limit && line.length > limit) {
|
|
48
|
+
truncatedLine = `${line.slice(0, limit - 3)}...`;
|
|
49
|
+
}
|
|
50
|
+
return truncatedLine.padEnd(limit || truncatedLine.length);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TypographyName, ColorName } from "../../core-types.js";
|
|
2
|
+
import type { VariantName } from "../../core-types.js";
|
|
3
|
+
type NextStepsPromptOptions = {
|
|
4
|
+
title?: string;
|
|
5
|
+
titleColor?: ColorName;
|
|
6
|
+
titleVariant?: VariantName;
|
|
7
|
+
titleTypography?: TypographyName;
|
|
8
|
+
content: string[];
|
|
9
|
+
contentColor?: ColorName;
|
|
10
|
+
contentVariant?: VariantName;
|
|
11
|
+
contentTypography?: TypographyName;
|
|
12
|
+
};
|
|
13
|
+
export declare function nextStepsPrompt(options: NextStepsPromptOptions): Promise<void>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { msg } from "../msg-fmt/messages.js";
|
|
2
|
+
export async function nextStepsPrompt(options) {
|
|
3
|
+
const {
|
|
4
|
+
title = "",
|
|
5
|
+
titleColor = "cyan",
|
|
6
|
+
titleVariant,
|
|
7
|
+
titleTypography = "none",
|
|
8
|
+
content = [],
|
|
9
|
+
contentColor = "dim",
|
|
10
|
+
contentVariant,
|
|
11
|
+
contentTypography = "italic"
|
|
12
|
+
} = options;
|
|
13
|
+
msg({
|
|
14
|
+
type: "M_INFO",
|
|
15
|
+
title,
|
|
16
|
+
titleColor,
|
|
17
|
+
titleTypography,
|
|
18
|
+
...titleVariant ? { titleVariant } : {},
|
|
19
|
+
content: Array.isArray(content) ? content.join("\n") : content,
|
|
20
|
+
contentColor,
|
|
21
|
+
contentTypography,
|
|
22
|
+
...contentVariant ? { contentVariant } : {}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BorderColorName, ColorName, FmtMsgOptions, TypographyName } from "../../core-types.js";
|
|
2
|
+
type VariantName = FmtMsgOptions["titleVariant"];
|
|
3
|
+
type NumberPromptOptions = {
|
|
4
|
+
title: string;
|
|
5
|
+
hint?: string;
|
|
6
|
+
hintPlaceholderColor?: ColorName;
|
|
7
|
+
validate?: (value: number) => string | undefined | boolean | Promise<string | undefined | boolean>;
|
|
8
|
+
defaultValue?: string | number;
|
|
9
|
+
schema?: any;
|
|
10
|
+
titleColor?: ColorName;
|
|
11
|
+
titleTypography?: TypographyName;
|
|
12
|
+
titleVariant?: VariantName;
|
|
13
|
+
content?: string;
|
|
14
|
+
contentColor?: ColorName;
|
|
15
|
+
contentTypography?: TypographyName;
|
|
16
|
+
contentVariant?: VariantName;
|
|
17
|
+
borderColor?: BorderColorName;
|
|
18
|
+
variantOptions?: any;
|
|
19
|
+
endTitle?: string;
|
|
20
|
+
endTitleColor?: ColorName;
|
|
21
|
+
border?: boolean;
|
|
22
|
+
hardcoded?: {
|
|
23
|
+
userInput?: string;
|
|
24
|
+
errorMessage?: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare function numberPrompt(opts: NumberPromptOptions): Promise<number>;
|
|
28
|
+
export {};
|