@reliverse/relinka 1.3.0 → 1.3.2
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/dist-npm/components/relinka/logger.d.ts +5 -12
- package/dist-npm/components/relinka/logger.js +4 -51
- package/dist-npm/main.d.ts +0 -1
- package/dist-npm/main.js +0 -1
- package/package.json +1 -1
- package/dist-npm/components/messages/mapping.d.ts +0 -3
- package/dist-npm/components/messages/mapping.js +0 -49
- package/dist-npm/components/messages/messages.d.ts +0 -88
- package/dist-npm/components/messages/messages.js +0 -306
- package/dist-npm/components/messages/mod.d.ts +0 -5
- package/dist-npm/components/messages/mod.js +0 -5
- package/dist-npm/components/messages/terminal.d.ts +0 -15
- package/dist-npm/components/messages/terminal.js +0 -57
- package/dist-npm/components/messages/types.d.ts +0 -12
- package/dist-npm/components/messages/types.js +0 -0
- package/dist-npm/components/messages/variants.d.ts +0 -12
- package/dist-npm/components/messages/variants.js +0 -52
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
titleColor?: "retroGradient" | "viceGradient" | "yellowBright";
|
|
7
|
-
titleTypography?: "bold";
|
|
8
|
-
contentColor?: "dim";
|
|
9
|
-
contentTypography?: "italic";
|
|
10
|
-
};
|
|
11
|
-
export declare const relinka: (kind: AllKinds, title: string, content?: string, hint?: string) => void;
|
|
12
|
-
export declare const throwError: (error: unknown) => never;
|
|
1
|
+
type MessageKind = "log" | "info" | "warn" | "error" | "success";
|
|
2
|
+
type VerboseKind = `${MessageKind}-verbose`;
|
|
3
|
+
type AllKinds = MessageKind | VerboseKind;
|
|
4
|
+
export declare const deprecatedRelinka: (_kind: AllKinds, title: string, content?: string, hint?: string) => void;
|
|
5
|
+
export {};
|
|
@@ -1,52 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type: "M_INFO",
|
|
6
|
-
titleColor: "retroGradient",
|
|
7
|
-
titleTypography: "bold"
|
|
8
|
-
},
|
|
9
|
-
info: {
|
|
10
|
-
type: "M_INFO",
|
|
11
|
-
titleColor: "retroGradient",
|
|
12
|
-
titleTypography: "bold"
|
|
13
|
-
},
|
|
14
|
-
success: {
|
|
15
|
-
type: "M_INFO",
|
|
16
|
-
titleColor: "viceGradient",
|
|
17
|
-
titleTypography: "bold"
|
|
18
|
-
},
|
|
19
|
-
warn: {
|
|
20
|
-
type: "M_ERROR",
|
|
21
|
-
titleColor: "yellowBright",
|
|
22
|
-
titleTypography: "bold"
|
|
23
|
-
},
|
|
24
|
-
error: {
|
|
25
|
-
type: "M_ERROR",
|
|
26
|
-
titleColor: "yellowBright",
|
|
27
|
-
titleTypography: "bold"
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export const relinka = (kind, title, content, hint) => {
|
|
31
|
-
const isVerbose = kind.endsWith("-verbose");
|
|
32
|
-
const baseKind = isVerbose ? kind.replace("-verbose", "") : kind;
|
|
33
|
-
if (isVerbose && !verboseLogging) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const config = MESSAGE_CONFIGS[baseKind];
|
|
37
|
-
msg({
|
|
38
|
-
...config,
|
|
39
|
-
title: isVerbose ? `[debug] ${title}` : title,
|
|
40
|
-
content: content ?? "",
|
|
41
|
-
contentColor: "dim",
|
|
42
|
-
contentTypography: "italic",
|
|
43
|
-
hint: hint ?? ""
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
export const throwError = (error) => {
|
|
47
|
-
msg({
|
|
48
|
-
type: "M_ERROR",
|
|
49
|
-
title: error instanceof Error ? `\u{1F914} Failed to set up the project: ${error.message}` : "\u{1F914} An unknown error occurred."
|
|
50
|
-
});
|
|
51
|
-
process.exit(1);
|
|
1
|
+
export const deprecatedRelinka = (_kind, title, content, hint) => {
|
|
2
|
+
console.log(`${title}
|
|
3
|
+
${content}
|
|
4
|
+
${hint}`);
|
|
52
5
|
};
|
package/dist-npm/main.d.ts
CHANGED
package/dist-npm/main.js
CHANGED
package/package.json
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { re } from "@reliverse/relico";
|
|
2
|
-
import gradient, { cristal, mind, passion, retro, vice } from "gradient-string";
|
|
3
|
-
import { rainbow } from "gradient-string";
|
|
4
|
-
export const colorMap = {
|
|
5
|
-
// @reliverse/relico
|
|
6
|
-
none: (text) => text,
|
|
7
|
-
reset: re.reset,
|
|
8
|
-
bgCyan: re.bgCyan,
|
|
9
|
-
bgCyanBright: re.bgCyanBright,
|
|
10
|
-
black: re.black,
|
|
11
|
-
blue: re.blue,
|
|
12
|
-
blueBright: re.blueBright,
|
|
13
|
-
cyan: re.cyan,
|
|
14
|
-
cyanBright: re.cyanBright,
|
|
15
|
-
dim: re.dim,
|
|
16
|
-
gray: re.gray,
|
|
17
|
-
green: re.green,
|
|
18
|
-
greenBright: re.greenBright,
|
|
19
|
-
inverse: (text) => re.bold(re.inverse(text)),
|
|
20
|
-
magenta: re.magenta,
|
|
21
|
-
magentaBright: re.magentaBright,
|
|
22
|
-
red: re.red,
|
|
23
|
-
redBright: re.redBright,
|
|
24
|
-
white: re.white,
|
|
25
|
-
yellow: re.yellow,
|
|
26
|
-
yellowBright: re.yellowBright,
|
|
27
|
-
// gradient-string
|
|
28
|
-
cristalGradient: cristal,
|
|
29
|
-
gradientGradient: gradient([
|
|
30
|
-
"red",
|
|
31
|
-
"yellow",
|
|
32
|
-
"green",
|
|
33
|
-
"cyan",
|
|
34
|
-
"blue",
|
|
35
|
-
"magenta"
|
|
36
|
-
]),
|
|
37
|
-
mindGradient: mind,
|
|
38
|
-
passionGradient: passion,
|
|
39
|
-
rainbowGradient: rainbow,
|
|
40
|
-
retroGradient: retro,
|
|
41
|
-
viceGradient: vice
|
|
42
|
-
};
|
|
43
|
-
export const typographyMap = {
|
|
44
|
-
none: (text) => text,
|
|
45
|
-
bold: re.bold,
|
|
46
|
-
italic: re.italic,
|
|
47
|
-
strikethrough: re.strikethrough,
|
|
48
|
-
underline: re.underline
|
|
49
|
-
};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { TypographyName } from "./types.js";
|
|
2
|
-
import type { ColorName, MsgType } from "./types.js";
|
|
3
|
-
import { type VariantName } from "./variants.js";
|
|
4
|
-
/**
|
|
5
|
-
* Known symbol names that will have IntelliSense support
|
|
6
|
-
*/
|
|
7
|
-
export type SymbolName = "pointer" | "start" | "middle" | "end" | "line" | "corner_top_right" | "step_active" | "step_error" | "info" | "success";
|
|
8
|
-
export type FmtMsgOptions = {
|
|
9
|
-
type: MsgType;
|
|
10
|
-
title?: string;
|
|
11
|
-
titleAfterAnim?: string;
|
|
12
|
-
content?: string | undefined;
|
|
13
|
-
titleColor?: ColorName;
|
|
14
|
-
titleTypography?: TypographyName;
|
|
15
|
-
titleVariant?: VariantName;
|
|
16
|
-
contentColor?: ColorName;
|
|
17
|
-
contentTypography?: TypographyName;
|
|
18
|
-
contentVariant?: VariantName;
|
|
19
|
-
hint?: string;
|
|
20
|
-
hintPlaceholderColor?: ColorName;
|
|
21
|
-
hintTypography?: TypographyName;
|
|
22
|
-
border?: boolean;
|
|
23
|
-
borderColor?: ColorName;
|
|
24
|
-
dontRemoveBar?: boolean;
|
|
25
|
-
variantOptions?: {
|
|
26
|
-
box?: {
|
|
27
|
-
limit?: number;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
errorMessage?: string;
|
|
31
|
-
addNewLineBefore?: boolean;
|
|
32
|
-
addNewLineAfter?: boolean;
|
|
33
|
-
placeholder?: string;
|
|
34
|
-
horizontalLine?: boolean;
|
|
35
|
-
horizontalLineLength?: number;
|
|
36
|
-
terminalWidth?: number;
|
|
37
|
-
instructions?: string;
|
|
38
|
-
wrapTitle?: boolean;
|
|
39
|
-
wrapContent?: boolean;
|
|
40
|
-
symbol?: SymbolName;
|
|
41
|
-
customSymbol?: string;
|
|
42
|
-
symbolColor?: ColorName;
|
|
43
|
-
};
|
|
44
|
-
export declare const symbols: {
|
|
45
|
-
readonly pointer: string;
|
|
46
|
-
readonly start: string;
|
|
47
|
-
readonly middle: string;
|
|
48
|
-
readonly end: string;
|
|
49
|
-
readonly line: string;
|
|
50
|
-
readonly corner_top_right: string;
|
|
51
|
-
readonly step_active: string;
|
|
52
|
-
readonly step_error: string;
|
|
53
|
-
readonly info: string;
|
|
54
|
-
readonly success: string;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Returns a colored vertical bar symbol. Prevents gradient colors for bars.
|
|
58
|
-
*/
|
|
59
|
-
export declare const bar: ({ borderColor, }?: {
|
|
60
|
-
borderColor?: ColorName;
|
|
61
|
-
}) => string;
|
|
62
|
-
/**
|
|
63
|
-
* Main formatter function: builds the final text output based on FmtMsgOptions.
|
|
64
|
-
*/
|
|
65
|
-
export declare function fmt(opts: FmtMsgOptions): {
|
|
66
|
-
text: string;
|
|
67
|
-
lineCount: number;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Logs a formatted message to the console and records how many lines it occupies.
|
|
71
|
-
*/
|
|
72
|
-
export declare function msg(opts: FmtMsgOptions): void;
|
|
73
|
-
/**
|
|
74
|
-
* Undo the last printed message by deleting its lines from the terminal.
|
|
75
|
-
* @param count How many messages to undo. Defaults to 1.
|
|
76
|
-
*/
|
|
77
|
-
export declare function msgUndo(count?: number): void;
|
|
78
|
-
/**
|
|
79
|
-
* Undo all printed messages so far.
|
|
80
|
-
*/
|
|
81
|
-
export declare function msgUndoAll(): void;
|
|
82
|
-
/**
|
|
83
|
-
* Prints: "│ <text>" (two spaces after the bar).
|
|
84
|
-
* If text is empty, it just prints "│".
|
|
85
|
-
* If indent is 1, it prints "│ <text>" (one space).
|
|
86
|
-
* If indent is 2, it prints "│ <text>" (two spaces), etc.
|
|
87
|
-
*/
|
|
88
|
-
export declare function printLineBar(text: string, indent?: number): void;
|
|
@@ -1,306 +0,0 @@
|
|
|
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 } = fmt(opts);
|
|
282
|
-
process.stdout.write(text);
|
|
283
|
-
}
|
|
284
|
-
export function msgUndo(count = 1) {
|
|
285
|
-
for (let i = 0; i < count; i++) {
|
|
286
|
-
const linesToDelete = printedLineStack.pop();
|
|
287
|
-
if (typeof linesToDelete === "number" && linesToDelete > 0) {
|
|
288
|
-
deleteLastLines(linesToDelete);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
export function msgUndoAll() {
|
|
293
|
-
while (printedLineStack.length > 0) {
|
|
294
|
-
const linesToDelete = printedLineStack.pop();
|
|
295
|
-
if (typeof linesToDelete === "number" && linesToDelete > 0) {
|
|
296
|
-
deleteLastLines(linesToDelete);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
export function printLineBar(text, indent = 2) {
|
|
301
|
-
if (text === "") {
|
|
302
|
-
console.log(re.dim("\u2502"));
|
|
303
|
-
} else {
|
|
304
|
-
console.log(`${re.dim("\u2502")}${" ".repeat(indent)}${text}`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
} else if (terminalWidth > 120) {
|
|
18
|
-
return terminalWidth - 30;
|
|
19
|
-
} else if (terminalWidth > 100) {
|
|
20
|
-
return terminalWidth - 20;
|
|
21
|
-
}
|
|
22
|
-
return terminalWidth;
|
|
23
|
-
}
|
|
24
|
-
export function breakLines(content, terminalWidth = 0) {
|
|
25
|
-
if (terminalWidth === 0) {
|
|
26
|
-
terminalWidth = getTerminalWidth();
|
|
27
|
-
}
|
|
28
|
-
return content.split("\n").flatMap(
|
|
29
|
-
(line) => wrapAnsi(line, terminalWidth, { trim: false, hard: true }).split("\n").map((str) => str.trimEnd())
|
|
30
|
-
).join("\n");
|
|
31
|
-
}
|
|
32
|
-
export function removeCursor() {
|
|
33
|
-
process.stdout.write(cursor.hide);
|
|
34
|
-
}
|
|
35
|
-
export function restoreCursor() {
|
|
36
|
-
process.stdout.write(cursor.show);
|
|
37
|
-
}
|
|
38
|
-
export function deleteLastLine() {
|
|
39
|
-
process.stdout.write(ansiEscapes.cursorUp(1) + ansiEscapes.eraseLine);
|
|
40
|
-
}
|
|
41
|
-
export function deleteLastLines(count) {
|
|
42
|
-
if (count <= 0) {
|
|
43
|
-
console.error("Count is less than or equal to 0. Nothing to delete.");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
process.stdout.write(ansiEscapes.eraseLines(count));
|
|
47
|
-
}
|
|
48
|
-
export function countLines(text) {
|
|
49
|
-
const adjustedWidth = getTerminalWidth();
|
|
50
|
-
const lines = text.split("\n");
|
|
51
|
-
let lineCount = 0;
|
|
52
|
-
for (const line of lines) {
|
|
53
|
-
const wrapped = wrapAnsi(line, adjustedWidth, { hard: true });
|
|
54
|
-
lineCount += wrapped.split("\n").length;
|
|
55
|
-
}
|
|
56
|
-
return lineCount;
|
|
57
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type MsgType = "M_NULL" | "M_INFO_NULL" | "M_START" | "M_MIDDLE" | "M_GENERAL" | "M_GENERAL_NULL" | "M_INFO" | "M_ERROR" | "M_ERROR_NULL" | "M_END" | "M_NEWLINE" | "M_BAR";
|
|
2
|
-
export type TypographyName = "bold" | "strikethrough" | "underline" | "italic" | "none";
|
|
3
|
-
export type BorderColorName = "reset" | "inverse" | "dim" | "black" | "red" | "redBright" | "green" | "greenBright" | "yellow" | "yellowBright" | "blue" | "blueBright" | "magenta" | "magentaBright" | "cyan" | "cyanBright" | "bgCyan" | "bgCyanBright" | "white" | "gray";
|
|
4
|
-
export type ColorName = BorderColorName | "gradientGradient" | "rainbowGradient" | "cristalGradient" | "mindGradient" | "passionGradient" | "viceGradient" | "retroGradient" | "none";
|
|
5
|
-
export type MsgConfig = {
|
|
6
|
-
symbol: string;
|
|
7
|
-
prefix?: string;
|
|
8
|
-
color?: (text: string) => string;
|
|
9
|
-
newLineBefore?: boolean;
|
|
10
|
-
newLineAfter?: boolean;
|
|
11
|
-
suffix?: string;
|
|
12
|
-
};
|
|
File without changes
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ColorName } from "./types.js";
|
|
2
|
-
export declare const variantMap: {
|
|
3
|
-
doubleBox: typeof createDoubleBox;
|
|
4
|
-
};
|
|
5
|
-
type ValidVariant = keyof typeof variantMap;
|
|
6
|
-
export type VariantName = ValidVariant | "none";
|
|
7
|
-
export declare function isValidVariant(variant: string | undefined): variant is ValidVariant;
|
|
8
|
-
export declare function applyVariant(lines: string[] | string, variant?: VariantName, options?: {
|
|
9
|
-
limit?: number;
|
|
10
|
-
}, borderColor?: ColorName): Promise<string>;
|
|
11
|
-
declare function createDoubleBox(lines: string[], limit?: number, borderColor?: ColorName): string;
|
|
12
|
-
export {};
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
}
|