@reliverse/relinka 1.2.3 → 1.2.5

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 (50) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +2 -8
  3. package/dist-npm/components/levels/levels.d.ts +21 -0
  4. package/dist-npm/components/levels/levels.js +8 -8
  5. package/dist-npm/components/messages/mapping.d.ts +3 -0
  6. package/dist-npm/components/messages/mapping.js +49 -0
  7. package/dist-npm/components/messages/messages.d.ts +89 -0
  8. package/dist-npm/components/messages/messages.js +329 -0
  9. package/dist-npm/components/messages/mod.d.ts +6 -0
  10. package/dist-npm/components/messages/mod.js +6 -0
  11. package/dist-npm/components/messages/platforms.d.ts +10 -0
  12. package/dist-npm/components/messages/platforms.js +67 -0
  13. package/dist-npm/components/messages/terminal.d.ts +15 -0
  14. package/dist-npm/components/messages/terminal.js +57 -0
  15. package/dist-npm/components/messages/types.d.ts +12 -0
  16. package/dist-npm/components/messages/types.js +0 -0
  17. package/dist-npm/components/messages/variants.d.ts +12 -0
  18. package/dist-npm/components/messages/variants.js +52 -0
  19. package/dist-npm/components/modes/basic.d.ts +14 -2
  20. package/dist-npm/components/modes/basic.js +6 -6
  21. package/dist-npm/components/modes/browser.d.ts +16 -2
  22. package/dist-npm/components/modes/browser.js +5 -5
  23. package/dist-npm/components/modes/shared.d.ts +1 -1
  24. package/dist-npm/components/modes/shared.js +1 -1
  25. package/dist-npm/components/relinka/logger.d.ts +12 -0
  26. package/dist-npm/components/relinka/logger.js +52 -0
  27. package/dist-npm/components/relinka/mod.d.ts +21 -0
  28. package/dist-npm/components/relinka/mod.js +34 -0
  29. package/dist-npm/components/relinka/relinka.d.ts +118 -20
  30. package/dist-npm/components/relinka/relinka.js +133 -36
  31. package/dist-npm/components/reporters/basic.d.ts +1 -1
  32. package/dist-npm/components/reporters/basic.js +5 -5
  33. package/dist-npm/components/reporters/browser.js +5 -5
  34. package/dist-npm/components/reporters/fancy.d.ts +1 -1
  35. package/dist-npm/components/reporters/fancy.js +9 -9
  36. package/dist-npm/main.d.ts +3 -8
  37. package/dist-npm/main.js +3 -34
  38. package/dist-npm/types/mod.d.ts +136 -29
  39. package/dist-npm/utils/box.d.ts +104 -14
  40. package/dist-npm/utils/box.js +1 -1
  41. package/dist-npm/utils/color.d.ts +20 -0
  42. package/dist-npm/utils/color.js +3 -3
  43. package/dist-npm/utils/error.d.ts +5 -0
  44. package/dist-npm/utils/format.d.ts +12 -0
  45. package/dist-npm/utils/log.d.ts +11 -0
  46. package/dist-npm/utils/stream.d.ts +13 -0
  47. package/dist-npm/utils/string.d.ts +45 -0
  48. package/dist-npm/utils/tree.d.ts +34 -5
  49. package/package.json +35 -32
  50. package/LICENSE.md +0 -21
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- MIT License
1
+ # MIT License
2
2
 
3
- Copyright (c) 2024 Reliverse
3
+ Copyright (c) 2024 Nazarii Korniienko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -22,18 +22,12 @@
22
22
  --->
23
23
  </p>
24
24
 
25
- @reliverse/relinka is a powerful logger for your terminal.
26
-
27
- @reliverse/relinka is a full-featured alternative to winston, unjs relinka, pino, bristol, node-bunyan, and similar libraries.
28
-
29
- Used by [@reliverse/prompts](https://github.com/reliverse/prompts#readme) and [@reliverse/cli](https://github.com/blefnk/reliverse#readme).
25
+ **Style your terminal or browser console like never before.** @reliverse/relinka is your next powerful logger. It's a full-featured alternative to winston, unjs relinka, pino, bristol, node-bunyan, and similar libraries. Used by [@reliverse/prompts](https://github.com/reliverse/prompts#readme) and [@reliverse/cli](https://github.com/blefnk/reliverse#readme).
30
26
 
31
27
  ## Installation
32
28
 
33
- Install with your preferred package manager:
34
-
35
29
  ```sh
36
- bun add @reliverse/relinka # Replace 'bun' with npm, pnpm, or yarn if desired (deno and full jsr support coming soon)
30
+ bun add @reliverse/relinka # Replace 'bun' with npm, pnpm, or yarn if desired
37
31
  ```
38
32
 
39
33
  ---
@@ -1,5 +1,26 @@
1
1
  import type { LogObject } from "../../types/mod.js";
2
+ /**
3
+ * Defines the level of logs as specific numbers or special number types.
4
+ *
5
+ * @type {0 | 1 | 2 | 3 | 4 | 5 | (number & {})} LogLevel - Represents the log level.
6
+ * @default 0 - Represents the default log level.
7
+ */
2
8
  export type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});
9
+ /**
10
+ * A mapping of `LogType` to its corresponding numeric log level.
11
+ *
12
+ * @type {Record<LogType, number>} LogLevels - key-value pairs of log types to their numeric levels. See {@link LogType}.
13
+ */
3
14
  export declare const LogLevels: Record<LogType, number>;
15
+ /**
16
+ * Lists the types of log messages supported by the system.
17
+ *
18
+ * @type {"silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose"} LogType - Represents the specific type of log message.
19
+ */
4
20
  export type LogType = "silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose";
21
+ /**
22
+ * Maps `LogType` to a `Partial<LogObject>`, primarily defining the log level.
23
+ *
24
+ * @type {Record<LogType, Partial<LogObject>>} LogTypes - key-value pairs of log types to partial log objects, specifying log levels. See {@link LogType} and {@link LogObject}.
25
+ */
5
26
  export declare const LogTypes: Record<LogType, Partial<LogObject>>;
@@ -15,26 +15,26 @@ export const LogLevels = {
15
15
  verbose: Number.POSITIVE_INFINITY
16
16
  };
17
17
  export const LogTypes = {
18
-
18
+ // Silent
19
19
  silent: {
20
20
  level: -1
21
21
  },
22
-
22
+ // Level 0
23
23
  fatal: {
24
24
  level: LogLevels.fatal
25
25
  },
26
26
  error: {
27
27
  level: LogLevels.error
28
28
  },
29
-
29
+ // Level 1
30
30
  warn: {
31
31
  level: LogLevels.warn
32
32
  },
33
-
33
+ // Level 2
34
34
  log: {
35
35
  level: LogLevels.log
36
36
  },
37
-
37
+ // Level 3
38
38
  info: {
39
39
  level: LogLevels.info
40
40
  },
@@ -53,15 +53,15 @@ export const LogTypes = {
53
53
  box: {
54
54
  level: LogLevels.info
55
55
  },
56
-
56
+ // Level 4
57
57
  debug: {
58
58
  level: LogLevels.debug
59
59
  },
60
-
60
+ // Level 5
61
61
  trace: {
62
62
  level: LogLevels.trace
63
63
  },
64
-
64
+ // Verbose
65
65
  verbose: {
66
66
  level: LogLevels.verbose
67
67
  }
@@ -0,0 +1,3 @@
1
+ import type { ColorName, TypographyName } from "./types.js";
2
+ export declare const colorMap: Record<ColorName, (text: string) => string>;
3
+ export declare const typographyMap: Record<TypographyName, (text: string) => string>;
@@ -0,0 +1,49 @@
1
+ import gradient, { cristal, mind, passion, retro, vice } from "gradient-string";
2
+ import { rainbow } from "gradient-string";
3
+ import pc from "picocolors";
4
+ export const colorMap = {
5
+ // picocolors
6
+ none: (text) => text,
7
+ reset: pc.reset,
8
+ bgCyan: pc.bgCyan,
9
+ bgCyanBright: pc.bgCyanBright,
10
+ black: pc.black,
11
+ blue: pc.blue,
12
+ blueBright: pc.blueBright,
13
+ cyan: pc.cyan,
14
+ cyanBright: pc.cyanBright,
15
+ dim: pc.dim,
16
+ gray: pc.gray,
17
+ green: pc.green,
18
+ greenBright: pc.greenBright,
19
+ inverse: (text) => pc.bold(pc.inverse(text)),
20
+ magenta: pc.magenta,
21
+ magentaBright: pc.magentaBright,
22
+ red: pc.red,
23
+ redBright: pc.redBright,
24
+ white: pc.white,
25
+ yellow: pc.yellow,
26
+ yellowBright: pc.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: pc.bold,
46
+ italic: pc.italic,
47
+ strikethrough: pc.strikethrough,
48
+ underline: pc.underline
49
+ };
@@ -0,0 +1,89 @@
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";
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.
58
+ */
59
+ export declare const bar: ({ borderColor, }: {
60
+ borderColor?: ColorName;
61
+ }) => string;
62
+ /**
63
+ * Formats a message line according to the given FmtMsgOptions.
64
+ * Returns both the formatted text and the number of lines it would occupy.
65
+ */
66
+ export declare function fmt(opts: FmtMsgOptions): {
67
+ text: string;
68
+ lineCount: number;
69
+ };
70
+ /**
71
+ * Logs a formatted message to the console and records how many lines it occupies.
72
+ */
73
+ export declare function msg(opts: FmtMsgOptions): void;
74
+ /**
75
+ * Undo the last printed message by deleting its lines from the terminal.
76
+ * @param count How many messages to undo. Defaults to 1.
77
+ */
78
+ export declare function msgUndo(count?: number): void;
79
+ /**
80
+ * Undo all printed messages so far.
81
+ */
82
+ export declare function msgUndoAll(): void;
83
+ /**
84
+ * Prints: "│ <text>" (two spaces after the bar).
85
+ * If text is empty, it just prints "│".
86
+ * If indent is 1, it prints "│ <text>" (one space).
87
+ * If indent is 2, it prints "│ <text>" (two spaces), etc.
88
+ */
89
+ export declare function printLineBar(text: string, indent?: number): void;
@@ -0,0 +1,329 @@
1
+ import pc from "picocolors";
2
+ import wrapAnsi from "wrap-ansi";
3
+ import { colorMap, typographyMap } from "./mapping.js";
4
+ import { isUnicodeSupported } from "./platforms.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 wrapAndStyleText(input, typographyName, colorName, variantName, borderColor) {
26
+ const adjustedWidth = getTerminalWidth();
27
+ const wrappedText = wrapAnsi(input, adjustedWidth, {
28
+ hard: false,
29
+ trim: true
30
+ });
31
+ return wrappedText.split("\n").map((line) => {
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");
41
+ }
42
+ function applyStyles(text, colorName, typographyName, variantName, borderColor) {
43
+ let styledText = text;
44
+ if (!isValidVariant(variantName)) {
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) {
52
+ styledText = variantMap[variantName](
53
+ [styledText],
54
+ void 0,
55
+ borderColor
56
+ ).toString();
57
+ }
58
+ return styledText;
59
+ }
60
+ export const bar = ({
61
+ borderColor = "dim"
62
+ }) => {
63
+ if (borderColor.endsWith("Gradient")) {
64
+ console.error(
65
+ "Gradient colors are not supported for bars. Please use a solid color instead."
66
+ );
67
+ return colorMap.dim(symbols.middle);
68
+ }
69
+ return colorMap[borderColor](symbols.middle);
70
+ };
71
+ function countLines(text) {
72
+ return text.split("\n").length;
73
+ }
74
+ export function fmt(opts) {
75
+ if (!opts.borderColor) {
76
+ opts.borderColor = "dim";
77
+ }
78
+ const border = applyStyles(symbols.middle, opts.borderColor);
79
+ const borderError = applyStyles(symbols.middle, "red");
80
+ const borderWithSpace = `${border} `;
81
+ const prefixStartLine = opts.borderColor ? colorMap[opts.borderColor](symbols.start + symbols.line) : symbols.start + symbols.line;
82
+ const prefixEndLine = opts.borderColor ? colorMap[opts.borderColor](symbols.end + symbols.line) : symbols.end + symbols.line;
83
+ const lineLength = opts.horizontalLineLength === 0 ? getExactTerminalWidth() - 3 : opts.horizontalLineLength ?? getExactTerminalWidth() - 3;
84
+ const suffixStartLine = opts.borderColor ? colorMap[opts.borderColor](`${symbols.line.repeat(lineLength)}\u22B1`) : `${symbols.line.repeat(lineLength)}\u22B1`;
85
+ const suffixEndLine = opts.borderColor ? colorMap[opts.borderColor](`${symbols.line.repeat(lineLength)}\u22B1`) : `${symbols.line.repeat(lineLength)}\u22B1`;
86
+ const MSG_CONFIGS = {
87
+ M_NULL: {
88
+ symbol: "",
89
+ prefix: borderWithSpace,
90
+ suffix: "",
91
+ newLineBefore: opts.addNewLineBefore ?? false,
92
+ newLineAfter: opts.addNewLineAfter ?? false
93
+ },
94
+ M_BAR: {
95
+ symbol: "",
96
+ prefix: "",
97
+ suffix: "",
98
+ newLineBefore: false,
99
+ newLineAfter: false
100
+ },
101
+ M_INFO_NULL: {
102
+ symbol: "",
103
+ prefix: borderWithSpace,
104
+ suffix: "",
105
+ newLineBefore: opts.addNewLineBefore ?? false,
106
+ newLineAfter: opts.addNewLineAfter ?? false
107
+ },
108
+ M_START: {
109
+ symbol: "",
110
+ prefix: "",
111
+ suffix: `
112
+ ${borderWithSpace}`,
113
+ newLineBefore: opts.addNewLineBefore ?? false,
114
+ newLineAfter: opts.addNewLineAfter ?? false
115
+ },
116
+ M_MIDDLE: {
117
+ symbol: "",
118
+ prefix: borderWithSpace,
119
+ suffix: "",
120
+ newLineBefore: opts.addNewLineBefore ?? false,
121
+ newLineAfter: opts.addNewLineAfter ?? false
122
+ },
123
+ M_GENERAL: {
124
+ symbol: opts.customSymbol ? opts.symbolColor ? colorMap[opts.symbolColor](opts.customSymbol) : opts.customSymbol : opts.symbol ? opts.symbolColor ? colorMap[opts.symbolColor](symbols[opts.symbol]) : symbols[opts.symbol] : pc.green(symbols.step_active),
125
+ prefix: borderWithSpace,
126
+ suffix: "",
127
+ newLineBefore: opts.addNewLineBefore ?? false,
128
+ newLineAfter: opts.addNewLineAfter ?? false
129
+ },
130
+ M_GENERAL_NULL: {
131
+ symbol: "",
132
+ prefix: borderWithSpace,
133
+ suffix: opts.placeholder ? colorMap[opts.hintPlaceholderColor ?? "blue"](opts.placeholder) : "",
134
+ newLineBefore: opts.addNewLineBefore ?? false,
135
+ newLineAfter: opts.addNewLineAfter ?? false
136
+ },
137
+ M_INFO: {
138
+ symbol: opts.customSymbol ? opts.symbolColor ? colorMap[opts.symbolColor](opts.customSymbol) : opts.customSymbol : opts.symbol ? opts.symbolColor ? colorMap[opts.symbolColor](symbols[opts.symbol]) : symbols[opts.symbol] : pc.green(symbols.info),
139
+ prefix: borderWithSpace,
140
+ suffix: "",
141
+ newLineBefore: opts.addNewLineBefore ?? false,
142
+ newLineAfter: opts.addNewLineAfter ?? true
143
+ },
144
+ M_ERROR: {
145
+ symbol: opts.customSymbol ? opts.symbolColor ? colorMap[opts.symbolColor](opts.customSymbol) : opts.customSymbol : opts.symbol ? opts.symbolColor ? colorMap[opts.symbolColor](symbols[opts.symbol]) : symbols[opts.symbol] : pc.redBright(symbols.step_error),
146
+ prefix: borderWithSpace,
147
+ newLineBefore: opts.addNewLineBefore ?? false,
148
+ newLineAfter: opts.addNewLineAfter ?? false
149
+ },
150
+ M_ERROR_NULL: {
151
+ symbol: "",
152
+ prefix: borderWithSpace,
153
+ newLineBefore: opts.addNewLineBefore ?? false,
154
+ newLineAfter: opts.addNewLineAfter ?? false
155
+ },
156
+ M_END: {
157
+ symbol: "",
158
+ prefix: "",
159
+ suffix: "",
160
+ newLineBefore: opts.addNewLineBefore ?? false,
161
+ newLineAfter: opts.addNewLineAfter ?? false
162
+ },
163
+ M_NEWLINE: {
164
+ symbol: "",
165
+ prefix: borderWithSpace,
166
+ newLineBefore: opts.addNewLineBefore ?? false,
167
+ newLineAfter: opts.addNewLineAfter ?? false
168
+ }
169
+ };
170
+ const config = MSG_CONFIGS[opts.type];
171
+ if (!config) {
172
+ throw new Error(`Invalid message type: ${opts.type}`);
173
+ }
174
+ const {
175
+ symbol = "",
176
+ suffix = "",
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 ?? "mindGradient"](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
+ }
257
+ let text = "";
258
+ if (opts.type === "M_BAR") {
259
+ text = bar({ borderColor: opts.borderColor });
260
+ } else {
261
+ text = [formattedTitle, formattedContent].filter(Boolean).join(`
262
+ `);
263
+ }
264
+ const fullText = [
265
+ newLineBefore ? `
266
+ ${borderWithSpace}` : "",
267
+ text,
268
+ newLineAfter ? `
269
+ ${borderWithSpace}` : "",
270
+ suffix
271
+ ].filter(Boolean).join("");
272
+ const lines = fullText.split("\n").map((line, index) => {
273
+ if (opts.type === "M_START") {
274
+ if (index === 0) {
275
+ return `${prefixStartLine} ${line} ${suffixStartLine}`;
276
+ }
277
+ if (index === 1) {
278
+ return borderWithSpace;
279
+ }
280
+ }
281
+ if (opts.type === "M_END" && opts.border && index === 0) {
282
+ return !opts.title ? line : `${pc.green(symbols.info)} ${line}`;
283
+ }
284
+ if (!line.trim() || line.includes(symbols.middle)) {
285
+ return line;
286
+ }
287
+ if (index === 0 && symbol) {
288
+ return `${symbol} ${line}`;
289
+ }
290
+ return `${borderWithSpace}${line}`;
291
+ });
292
+ if (opts.type === "M_END" && opts.border) {
293
+ lines.push(`${prefixEndLine}${suffixEndLine}
294
+ `);
295
+ }
296
+ const finalText = lines.join("\n");
297
+ const lineCount = countLines(finalText);
298
+ return { text: finalText, lineCount };
299
+ }
300
+ const printedLineStack = [];
301
+ export function msg(opts) {
302
+ const { text, lineCount } = fmt(opts);
303
+ process.stdout.write(text + `
304
+ `);
305
+ printedLineStack.push(lineCount + 1);
306
+ }
307
+ export function msgUndo(count = 1) {
308
+ for (let i = 0; i < count; i++) {
309
+ const linesToDelete = printedLineStack.pop();
310
+ if (typeof linesToDelete === "number" && linesToDelete > 0) {
311
+ deleteLastLines(linesToDelete);
312
+ }
313
+ }
314
+ }
315
+ export function msgUndoAll() {
316
+ while (printedLineStack.length > 0) {
317
+ const linesToDelete = printedLineStack.pop();
318
+ if (typeof linesToDelete === "number" && linesToDelete > 0) {
319
+ deleteLastLines(linesToDelete);
320
+ }
321
+ }
322
+ }
323
+ export function printLineBar(text, indent = 2) {
324
+ if (text === "") {
325
+ console.log(pc.dim("\u2502"));
326
+ } else {
327
+ console.log(`${pc.dim("\u2502")}${" ".repeat(indent)}${text}`);
328
+ }
329
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./types.js";
2
+ export * from "./terminal.js";
3
+ export * from "./platforms.js";
4
+ export * from "./mapping.js";
5
+ export * from "./variants.js";
6
+ export * from "./messages.js";
@@ -0,0 +1,6 @@
1
+ export * from "./types.js";
2
+ export * from "./terminal.js";
3
+ export * from "./platforms.js";
4
+ export * from "./mapping.js";
5
+ export * from "./variants.js";
6
+ export * from "./messages.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Determines if Unicode is supported in the current terminal.
3
+ * @returns {boolean} True if Unicode is supported, false otherwise.
4
+ */
5
+ export declare function isUnicodeSupported(): boolean;
6
+ /**
7
+ * Determines the current terminal name based on environment variables.
8
+ * @returns {string} The name of the current terminal or "Unknown" if it cannot be determined.
9
+ */
10
+ export declare function getCurrentTerminalName(): string;
@@ -0,0 +1,67 @@
1
+ import { env, isWindows, isLinux, isMacOS } from "std-env";
2
+ export function isUnicodeSupported() {
3
+ if (isLinux) {
4
+ return env["TERM"] !== "linux";
5
+ }
6
+ return env["WT_SESSION"] !== void 0 || env["TERMINUS_SUBLIME"] !== void 0 || env["ConEmuTask"] === "{cmd::Cmder}" || env["TERM_PROGRAM"] === "Terminus-Sublime" || env["TERM_PROGRAM"] === "vscode" || env["TERM"] === "xterm-256color" || env["TERM"] === "alacritty" || env["TERMINAL_EMULATOR"] === "JetBrains-JediTerm";
7
+ }
8
+ export function getCurrentTerminalName() {
9
+ const termProgram = env["TERM_PROGRAM"];
10
+ const term = env["TERM"];
11
+ const terminalEmulator = env["TERMINAL_EMULATOR"];
12
+ if (termProgram) {
13
+ switch (termProgram.toLowerCase()) {
14
+ case "vscode":
15
+ return "VSCode Terminal";
16
+ case "terminus-sublime":
17
+ return "Terminus Sublime";
18
+ case "hyper":
19
+ return "Hyper";
20
+ case "iterm.app":
21
+ case "iterm":
22
+ return "iTerm2";
23
+ case "alacritty":
24
+ return "Alacritty";
25
+ case "wezterm":
26
+ return "WezTerm";
27
+ case "terminus":
28
+ return "Terminus";
29
+ default:
30
+ return `TERM_PROGRAM: ${termProgram}`;
31
+ }
32
+ }
33
+ if (terminalEmulator) {
34
+ switch (terminalEmulator.toLowerCase()) {
35
+ case "jetbrains-jediterm":
36
+ return "JetBrains JediTerm";
37
+ case "cmder":
38
+ return "Cmder";
39
+ case "conemu":
40
+ return "ConEmu";
41
+ default:
42
+ return `TERMINAL_EMULATOR: ${terminalEmulator}`;
43
+ }
44
+ }
45
+ if (term) {
46
+ switch (term.toLowerCase()) {
47
+ case "xterm-256color":
48
+ return "Xterm 256 Color";
49
+ case "alacritty":
50
+ return "Alacritty";
51
+ case "xterm":
52
+ return "Xterm";
53
+ case "linux":
54
+ return "Linux Console Kernel";
55
+ default:
56
+ return `TERM: ${term}`;
57
+ }
58
+ }
59
+ if (isWindows) {
60
+ return "Windows Terminal";
61
+ } else if (isMacOS) {
62
+ return "macOS Terminal";
63
+ } else if (isLinux) {
64
+ return "Linux Terminal";
65
+ }
66
+ return "Unknown Terminal";
67
+ }
@@ -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;