@reliverse/rempts 1.7.65 → 2.2.7

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 (131) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1534 -1431
  3. package/cleanup.mjs +33 -0
  4. package/dist/cancel.d.ts +31 -0
  5. package/dist/cancel.js +28 -0
  6. package/dist/ffi.d.ts +1 -0
  7. package/dist/ffi.js +165 -0
  8. package/dist/group.d.ts +16 -0
  9. package/dist/group.js +22 -0
  10. package/dist/launcher/command.d.ts +8 -0
  11. package/dist/launcher/command.js +10 -0
  12. package/dist/launcher/discovery.d.ts +3 -0
  13. package/dist/launcher/discovery.js +207 -0
  14. package/dist/launcher/errors.d.ts +15 -0
  15. package/dist/launcher/errors.js +31 -0
  16. package/dist/launcher/help.d.ts +3 -0
  17. package/dist/launcher/help.js +145 -0
  18. package/dist/launcher/mod.d.ts +12 -0
  19. package/dist/launcher/mod.js +222 -0
  20. package/dist/launcher/parser.d.ts +14 -0
  21. package/dist/launcher/parser.js +255 -0
  22. package/dist/launcher/registry.d.ts +10 -0
  23. package/dist/launcher/registry.js +42 -0
  24. package/dist/launcher/types.d.ts +78 -0
  25. package/dist/launcher/validator.d.ts +3 -0
  26. package/dist/launcher/validator.js +39 -0
  27. package/dist/mod.d.ts +6 -0
  28. package/dist/mod.js +6 -0
  29. package/dist/prompt.d.ts +13 -0
  30. package/dist/prompt.js +53 -0
  31. package/dist/selection.d.ts +92 -0
  32. package/dist/selection.js +191 -0
  33. package/dist/spinner.d.ts +26 -0
  34. package/dist/spinner.js +141 -0
  35. package/dist/utils.d.ts +3 -0
  36. package/dist/utils.js +11 -0
  37. package/package.json +41 -47
  38. package/bin/libs/animate/animate-mod.ts.txt +0 -78
  39. package/bin/libs/anykey/anykey-mod.d.ts +0 -12
  40. package/bin/libs/anykey/anykey-mod.js +0 -125
  41. package/bin/libs/cancel/cancel.d.ts +0 -45
  42. package/bin/libs/cancel/cancel.js +0 -72
  43. package/bin/libs/confirm/confirm-alias.d.ts +0 -2
  44. package/bin/libs/confirm/confirm-alias.js +0 -2
  45. package/bin/libs/confirm/confirm-mod.d.ts +0 -5
  46. package/bin/libs/confirm/confirm-mod.js +0 -179
  47. package/bin/libs/date/date.d.ts +0 -2
  48. package/bin/libs/date/date.js +0 -254
  49. package/bin/libs/editor/editor-mod.d.ts +0 -25
  50. package/bin/libs/editor/editor-mod.js +0 -1133
  51. package/bin/libs/figures/figures-mod.d.ts +0 -461
  52. package/bin/libs/figures/figures-mod.js +0 -285
  53. package/bin/libs/group/group-mod.d.ts +0 -33
  54. package/bin/libs/group/group-mod.js +0 -89
  55. package/bin/libs/input/input-alias.d.ts +0 -5
  56. package/bin/libs/input/input-alias.js +0 -4
  57. package/bin/libs/input/input-mod.d.ts +0 -16
  58. package/bin/libs/input/input-mod.js +0 -370
  59. package/bin/libs/intro/intro-alias.d.ts +0 -3
  60. package/bin/libs/intro/intro-alias.js +0 -3
  61. package/bin/libs/intro/intro-mod.d.ts +0 -19
  62. package/bin/libs/intro/intro-mod.js +0 -71
  63. package/bin/libs/launcher/command-runner.d.ts +0 -31
  64. package/bin/libs/launcher/command-runner.js +0 -229
  65. package/bin/libs/launcher/launcher-alias.d.ts +0 -2
  66. package/bin/libs/launcher/launcher-alias.js +0 -2
  67. package/bin/libs/launcher/launcher-mod.d.ts +0 -66
  68. package/bin/libs/launcher/launcher-mod.js +0 -1037
  69. package/bin/libs/launcher/launcher-types.d.ts +0 -176
  70. package/bin/libs/launcher/launcher-types.js +0 -0
  71. package/bin/libs/log/log-alias.d.ts +0 -1
  72. package/bin/libs/log/log-alias.js +0 -2
  73. package/bin/libs/msg-fmt/colors.d.ts +0 -30
  74. package/bin/libs/msg-fmt/colors.js +0 -42
  75. package/bin/libs/msg-fmt/mapping.d.ts +0 -3
  76. package/bin/libs/msg-fmt/mapping.js +0 -41
  77. package/bin/libs/msg-fmt/messages.d.ts +0 -35
  78. package/bin/libs/msg-fmt/messages.js +0 -305
  79. package/bin/libs/msg-fmt/terminal.d.ts +0 -15
  80. package/bin/libs/msg-fmt/terminal.js +0 -60
  81. package/bin/libs/msg-fmt/variants.d.ts +0 -11
  82. package/bin/libs/msg-fmt/variants.js +0 -52
  83. package/bin/libs/multiselect/multiselect-alias.d.ts +0 -2
  84. package/bin/libs/multiselect/multiselect-alias.js +0 -2
  85. package/bin/libs/multiselect/multiselect-prompt.d.ts +0 -2
  86. package/bin/libs/multiselect/multiselect-prompt.js +0 -340
  87. package/bin/libs/next-steps/next-steps.d.ts +0 -13
  88. package/bin/libs/next-steps/next-steps.js +0 -24
  89. package/bin/libs/number/number-mod.d.ts +0 -28
  90. package/bin/libs/number/number-mod.js +0 -234
  91. package/bin/libs/outro/outro-alias.d.ts +0 -3
  92. package/bin/libs/outro/outro-alias.js +0 -3
  93. package/bin/libs/outro/outro-mod.d.ts +0 -7
  94. package/bin/libs/outro/outro-mod.js +0 -49
  95. package/bin/libs/reliarg/reliarg-mod.d.ts +0 -76
  96. package/bin/libs/reliarg/reliarg-mod.js +0 -276
  97. package/bin/libs/results/results.d.ts +0 -7
  98. package/bin/libs/results/results.js +0 -27
  99. package/bin/libs/select/nummultiselect-prompt.d.ts +0 -6
  100. package/bin/libs/select/nummultiselect-prompt.js +0 -141
  101. package/bin/libs/select/numselect-prompt.d.ts +0 -7
  102. package/bin/libs/select/numselect-prompt.js +0 -111
  103. package/bin/libs/select/select-alias.d.ts +0 -9
  104. package/bin/libs/select/select-alias.js +0 -9
  105. package/bin/libs/select/select-prompt.d.ts +0 -5
  106. package/bin/libs/select/select-prompt.js +0 -311
  107. package/bin/libs/select/toggle-prompt.d.ts +0 -5
  108. package/bin/libs/select/toggle-prompt.js +0 -207
  109. package/bin/libs/spinner/spinner-impl.d.ts +0 -70
  110. package/bin/libs/spinner/spinner-impl.js +0 -336
  111. package/bin/libs/spinner/spinner-mod.d.ts +0 -167
  112. package/bin/libs/spinner/spinner-mod.js +0 -447
  113. package/bin/libs/utils/colorize.d.ts +0 -2
  114. package/bin/libs/utils/colorize.js +0 -122
  115. package/bin/libs/utils/errors.d.ts +0 -1
  116. package/bin/libs/utils/errors.js +0 -17
  117. package/bin/libs/utils/prevent.d.ts +0 -8
  118. package/bin/libs/utils/prevent.js +0 -62
  119. package/bin/libs/utils/prompt-end.d.ts +0 -8
  120. package/bin/libs/utils/prompt-end.js +0 -36
  121. package/bin/libs/utils/stream-text.d.ts +0 -18
  122. package/bin/libs/utils/stream-text.js +0 -138
  123. package/bin/libs/utils/system.d.ts +0 -6
  124. package/bin/libs/utils/system.js +0 -7
  125. package/bin/libs/utils/validate.d.ts +0 -21
  126. package/bin/libs/utils/validate.js +0 -17
  127. package/bin/libs/visual/visual-mod.ts.txt +0 -19
  128. package/bin/mod.d.ts +0 -50
  129. package/bin/mod.js +0 -127
  130. package/bin/types.d.ts +0 -372
  131. /package/{bin → dist/launcher}/types.js +0 -0
@@ -1,176 +0,0 @@
1
- export type EmptyArgs = Record<string, never>;
2
- export interface BaseArgProps {
3
- description?: string;
4
- required?: boolean;
5
- allowed?: readonly string[];
6
- }
7
- export interface BaseArgDefinition {
8
- type: string;
9
- description?: string;
10
- required?: boolean;
11
- default?: any;
12
- allowed?: readonly any[];
13
- dependencies?: string[];
14
- }
15
- export type PositionalArgDefinition = BaseArgDefinition & {
16
- type: "positional";
17
- default?: string;
18
- allowed?: readonly string[];
19
- };
20
- export type BooleanArgDefinition = BaseArgDefinition & {
21
- type: "boolean";
22
- default?: boolean;
23
- allowed?: readonly boolean[];
24
- alias?: string;
25
- };
26
- export type StringArgDefinition = BaseArgDefinition & {
27
- type: "string";
28
- default?: string;
29
- allowed?: readonly string[];
30
- alias?: string;
31
- };
32
- export type NumberArgDefinition = BaseArgDefinition & {
33
- type: "number";
34
- default?: number;
35
- allowed?: readonly number[];
36
- alias?: string;
37
- };
38
- export type ArrayArgDefinition = BaseArgDefinition & {
39
- type: "array";
40
- default?: string | readonly string[];
41
- allowed?: readonly string[];
42
- alias?: string;
43
- };
44
- export type ArgDefinition = PositionalArgDefinition | BooleanArgDefinition | StringArgDefinition | NumberArgDefinition | ArrayArgDefinition;
45
- export type ArgDefinitions = Record<string, ArgDefinition>;
46
- export interface CommandMeta {
47
- name: string;
48
- version?: string;
49
- description?: string;
50
- hidden?: boolean;
51
- aliases?: string[];
52
- }
53
- /**
54
- * A subcommand can be either:
55
- * 1) A string path to a module with a default export of type Command.
56
- * 2) A lazy import function returning a Promise that resolves to
57
- * { default: Command<any> } or directly to a Command instance.
58
- */
59
- export type CommandSpec = string | (() => Promise<{
60
- default: Command<any>;
61
- } | Command<any>>);
62
- export type CommandsMap = Record<string, CommandSpec>;
63
- export interface CommandContext<ARGS> {
64
- args: ARGS;
65
- raw: string[];
66
- }
67
- export type CommandRun<ARGS> = (ctx: CommandContext<ARGS>) => void | Promise<void>;
68
- export type CommandHook<ARGS> = (ctx: CommandContext<ARGS>) => void | Promise<void>;
69
- export interface DefineCommandOptions<A extends ArgDefinitions = EmptyArgs> {
70
- meta?: CommandMeta;
71
- args?: A;
72
- run?: CommandRun<InferArgTypes<A>>;
73
- /**
74
- * Object subcommands for this command.
75
- */
76
- commands?: CommandsMap;
77
- /**
78
- * @deprecated Use `commands` instead. Will be removed in a future major version.
79
- */
80
- subCommands?: CommandsMap;
81
- /**
82
- * Called before the command runs. Receives `{ args, raw }` (parsed args and raw argv).
83
- */
84
- onCmdInit?: CommandHook<InferArgTypes<A>>;
85
- /**
86
- * Called after the command finishes. Receives `{ args, raw }` (parsed args and raw argv).
87
- */
88
- onCmdExit?: CommandHook<InferArgTypes<A>>;
89
- /**
90
- * @deprecated Use onCmdInit instead
91
- */
92
- setup?: CommandHook<InferArgTypes<A>>;
93
- /**
94
- * @deprecated Use onCmdExit instead
95
- */
96
- cleanup?: CommandHook<InferArgTypes<A>>;
97
- /**
98
- * Called once per CLI process, before any command/run() is executed
99
- */
100
- onLauncherInit?: () => void | Promise<void>;
101
- /**
102
- * Called once per CLI process, after all command/run() logic is finished
103
- */
104
- onLauncherExit?: () => void | Promise<void>;
105
- }
106
- export interface Command<A extends ArgDefinitions = EmptyArgs> {
107
- meta?: CommandMeta;
108
- args: A;
109
- run?: CommandRun<InferArgTypes<A>>;
110
- /**
111
- * Object subcommands for this command.
112
- */
113
- commands?: CommandsMap;
114
- /**
115
- * @deprecated Use `commands` instead. Will be removed in a future major version.
116
- */
117
- subCommands?: CommandsMap;
118
- /**
119
- * Called before the command runs. Receives `{ args, raw }` (parsed args and raw argv).
120
- */
121
- onCmdInit?: CommandHook<InferArgTypes<A>>;
122
- /**
123
- * Called after the command finishes. Receives `{ args, raw }` (parsed args and raw argv).
124
- */
125
- onCmdExit?: CommandHook<InferArgTypes<A>>;
126
- /**
127
- * @deprecated Use onCmdInit instead
128
- */
129
- setup?: CommandHook<InferArgTypes<A>>;
130
- /**
131
- * @deprecated Use onCmdExit instead
132
- */
133
- cleanup?: CommandHook<InferArgTypes<A>>;
134
- /**
135
- * Called once per CLI process, before any command/run() is executed
136
- */
137
- onLauncherInit?: () => void | Promise<void>;
138
- /**
139
- * Called once per CLI process, after all command/run() logic is finished
140
- */
141
- onLauncherExit?: () => void | Promise<void>;
142
- }
143
- type ExtractAllowed<T extends ArgDefinition> = T extends {
144
- type: "positional";
145
- allowed: readonly (infer U)[];
146
- } ? U : T extends {
147
- type: "positional";
148
- } ? string : T extends {
149
- type: "boolean";
150
- allowed: readonly (infer U)[];
151
- } ? U : T extends {
152
- type: "boolean";
153
- } ? boolean : T extends {
154
- type: "string";
155
- allowed: readonly (infer U)[];
156
- } ? U : T extends {
157
- type: "string";
158
- } ? string : T extends {
159
- type: "number";
160
- allowed: readonly (infer U)[];
161
- } ? U : T extends {
162
- type: "number";
163
- } ? number : T extends {
164
- type: "array";
165
- allowed: readonly (infer U)[];
166
- } ? U[] : T extends {
167
- type: "array";
168
- } ? string[] : never;
169
- export type InferArgTypes<A extends ArgDefinitions> = {
170
- [K in keyof A]: ExtractAllowed<A[K]>;
171
- };
172
- export interface FileBasedOptions {
173
- enable: boolean;
174
- cmdsRootPath: string;
175
- }
176
- export {};
File without changes
@@ -1 +0,0 @@
1
- export declare const log: import("@reliverse/relinka").RelinkaFunction;
@@ -1,2 +0,0 @@
1
- import { relinka } from "@reliverse/relinka";
2
- export const log = relinka;
@@ -1,30 +0,0 @@
1
- import type { ColorName, OutputColor, StandardColor } from "../../types";
2
- /**
3
- * Maps complex colors (gradients, bright, background) to standard terminal colors.
4
- * Used by ora spinners and other terminal utilities that only support basic colors.
5
- *
6
- * Handles:
7
- * - Gradient colors -> solid colors (e.g., retroGradient -> cyan)
8
- * - Bright colors -> base colors (e.g., redBright -> red)
9
- * - Background colors -> foreground colors (e.g., bgRed -> red)
10
- * - Special colors -> undefined (reset, inverse, dim, none)
11
- *
12
- * @param color The complex color to convert
13
- * @returns A standard terminal color or undefined for special colors
14
- */
15
- export declare function toBaseColor(color?: ColorName): StandardColor | undefined;
16
- /**
17
- * Maps any color type to a standard solid color for consistent display.
18
- * Similar to toBaseColor but always returns a color (never undefined).
19
- *
20
- * Handles:
21
- * - Gradient colors -> solid colors (e.g., retroGradient -> cyan)
22
- * - Bright colors -> base colors (e.g., redBright -> red)
23
- * - Background colors -> foreground colors (e.g., bgRed -> red)
24
- * - Special colors (reset, inverse, none) -> dim
25
- * - Undefined -> dim
26
- *
27
- * @param color The color to convert
28
- * @returns A standard terminal color, defaulting to "dim" for special cases
29
- */
30
- export declare function toSolidColor(color?: ColorName): OutputColor;
@@ -1,42 +0,0 @@
1
- const GRADIENT_COLOR_MAP = {
2
- retroGradient: "cyan",
3
- viceGradient: "green",
4
- gradientGradient: "blue",
5
- rainbowGradient: "blue",
6
- cristalGradient: "blue",
7
- mindGradient: "blue",
8
- passionGradient: "blue"
9
- };
10
- const SPECIAL_COLORS = ["reset", "inverse", "none"];
11
- function stripBrightModifier(color) {
12
- return color.replace("Bright", "");
13
- }
14
- function stripBgModifier(color) {
15
- return color.replace("bg", "").toLowerCase();
16
- }
17
- function stripColorModifiers(color) {
18
- if (color.includes("Bright")) {
19
- return stripBrightModifier(color);
20
- }
21
- if (color.startsWith("bg")) {
22
- return stripBgModifier(color);
23
- }
24
- return color;
25
- }
26
- export function toBaseColor(color) {
27
- if (!color || color === "dim" || SPECIAL_COLORS.includes(color)) {
28
- return;
29
- }
30
- if (color in GRADIENT_COLOR_MAP) {
31
- return GRADIENT_COLOR_MAP[color];
32
- }
33
- if (color.includes("Bright") || color.startsWith("bg")) {
34
- const baseColor = stripColorModifiers(color);
35
- return baseColor;
36
- }
37
- return color;
38
- }
39
- export function toSolidColor(color) {
40
- const baseColor = toBaseColor(color);
41
- return baseColor ?? "dim";
42
- }
@@ -1,3 +0,0 @@
1
- import type { ColorName, TypographyName } from "../../types";
2
- export declare const colorMap: Record<ColorName, (text: string) => string>;
3
- export declare const typographyMap: Record<TypographyName, (text: string) => string>;
@@ -1,41 +0,0 @@
1
- import { re } from "@reliverse/relico";
2
- import gradient, { cristal, mind, passion, rainbow, retro, vice } from "gradient-string";
3
- export const colorMap = {
4
- // @reliverse/relico
5
- none: (text) => text,
6
- reset: re.reset,
7
- bgCyan: re.bgCyan,
8
- bgCyanBright: re.bgCyanBright,
9
- black: re.black,
10
- blue: re.blue,
11
- blueBright: re.blueBright,
12
- cyan: re.cyan,
13
- cyanBright: re.cyanBright,
14
- dim: re.dim,
15
- gray: re.gray,
16
- green: re.green,
17
- greenBright: re.greenBright,
18
- inverse: (text) => re.bold(re.inverse(text)),
19
- magenta: re.magenta,
20
- magentaBright: re.magentaBright,
21
- red: re.red,
22
- redBright: re.redBright,
23
- white: re.white,
24
- yellow: re.yellow,
25
- yellowBright: re.yellowBright,
26
- // gradient-string
27
- cristalGradient: cristal,
28
- gradientGradient: gradient(["red", "yellow", "green", "cyan", "blue", "magenta"]),
29
- mindGradient: mind,
30
- passionGradient: passion,
31
- rainbowGradient: rainbow,
32
- retroGradient: retro,
33
- viceGradient: vice
34
- };
35
- export const typographyMap = {
36
- none: (text) => text,
37
- bold: re.bold,
38
- italic: re.italic,
39
- strikethrough: re.strikethrough,
40
- underline: re.underline
41
- };
@@ -1,35 +0,0 @@
1
- import type { ColorName, FmtMsgOptions, Symbols } from "../../types";
2
- export declare const symbols: Symbols;
3
- /**
4
- * Returns a colored vertical bar symbol. Prevents gradient colors for bars.
5
- */
6
- export declare const bar: ({ borderColor }?: {
7
- borderColor?: ColorName;
8
- }) => string;
9
- /**
10
- * Main formatter function: builds the final text output based on FmtMsgOptions.
11
- */
12
- export declare function fmt(opts: FmtMsgOptions): {
13
- text: string;
14
- lineCount: number;
15
- };
16
- /**
17
- * Logs a formatted message to the console and records how many lines it occupies.
18
- */
19
- export declare function msg(opts: FmtMsgOptions): void;
20
- /**
21
- * Undo the last printed message by deleting its lines from the terminal.
22
- * @param count How many messages to undo. Defaults to 1.
23
- */
24
- export declare function msgUndo(count?: number): void;
25
- /**
26
- * Undo all printed messages so far.
27
- */
28
- export declare function msgUndoAll(): void;
29
- /**
30
- * Prints: "│ <text>" (two spaces after the bar).
31
- * If text is empty, it just prints "│".
32
- * If indent is 1, it prints "│ <text>" (one space).
33
- * If indent is 2, it prints "│ <text>" (two spaces), etc.
34
- */
35
- export declare function printLineBar(text: string, indent?: number): void;
@@ -1,305 +0,0 @@
1
- import { re } from "@reliverse/relico";
2
- import { relinka } from "@reliverse/relinka";
3
- import { isUnicodeSupported } from "@reliverse/reltime";
4
- import wrapAnsi from "wrap-ansi";
5
- import { colorMap, typographyMap } from "./mapping.js";
6
- import { deleteLastLines, getExactTerminalWidth, getTerminalWidth } from "./terminal.js";
7
- import { isValidVariant, variantMap } from "./variants.js";
8
- const unicode = isUnicodeSupported();
9
- const u = (c, fallback) => unicode ? c : fallback;
10
- export const symbols = {
11
- pointer: u("\u{1F449}", ">"),
12
- start: u("\u256D", "*"),
13
- middle: u("\u2502", "|"),
14
- end: u("\u2570", "*"),
15
- line: u("\u2500", "\u2014"),
16
- corner_top_right: u("\u256D", "*"),
17
- step_active: u("\u25C6", "\u2666"),
18
- step_error: u("\u{1F5F4}", "x"),
19
- info: u("\u2139", "i"),
20
- log: u("\u2502", "|"),
21
- success: u("\u2705", "\u2713"),
22
- warn: u("\u26A0", "!"),
23
- error: u("\u274C", "x")
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((line) => applyStyles(line, colorName, typographyName, variantName, borderColor)).join("\n");
30
- }
31
- function applyStyles(text, colorName, typographyName, variantName, borderColor) {
32
- let styledText = text;
33
- if (variantName && isValidVariant(variantName)) {
34
- styledText = variantMap[variantName]([styledText], void 0, borderColor).toString();
35
- return styledText;
36
- }
37
- if (colorName && colorMap[colorName]) {
38
- styledText = colorMap[colorName](styledText);
39
- }
40
- if (typographyName && typographyMap[typographyName]) {
41
- styledText = typographyMap[typographyName](styledText);
42
- }
43
- return styledText;
44
- }
45
- export const bar = ({ borderColor = "dim" } = {}) => {
46
- if (borderColor.endsWith("Gradient")) {
47
- relinka(
48
- "error",
49
- "Gradient colors are not supported for bars. Please use a solid color instead."
50
- );
51
- return colorMap.dim(symbols.middle);
52
- }
53
- return colorMap[borderColor](symbols.middle);
54
- };
55
- function countLines(text) {
56
- return text.split("\n").length;
57
- }
58
- function getColoredSymbol(customSymbol, symbolName, symbolColor) {
59
- if (customSymbol) {
60
- return symbolColor && colorMap[symbolColor] ? colorMap[symbolColor](customSymbol) : customSymbol;
61
- }
62
- if (symbolName && symbols[symbolName]) {
63
- return symbolColor && colorMap[symbolColor] ? colorMap[symbolColor](symbols[symbolName]) : symbols[symbolName];
64
- }
65
- return;
66
- }
67
- function formatTitle(opts, borderTwoSpaces, borderError) {
68
- let formattedTitle = "";
69
- if (!opts.title) return formattedTitle;
70
- const wrappedOrStyledTitle = wrapThenStyle(
71
- opts.title,
72
- opts.wrapTitle ?? true,
73
- opts.titleTypography ?? "bold",
74
- opts.titleColor ?? "cyan",
75
- opts.titleVariant,
76
- opts.borderColor
77
- );
78
- formattedTitle += wrappedOrStyledTitle;
79
- if (opts.hint) {
80
- const hintColor = opts.hintPlaceholderColor ?? "blue";
81
- const wrappedHint = wrapThenStyle(
82
- opts.hint,
83
- opts.wrapTitle ?? true,
84
- // same wrap logic as title by default
85
- opts.hintTypography ?? "italic",
86
- hintColor,
87
- void 0,
88
- opts.borderColor
89
- );
90
- formattedTitle += `
91
- ${borderTwoSpaces}${wrappedHint}`;
92
- }
93
- if (opts.placeholder && opts.type === "M_GENERAL") {
94
- const placeHolderColor = opts.hintPlaceholderColor ?? "blue";
95
- formattedTitle += `
96
- ${borderTwoSpaces}${colorMap[placeHolderColor](opts.placeholder)}`;
97
- }
98
- if (opts.errorMessage) {
99
- const formattedError = applyStyles(
100
- opts.errorMessage,
101
- "red",
102
- "bold",
103
- void 0,
104
- opts.borderColor
105
- );
106
- formattedTitle += `
107
- ${borderError} ${formattedError}`;
108
- }
109
- return formattedTitle;
110
- }
111
- function formatContent(opts) {
112
- if (!opts.content) return "";
113
- return wrapThenStyle(
114
- opts.content,
115
- opts.wrapContent ?? true,
116
- opts.contentTypography ?? "italic",
117
- opts.contentColor ?? "dim",
118
- opts.contentVariant,
119
- opts.borderColor
120
- );
121
- }
122
- export function fmt(opts) {
123
- if (!opts.borderColor) {
124
- opts.borderColor = "dim";
125
- }
126
- const borderColored = applyStyles(symbols.middle, opts.borderColor);
127
- const borderError = applyStyles(symbols.middle, "red");
128
- const borderTwoSpaces = `${borderColored} `;
129
- const prefixStartLine = opts.borderColor ? colorMap[opts.borderColor](symbols.start + symbols.line) : symbols.start + symbols.line;
130
- const prefixEndLine = opts.borderColor ? colorMap[opts.borderColor](symbols.end + symbols.line) : symbols.end + symbols.line;
131
- const lineLength = opts.horizontalLineLength === 0 ? getExactTerminalWidth() - 3 : opts.horizontalLineLength ?? getExactTerminalWidth() - 3;
132
- const suffixStartLine = opts.borderColor ? colorMap[opts.borderColor](`${symbols.line.repeat(lineLength)}\u22B1`) : `${symbols.line.repeat(lineLength)}\u22B1`;
133
- const suffixEndLine = opts.borderColor ? colorMap[opts.borderColor](`${symbols.line.repeat(lineLength)}\u22B1`) : `${symbols.line.repeat(lineLength)}\u22B1`;
134
- const computedSymbol = getColoredSymbol(opts.customSymbol, opts.symbol, opts.symbolColor) ?? re.green(symbols.step_active);
135
- const MESSAGE_CONFIG_MAP = {
136
- M_NULL: {
137
- symbol: "",
138
- prefix: borderTwoSpaces,
139
- suffix: "",
140
- newLineBefore: opts.addNewLineBefore ?? false,
141
- newLineAfter: opts.addNewLineAfter ?? false
142
- },
143
- M_BAR: {
144
- symbol: "",
145
- prefix: "",
146
- suffix: "",
147
- newLineBefore: false,
148
- newLineAfter: false
149
- },
150
- M_INFO_NULL: {
151
- symbol: "",
152
- prefix: borderTwoSpaces,
153
- suffix: "",
154
- newLineBefore: opts.addNewLineBefore ?? false,
155
- newLineAfter: opts.addNewLineAfter ?? false
156
- },
157
- M_START: {
158
- symbol: "",
159
- prefix: "",
160
- suffix: `
161
- ${borderTwoSpaces}`,
162
- newLineBefore: opts.addNewLineBefore ?? false,
163
- newLineAfter: opts.addNewLineAfter ?? false
164
- },
165
- M_MIDDLE: {
166
- symbol: "",
167
- prefix: borderTwoSpaces,
168
- suffix: "",
169
- newLineBefore: opts.addNewLineBefore ?? false,
170
- newLineAfter: opts.addNewLineAfter ?? false
171
- },
172
- M_GENERAL: {
173
- symbol: computedSymbol,
174
- prefix: borderTwoSpaces,
175
- suffix: "",
176
- newLineBefore: opts.addNewLineBefore ?? false,
177
- newLineAfter: opts.addNewLineAfter ?? false
178
- },
179
- M_GENERAL_NULL: {
180
- symbol: "",
181
- prefix: borderTwoSpaces,
182
- suffix: opts.placeholder ? colorMap[opts.hintPlaceholderColor ?? "blue"](opts.placeholder) : "",
183
- newLineBefore: opts.addNewLineBefore ?? false,
184
- newLineAfter: opts.addNewLineAfter ?? false
185
- },
186
- M_INFO: {
187
- symbol: computedSymbol || re.green(symbols.info),
188
- prefix: borderTwoSpaces,
189
- suffix: "",
190
- newLineBefore: opts.addNewLineBefore ?? false,
191
- newLineAfter: opts.addNewLineAfter ?? true
192
- },
193
- M_ERROR: {
194
- symbol: computedSymbol || re.redBright(symbols.step_error),
195
- prefix: borderTwoSpaces,
196
- suffix: "",
197
- newLineBefore: opts.addNewLineBefore ?? false,
198
- newLineAfter: opts.addNewLineAfter ?? false
199
- },
200
- M_ERROR_NULL: {
201
- symbol: "",
202
- prefix: borderTwoSpaces,
203
- suffix: "",
204
- newLineBefore: opts.addNewLineBefore ?? false,
205
- newLineAfter: opts.addNewLineAfter ?? false
206
- },
207
- M_END: {
208
- symbol: "",
209
- prefix: "",
210
- suffix: "",
211
- newLineBefore: opts.addNewLineBefore ?? false,
212
- newLineAfter: opts.addNewLineAfter ?? false
213
- },
214
- M_NEWLINE: {
215
- symbol: "",
216
- prefix: borderTwoSpaces,
217
- suffix: "",
218
- newLineBefore: opts.addNewLineBefore ?? false,
219
- newLineAfter: opts.addNewLineAfter ?? false
220
- }
221
- };
222
- const config = MESSAGE_CONFIG_MAP[opts.type];
223
- if (!config) {
224
- throw new Error(`Invalid message type: ${opts.type}`);
225
- }
226
- const { symbol, suffix, newLineBefore, newLineAfter } = config;
227
- const finalTitle = formatTitle(opts, borderTwoSpaces, borderError);
228
- const finalContent = formatContent(opts);
229
- let text = "";
230
- if (opts.type === "M_BAR") {
231
- text = bar({ borderColor: opts.borderColor });
232
- } else {
233
- text = [finalTitle, finalContent].filter(Boolean).join("\n");
234
- }
235
- const fullText = [
236
- newLineBefore ? `
237
- ${borderTwoSpaces}` : "",
238
- text,
239
- newLineAfter ? `
240
- ${borderTwoSpaces}` : "",
241
- suffix
242
- ].filter(Boolean).join("");
243
- const lines = fullText.split("\n").map((line, index) => {
244
- if (opts.type === "M_START") {
245
- if (index === 0) {
246
- return `${prefixStartLine} ${line} ${suffixStartLine}`;
247
- }
248
- if (index === 1) {
249
- return borderTwoSpaces;
250
- }
251
- }
252
- if (opts.type === "M_END" && opts.border && index === 0) {
253
- if (!opts.title) return "";
254
- return `${bar({ borderColor: opts.borderColor ?? "dim" })} ${line}`;
255
- }
256
- if (!line.trim() || line.includes(symbols.middle)) {
257
- return line;
258
- }
259
- if (index === 0 && symbol) {
260
- return `${symbol} ${line}`;
261
- }
262
- return `${config.prefix}${line}`;
263
- });
264
- if (opts.type === "M_END" && opts.border) {
265
- lines.push(`${prefixEndLine}${suffixEndLine}
266
- `);
267
- }
268
- const finalText = lines.join("\n");
269
- const lineCount = countLines(finalText);
270
- return { text: finalText, lineCount };
271
- }
272
- const printedLineStack = [];
273
- export function msg(opts) {
274
- const { text, lineCount } = fmt(opts);
275
- if (opts.type === "M_BAR" && opts.noNewLine) {
276
- process.stdout.write(text);
277
- } else {
278
- process.stdout.write(`${text}
279
- `);
280
- }
281
- printedLineStack.push(opts.type === "M_BAR" && opts.noNewLine ? lineCount : lineCount + 1);
282
- }
283
- export function msgUndo(count = 1) {
284
- for (let i = 0; i < count; i++) {
285
- const linesToDelete = printedLineStack.pop();
286
- if (typeof linesToDelete === "number" && linesToDelete > 0) {
287
- deleteLastLines(linesToDelete);
288
- }
289
- }
290
- }
291
- export function msgUndoAll() {
292
- while (printedLineStack.length > 0) {
293
- const linesToDelete = printedLineStack.pop();
294
- if (typeof linesToDelete === "number" && linesToDelete > 0) {
295
- deleteLastLines(linesToDelete);
296
- }
297
- }
298
- }
299
- export function printLineBar(text, indent = 2) {
300
- if (text === "") {
301
- relinka("log", re.dim("\u2502"));
302
- } else {
303
- relinka("log", `${re.dim("\u2502")}${" ".repeat(indent)}${text}`);
304
- }
305
- }
@@ -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;