@reliverse/relinka 1.2.7 → 1.2.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.
|
@@ -4,7 +4,7 @@ import { type VariantName } from "./variants.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Known symbol names that will have IntelliSense support
|
|
6
6
|
*/
|
|
7
|
-
export type SymbolName = "pointer" | "start" | "middle" | "end" | "line" | "corner_top_right" | "step_active" | "step_error" | "info";
|
|
7
|
+
export type SymbolName = "pointer" | "start" | "middle" | "end" | "line" | "corner_top_right" | "step_active" | "step_error" | "info" | "success";
|
|
8
8
|
export type FmtMsgOptions = {
|
|
9
9
|
type: MsgType;
|
|
10
10
|
title?: string;
|
|
@@ -54,14 +54,13 @@ export declare const symbols: {
|
|
|
54
54
|
readonly success: string;
|
|
55
55
|
};
|
|
56
56
|
/**
|
|
57
|
-
* Returns a colored vertical bar symbol.
|
|
57
|
+
* Returns a colored vertical bar symbol. Prevents gradient colors for bars.
|
|
58
58
|
*/
|
|
59
|
-
export declare const bar: ({ borderColor, }
|
|
59
|
+
export declare const bar: ({ borderColor, }?: {
|
|
60
60
|
borderColor?: ColorName;
|
|
61
61
|
}) => string;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
64
|
-
* Returns both the formatted text and the number of lines it would occupy.
|
|
63
|
+
* Main formatter function: builds the final text output based on FmtMsgOptions.
|
|
65
64
|
*/
|
|
66
65
|
export declare function fmt(opts: FmtMsgOptions): {
|
|
67
66
|
text: string;
|
|
@@ -83,7 +82,6 @@ export declare function msgUndoAll(): void;
|
|
|
83
82
|
/**
|
|
84
83
|
* Prints: "│ <text>" (two spaces after the bar).
|
|
85
84
|
* If text is empty, it just prints "│".
|
|
86
|
-
* If indent is 1, it prints "│ <text>"
|
|
87
|
-
* If indent is 2, it prints "│ <text>" (two spaces), etc.
|
|
85
|
+
* If indent is 1, it prints "│ <text>", etc.
|
|
88
86
|
*/
|
|
89
87
|
export declare function printLineBar(text: string, indent?: number): void;
|
|
@@ -22,44 +22,35 @@ export const symbols = {
|
|
|
22
22
|
info: u("\u2139", "i"),
|
|
23
23
|
success: u("\u2705", "\u2713")
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const isOption = line.startsWith(" ") || line.startsWith("[ ]") || line.startsWith("[x]");
|
|
33
|
-
return applyStyles(
|
|
34
|
-
line,
|
|
35
|
-
colorName && !isOption ? colorName : void 0,
|
|
36
|
-
typographyName && !isOption ? typographyName : void 0,
|
|
37
|
-
variantName && variantName !== "none" ? variantName : void 0,
|
|
38
|
-
borderColor
|
|
39
|
-
);
|
|
40
|
-
}).join("\n");
|
|
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");
|
|
41
32
|
}
|
|
42
33
|
function applyStyles(text, colorName, typographyName, variantName, borderColor) {
|
|
43
34
|
let styledText = text;
|
|
44
|
-
if (
|
|
45
|
-
if (colorName && colorMap[colorName]) {
|
|
46
|
-
styledText = colorMap[colorName](styledText);
|
|
47
|
-
}
|
|
48
|
-
if (typographyName && typographyMap[typographyName]) {
|
|
49
|
-
styledText = typographyMap[typographyName](styledText);
|
|
50
|
-
}
|
|
51
|
-
} else if (variantName) {
|
|
35
|
+
if (variantName && isValidVariant(variantName)) {
|
|
52
36
|
styledText = variantMap[variantName](
|
|
53
37
|
[styledText],
|
|
54
38
|
void 0,
|
|
55
39
|
borderColor
|
|
56
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);
|
|
57
48
|
}
|
|
58
49
|
return styledText;
|
|
59
50
|
}
|
|
60
51
|
export const bar = ({
|
|
61
52
|
borderColor = "dim"
|
|
62
|
-
}) => {
|
|
53
|
+
} = {}) => {
|
|
63
54
|
if (borderColor.endsWith("Gradient")) {
|
|
64
55
|
console.error(
|
|
65
56
|
"Gradient colors are not supported for bars. Please use a solid color instead."
|
|
@@ -71,22 +62,87 @@ export const bar = ({
|
|
|
71
62
|
function countLines(text) {
|
|
72
63
|
return text.split("\n").length;
|
|
73
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
|
+
}
|
|
74
129
|
export function fmt(opts) {
|
|
75
130
|
if (!opts.borderColor) {
|
|
76
131
|
opts.borderColor = "dim";
|
|
77
132
|
}
|
|
78
|
-
const
|
|
133
|
+
const borderColored = applyStyles(symbols.middle, opts.borderColor);
|
|
79
134
|
const borderError = applyStyles(symbols.middle, "red");
|
|
80
|
-
const
|
|
135
|
+
const borderTwoSpaces = `${borderColored} `;
|
|
81
136
|
const prefixStartLine = opts.borderColor ? colorMap[opts.borderColor](symbols.start + symbols.line) : symbols.start + symbols.line;
|
|
82
137
|
const prefixEndLine = opts.borderColor ? colorMap[opts.borderColor](symbols.end + symbols.line) : symbols.end + symbols.line;
|
|
83
138
|
const lineLength = opts.horizontalLineLength === 0 ? getExactTerminalWidth() - 3 : opts.horizontalLineLength ?? getExactTerminalWidth() - 3;
|
|
84
139
|
const suffixStartLine = opts.borderColor ? colorMap[opts.borderColor](`${symbols.line.repeat(lineLength)}\u22B1`) : `${symbols.line.repeat(lineLength)}\u22B1`;
|
|
85
140
|
const suffixEndLine = opts.borderColor ? colorMap[opts.borderColor](`${symbols.line.repeat(lineLength)}\u22B1`) : `${symbols.line.repeat(lineLength)}\u22B1`;
|
|
86
|
-
const
|
|
141
|
+
const computedSymbol = getColoredSymbol(opts.customSymbol, opts.symbol, opts.symbolColor) ?? pc.green(symbols.step_active);
|
|
142
|
+
const MESSAGE_CONFIG_MAP = {
|
|
87
143
|
M_NULL: {
|
|
88
144
|
symbol: "",
|
|
89
|
-
prefix:
|
|
145
|
+
prefix: borderTwoSpaces,
|
|
90
146
|
suffix: "",
|
|
91
147
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
92
148
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
@@ -100,7 +156,7 @@ export function fmt(opts) {
|
|
|
100
156
|
},
|
|
101
157
|
M_INFO_NULL: {
|
|
102
158
|
symbol: "",
|
|
103
|
-
prefix:
|
|
159
|
+
prefix: borderTwoSpaces,
|
|
104
160
|
suffix: "",
|
|
105
161
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
106
162
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
@@ -109,47 +165,49 @@ export function fmt(opts) {
|
|
|
109
165
|
symbol: "",
|
|
110
166
|
prefix: "",
|
|
111
167
|
suffix: `
|
|
112
|
-
${
|
|
168
|
+
${borderTwoSpaces}`,
|
|
113
169
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
114
170
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
115
171
|
},
|
|
116
172
|
M_MIDDLE: {
|
|
117
173
|
symbol: "",
|
|
118
|
-
prefix:
|
|
174
|
+
prefix: borderTwoSpaces,
|
|
119
175
|
suffix: "",
|
|
120
176
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
121
177
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
122
178
|
},
|
|
123
179
|
M_GENERAL: {
|
|
124
|
-
symbol:
|
|
125
|
-
prefix:
|
|
180
|
+
symbol: computedSymbol,
|
|
181
|
+
prefix: borderTwoSpaces,
|
|
126
182
|
suffix: "",
|
|
127
183
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
128
184
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
129
185
|
},
|
|
130
186
|
M_GENERAL_NULL: {
|
|
131
187
|
symbol: "",
|
|
132
|
-
prefix:
|
|
188
|
+
prefix: borderTwoSpaces,
|
|
133
189
|
suffix: opts.placeholder ? colorMap[opts.hintPlaceholderColor ?? "blue"](opts.placeholder) : "",
|
|
134
190
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
135
191
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
136
192
|
},
|
|
137
193
|
M_INFO: {
|
|
138
|
-
symbol:
|
|
139
|
-
prefix:
|
|
194
|
+
symbol: computedSymbol || pc.green(symbols.info),
|
|
195
|
+
prefix: borderTwoSpaces,
|
|
140
196
|
suffix: "",
|
|
141
197
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
142
198
|
newLineAfter: opts.addNewLineAfter ?? true
|
|
143
199
|
},
|
|
144
200
|
M_ERROR: {
|
|
145
|
-
symbol:
|
|
146
|
-
prefix:
|
|
201
|
+
symbol: computedSymbol || pc.redBright(symbols.step_error),
|
|
202
|
+
prefix: borderTwoSpaces,
|
|
203
|
+
suffix: "",
|
|
147
204
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
148
205
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
149
206
|
},
|
|
150
207
|
M_ERROR_NULL: {
|
|
151
208
|
symbol: "",
|
|
152
|
-
prefix:
|
|
209
|
+
prefix: borderTwoSpaces,
|
|
210
|
+
suffix: "",
|
|
153
211
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
154
212
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
155
213
|
},
|
|
@@ -162,111 +220,31 @@ ${borderWithSpace}`,
|
|
|
162
220
|
},
|
|
163
221
|
M_NEWLINE: {
|
|
164
222
|
symbol: "",
|
|
165
|
-
prefix:
|
|
223
|
+
prefix: borderTwoSpaces,
|
|
224
|
+
suffix: "",
|
|
166
225
|
newLineBefore: opts.addNewLineBefore ?? false,
|
|
167
226
|
newLineAfter: opts.addNewLineAfter ?? false
|
|
168
227
|
}
|
|
169
228
|
};
|
|
170
|
-
const config =
|
|
229
|
+
const config = MESSAGE_CONFIG_MAP[opts.type];
|
|
171
230
|
if (!config) {
|
|
172
231
|
throw new Error(`Invalid message type: ${opts.type}`);
|
|
173
232
|
}
|
|
174
|
-
const {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
newLineBefore = false,
|
|
178
|
-
newLineAfter = false
|
|
179
|
-
} = config;
|
|
180
|
-
function validateColorName(colorName) {
|
|
181
|
-
if (!colorMap[colorName]) {
|
|
182
|
-
throw new Error(`Invalid color name: ${colorName}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
let formattedTitle = "";
|
|
186
|
-
if (opts.title) {
|
|
187
|
-
const rawTitle = opts.title;
|
|
188
|
-
if (opts.wrapTitle ?? true) {
|
|
189
|
-
formattedTitle = wrapAndStyleText(
|
|
190
|
-
rawTitle,
|
|
191
|
-
opts.titleTypography ?? "bold",
|
|
192
|
-
opts.titleColor ?? "cyan",
|
|
193
|
-
opts.titleVariant,
|
|
194
|
-
opts.borderColor
|
|
195
|
-
);
|
|
196
|
-
} else {
|
|
197
|
-
formattedTitle = applyStyles(
|
|
198
|
-
rawTitle,
|
|
199
|
-
opts.titleColor ?? "cyan",
|
|
200
|
-
opts.titleTypography ?? "bold",
|
|
201
|
-
opts.titleVariant,
|
|
202
|
-
opts.borderColor
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
if (opts.hint) {
|
|
206
|
-
const hintPlaceholderColor = opts.hintPlaceholderColor ?? "blue";
|
|
207
|
-
if (opts.hintPlaceholderColor) {
|
|
208
|
-
validateColorName(opts.hintPlaceholderColor);
|
|
209
|
-
}
|
|
210
|
-
const formattedHint = wrapAndStyleText(
|
|
211
|
-
opts.hint,
|
|
212
|
-
opts.hintTypography ?? "italic",
|
|
213
|
-
hintPlaceholderColor,
|
|
214
|
-
void 0,
|
|
215
|
-
opts.borderColor
|
|
216
|
-
);
|
|
217
|
-
formattedTitle += `
|
|
218
|
-
${borderWithSpace}${formattedHint}`;
|
|
219
|
-
}
|
|
220
|
-
if (opts.placeholder && opts.type === "M_GENERAL") {
|
|
221
|
-
formattedTitle += `
|
|
222
|
-
${borderWithSpace}${colorMap[opts.hintPlaceholderColor ?? "blue"](opts.placeholder)}`;
|
|
223
|
-
}
|
|
224
|
-
if (opts.errorMessage) {
|
|
225
|
-
const formattedError = applyStyles(
|
|
226
|
-
opts.errorMessage,
|
|
227
|
-
"red",
|
|
228
|
-
"bold",
|
|
229
|
-
"",
|
|
230
|
-
opts.borderColor
|
|
231
|
-
);
|
|
232
|
-
formattedTitle += `
|
|
233
|
-
${borderError} ${formattedError}`;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
let formattedContent = "";
|
|
237
|
-
if (opts.content) {
|
|
238
|
-
const rawContent = opts.content;
|
|
239
|
-
if (opts.wrapContent ?? true) {
|
|
240
|
-
formattedContent = wrapAndStyleText(
|
|
241
|
-
rawContent,
|
|
242
|
-
opts.contentTypography ?? "italic",
|
|
243
|
-
opts.contentColor ?? "dim",
|
|
244
|
-
opts.contentVariant,
|
|
245
|
-
opts.borderColor
|
|
246
|
-
);
|
|
247
|
-
} else {
|
|
248
|
-
formattedContent = applyStyles(
|
|
249
|
-
rawContent,
|
|
250
|
-
opts.contentColor ?? "dim",
|
|
251
|
-
opts.contentTypography ?? "italic",
|
|
252
|
-
opts.contentVariant,
|
|
253
|
-
opts.borderColor
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
233
|
+
const { symbol, suffix, newLineBefore, newLineAfter } = config;
|
|
234
|
+
const finalTitle = formatTitle(opts, borderTwoSpaces, borderError);
|
|
235
|
+
const finalContent = formatContent(opts);
|
|
257
236
|
let text = "";
|
|
258
237
|
if (opts.type === "M_BAR") {
|
|
259
238
|
text = bar({ borderColor: opts.borderColor });
|
|
260
239
|
} else {
|
|
261
|
-
text = [
|
|
262
|
-
`);
|
|
240
|
+
text = [finalTitle, finalContent].filter(Boolean).join("\n");
|
|
263
241
|
}
|
|
264
242
|
const fullText = [
|
|
265
243
|
newLineBefore ? `
|
|
266
|
-
${
|
|
244
|
+
${borderTwoSpaces}` : "",
|
|
267
245
|
text,
|
|
268
246
|
newLineAfter ? `
|
|
269
|
-
${
|
|
247
|
+
${borderTwoSpaces}` : "",
|
|
270
248
|
suffix
|
|
271
249
|
].filter(Boolean).join("");
|
|
272
250
|
const lines = fullText.split("\n").map((line, index) => {
|
|
@@ -275,11 +253,12 @@ ${borderWithSpace}` : "",
|
|
|
275
253
|
return `${prefixStartLine} ${line} ${suffixStartLine}`;
|
|
276
254
|
}
|
|
277
255
|
if (index === 1) {
|
|
278
|
-
return
|
|
256
|
+
return borderTwoSpaces;
|
|
279
257
|
}
|
|
280
258
|
}
|
|
281
259
|
if (opts.type === "M_END" && opts.border && index === 0) {
|
|
282
|
-
|
|
260
|
+
if (!opts.title) return "";
|
|
261
|
+
return `${bar({ borderColor: opts.borderColor })} ${line}`;
|
|
283
262
|
}
|
|
284
263
|
if (!line.trim() || line.includes(symbols.middle)) {
|
|
285
264
|
return line;
|
|
@@ -287,7 +266,7 @@ ${borderWithSpace}` : "",
|
|
|
287
266
|
if (index === 0 && symbol) {
|
|
288
267
|
return `${symbol} ${line}`;
|
|
289
268
|
}
|
|
290
|
-
return `${
|
|
269
|
+
return `${config.prefix}${line}`;
|
|
291
270
|
});
|
|
292
271
|
if (opts.type === "M_END" && opts.border) {
|
|
293
272
|
lines.push(`${prefixEndLine}${suffixEndLine}
|
|
@@ -300,8 +279,7 @@ ${borderWithSpace}` : "",
|
|
|
300
279
|
const printedLineStack = [];
|
|
301
280
|
export function msg(opts) {
|
|
302
281
|
const { text, lineCount } = fmt(opts);
|
|
303
|
-
process.stdout.write(text +
|
|
304
|
-
`);
|
|
282
|
+
process.stdout.write(text + "\n");
|
|
305
283
|
printedLineStack.push(lineCount + 1);
|
|
306
284
|
}
|
|
307
285
|
export function msgUndo(count = 1) {
|
|
@@ -323,7 +301,7 @@ export function msgUndoAll() {
|
|
|
323
301
|
export function printLineBar(text, indent = 2) {
|
|
324
302
|
if (text === "") {
|
|
325
303
|
console.log(pc.dim("\u2502"));
|
|
326
|
-
|
|
327
|
-
console.log(`${pc.dim("\u2502")}${" ".repeat(indent)}${text}`);
|
|
304
|
+
return;
|
|
328
305
|
}
|
|
306
|
+
console.log(`${pc.dim("\u2502")}${" ".repeat(indent)}${text}`);
|
|
329
307
|
}
|