@moku-labs/common 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/browser.d.mts +6 -0
- package/dist/browser.mjs +13 -0
- package/dist/cli.cjs +669 -0
- package/dist/cli.d.cts +517 -0
- package/dist/cli.d.mts +517 -0
- package/dist/cli.mjs +652 -0
- package/dist/index.cjs +13 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +13 -0
- package/package.json +23 -5
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
//#region src/cli/ansi.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @file `@moku-labs/common/cli` — TTY/`NO_COLOR`-aware ANSI color + box-drawing
|
|
4
|
+
* primitives: the shared "brand DNA" every Moku CLI renders through (the brand pink,
|
|
5
|
+
* the palette, the box/spinner/progress glyphs). Color and Unicode glyphs are emitted
|
|
6
|
+
* only on a real TTY with `NO_COLOR` unset; otherwise plain ASCII so CI logs and pipes
|
|
7
|
+
* stay readable. Pure: depends on nothing but `process.stdout`/`process.env` defaults,
|
|
8
|
+
* so a consuming framework can build its own panels on top without pulling in any UI lib.
|
|
9
|
+
*/
|
|
10
|
+
/** ANSI SGR codes used by the brand renderer (each prefixed with the ESC byte). */
|
|
11
|
+
declare const ANSI: {
|
|
12
|
+
readonly reset: `${string}[0m`;
|
|
13
|
+
readonly bold: `${string}[1m`;
|
|
14
|
+
readonly dim: `${string}[2m`;
|
|
15
|
+
readonly red: `${string}[31m`;
|
|
16
|
+
readonly green: `${string}[32m`;
|
|
17
|
+
readonly yellow: `${string}[33m`;
|
|
18
|
+
readonly blue: `${string}[34m`;
|
|
19
|
+
readonly magenta: `${string}[35m`;
|
|
20
|
+
readonly cyan: `${string}[36m`;
|
|
21
|
+
readonly gray: `${string}[90m`;
|
|
22
|
+
};
|
|
23
|
+
/** A single ANSI color code from {@link ANSI}. */
|
|
24
|
+
type AnsiCode = (typeof ANSI)[keyof typeof ANSI];
|
|
25
|
+
/**
|
|
26
|
+
* The Moku brand pink (`#FF1E6F`) as an RGB triple, used for 24-bit truecolor output.
|
|
27
|
+
* Degrades to {@link ANSI.magenta} on a 16-color TTY and to plain text off a TTY.
|
|
28
|
+
*/
|
|
29
|
+
declare const BRAND_PINK: {
|
|
30
|
+
readonly r: 255;
|
|
31
|
+
readonly g: 30;
|
|
32
|
+
readonly b: 111;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Build a 24-bit (truecolor) SGR foreground escape for the given RGB triple.
|
|
36
|
+
*
|
|
37
|
+
* @param r - Red channel (0–255).
|
|
38
|
+
* @param g - Green channel (0–255).
|
|
39
|
+
* @param b - Blue channel (0–255).
|
|
40
|
+
* @returns The `ESC[38;2;r;g;bm` foreground sequence.
|
|
41
|
+
* @example
|
|
42
|
+
* fg24(255, 30, 111); // "\x1b[38;2;255;30;111m"
|
|
43
|
+
*/
|
|
44
|
+
declare function fg24(r: number, g: number, b: number): string;
|
|
45
|
+
/** ANSI: erase the entire current line, leaving the cursor where it is. */
|
|
46
|
+
declare const CLEAR_LINE: string;
|
|
47
|
+
/** ANSI: erase from the cursor to the end of the screen (drops stale trailing rows). */
|
|
48
|
+
declare const CLEAR_BELOW: string;
|
|
49
|
+
/**
|
|
50
|
+
* Braille spinner frames for live "working…" indicators on a TTY (advance one per tick).
|
|
51
|
+
* Off a TTY a renderer never animates, so this is unused in plain/CI output.
|
|
52
|
+
*/
|
|
53
|
+
declare const SPINNER_FRAMES: readonly ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
54
|
+
/**
|
|
55
|
+
* The ANSI sequence to move the cursor up `n` lines (empty string for `n <= 0`). A
|
|
56
|
+
* renderer uses it to repaint a live block in place — move up over the previous draw,
|
|
57
|
+
* then rewrite each row — so progress updates a fixed region instead of scrolling lines.
|
|
58
|
+
*
|
|
59
|
+
* @param n - Number of lines to move the cursor up.
|
|
60
|
+
* @returns The cursor-up escape sequence, or `""` when `n <= 0`.
|
|
61
|
+
* @example
|
|
62
|
+
* cursorUp(3); // "\x1b[3A"
|
|
63
|
+
*/
|
|
64
|
+
declare function cursorUp(n: number): string;
|
|
65
|
+
/**
|
|
66
|
+
* Box-drawing glyphs used to frame panels (Unicode on a TTY, ASCII fallback off it).
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const glyphs = boxGlyphs(true);
|
|
70
|
+
*/
|
|
71
|
+
type BoxGlyphs = {
|
|
72
|
+
/** Top-left corner. */topLeft: string; /** Top-right corner. */
|
|
73
|
+
topRight: string; /** Bottom-left corner. */
|
|
74
|
+
bottomLeft: string; /** Bottom-right corner. */
|
|
75
|
+
bottomRight: string; /** Horizontal edge. */
|
|
76
|
+
horizontal: string; /** Vertical edge. */
|
|
77
|
+
vertical: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* The minimal stream shape {@link supportsColor} probes — just the `isTTY` flag.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const stream: ColorStream = { isTTY: true };
|
|
84
|
+
*/
|
|
85
|
+
type ColorStream = {
|
|
86
|
+
/** Whether the stream is a TTY (color-capable). */isTTY?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Whether ANSI color/box glyphs should be emitted: a TTY stream with `NO_COLOR`
|
|
90
|
+
* unset. Reads `process.stdout.isTTY` and `process.env.NO_COLOR` by default so the
|
|
91
|
+
* renderer auto-degrades in CI and pipes.
|
|
92
|
+
*
|
|
93
|
+
* @param stream - Stream to probe for `isTTY` (defaults to `process.stdout`).
|
|
94
|
+
* @param noColor - The `NO_COLOR` value (defaults to `process.env.NO_COLOR`).
|
|
95
|
+
* @returns `true` when color should be used.
|
|
96
|
+
* @example
|
|
97
|
+
* supportsColor(); // true in an interactive terminal
|
|
98
|
+
*/
|
|
99
|
+
declare function supportsColor(stream?: ColorStream, noColor?: string | undefined): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Whether the terminal advertises 24-bit (truecolor) support via `COLORTERM`, so the
|
|
102
|
+
* renderer may emit the exact brand pink ({@link BRAND_PINK}) instead of the 16-color
|
|
103
|
+
* `magenta` approximation. Always layered on top of {@link supportsColor} — truecolor
|
|
104
|
+
* is never used when color itself is disabled.
|
|
105
|
+
*
|
|
106
|
+
* @param colorTerm - The `COLORTERM` value (defaults to `process.env.COLORTERM`).
|
|
107
|
+
* @returns `true` when `COLORTERM` is `truecolor` or `24bit`.
|
|
108
|
+
* @example
|
|
109
|
+
* supportsTruecolor("truecolor"); // true
|
|
110
|
+
*/
|
|
111
|
+
declare function supportsTruecolor(colorTerm?: string | undefined): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* The braille spinner glyph for a given elapsed time, advancing one frame per
|
|
114
|
+
* `frameMs`. Deriving the frame from wall-clock elapsed (rather than a tick counter)
|
|
115
|
+
* keeps the spinner correct even when the animation ticker is briefly starved by a
|
|
116
|
+
* synchronous build phase and several ticks coalesce — the glyph still reflects real
|
|
117
|
+
* elapsed time instead of freezing on a stale frame.
|
|
118
|
+
*
|
|
119
|
+
* @param elapsedMs - Milliseconds since the live region opened.
|
|
120
|
+
* @param frameMs - Milliseconds per frame (defaults to `80`).
|
|
121
|
+
* @returns The active spinner glyph.
|
|
122
|
+
* @example
|
|
123
|
+
* spinnerFrameAt(240); // "⠹" (the 4th frame at 80ms/frame)
|
|
124
|
+
*/
|
|
125
|
+
declare function spinnerFrameAt(elapsedMs: number, frameMs?: number): string;
|
|
126
|
+
/**
|
|
127
|
+
* Select the box glyph set for the given color mode (Unicode on a TTY, ASCII off it).
|
|
128
|
+
*
|
|
129
|
+
* @param color - Whether color/Unicode output is enabled.
|
|
130
|
+
* @returns The matching {@link BoxGlyphs} set.
|
|
131
|
+
* @example
|
|
132
|
+
* const glyphs = boxGlyphs(supportsColor());
|
|
133
|
+
*/
|
|
134
|
+
declare function boxGlyphs(color: boolean): BoxGlyphs;
|
|
135
|
+
/**
|
|
136
|
+
* The visible width of a string, ignoring any ANSI escape sequences it contains.
|
|
137
|
+
*
|
|
138
|
+
* @param text - The (possibly colorized) text to measure.
|
|
139
|
+
* @returns The number of visible characters.
|
|
140
|
+
* @example
|
|
141
|
+
* visibleWidth(`${ANSI.red}hi${ANSI.reset}`); // 2
|
|
142
|
+
*/
|
|
143
|
+
declare function visibleWidth(text: string): number;
|
|
144
|
+
/**
|
|
145
|
+
* A color palette bound to a fixed color mode. `paint` wraps text in an ANSI code
|
|
146
|
+
* when enabled (no-op in plain mode); the named accessors are thin sugar over it.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* const palette = makePalette(true);
|
|
150
|
+
* palette.green("ok");
|
|
151
|
+
*/
|
|
152
|
+
type Palette = {
|
|
153
|
+
/** Whether this palette emits color. */readonly enabled: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Wrap text in the given ANSI code (returns it unchanged in plain mode).
|
|
156
|
+
*
|
|
157
|
+
* @param code - The ANSI SGR code to apply.
|
|
158
|
+
* @param text - The text to colorize.
|
|
159
|
+
* @returns The colorized (or unchanged) text.
|
|
160
|
+
* @example
|
|
161
|
+
* palette.paint(ANSI.green, "ok");
|
|
162
|
+
*/
|
|
163
|
+
paint(code: AnsiCode, text: string): string;
|
|
164
|
+
/**
|
|
165
|
+
* Bold the given text (no-op in plain mode).
|
|
166
|
+
*
|
|
167
|
+
* @param text - The text to embolden.
|
|
168
|
+
* @returns The bold (or unchanged) text.
|
|
169
|
+
* @example
|
|
170
|
+
* palette.bold("title");
|
|
171
|
+
*/
|
|
172
|
+
bold(text: string): string;
|
|
173
|
+
/**
|
|
174
|
+
* Dim the given text (no-op in plain mode).
|
|
175
|
+
*
|
|
176
|
+
* @param text - The text to dim.
|
|
177
|
+
* @returns The dim (or unchanged) text.
|
|
178
|
+
* @example
|
|
179
|
+
* palette.dim("· 84ms");
|
|
180
|
+
*/
|
|
181
|
+
dim(text: string): string;
|
|
182
|
+
/**
|
|
183
|
+
* Color the given text green (no-op in plain mode).
|
|
184
|
+
*
|
|
185
|
+
* @param text - The text to colorize.
|
|
186
|
+
* @returns The green (or unchanged) text.
|
|
187
|
+
* @example
|
|
188
|
+
* palette.green("✓");
|
|
189
|
+
*/
|
|
190
|
+
green(text: string): string;
|
|
191
|
+
/**
|
|
192
|
+
* Color the given text yellow (no-op in plain mode).
|
|
193
|
+
*
|
|
194
|
+
* @param text - The text to colorize.
|
|
195
|
+
* @returns The yellow (or unchanged) text.
|
|
196
|
+
* @example
|
|
197
|
+
* palette.yellow("~");
|
|
198
|
+
*/
|
|
199
|
+
yellow(text: string): string;
|
|
200
|
+
/**
|
|
201
|
+
* Color the given text red (no-op in plain mode).
|
|
202
|
+
*
|
|
203
|
+
* @param text - The text to colorize.
|
|
204
|
+
* @returns The red (or unchanged) text.
|
|
205
|
+
* @example
|
|
206
|
+
* palette.red("✗");
|
|
207
|
+
*/
|
|
208
|
+
red(text: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Color the given text cyan (no-op in plain mode).
|
|
211
|
+
*
|
|
212
|
+
* @param text - The text to colorize.
|
|
213
|
+
* @returns The cyan (or unchanged) text.
|
|
214
|
+
* @example
|
|
215
|
+
* palette.cyan("http://localhost:4173");
|
|
216
|
+
*/
|
|
217
|
+
cyan(text: string): string;
|
|
218
|
+
/**
|
|
219
|
+
* Color the given text the Moku brand pink — exact `#FF1E6F` (24-bit) when truecolor
|
|
220
|
+
* is enabled, else the 16-color `magenta` approximation, else unchanged (plain mode).
|
|
221
|
+
* The brand accent for the cube mark, the lockup wordmark, the filled progress bar,
|
|
222
|
+
* and hero numbers.
|
|
223
|
+
*
|
|
224
|
+
* @param text - The text to colorize.
|
|
225
|
+
* @returns The pink (or unchanged) text.
|
|
226
|
+
* @example
|
|
227
|
+
* palette.pink("▟▙ moku web");
|
|
228
|
+
*/
|
|
229
|
+
pink(text: string): string;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Build a {@link Palette} bound to a fixed color mode. When `color` is `false` every
|
|
233
|
+
* helper returns its input unchanged, so the same render code path produces plain
|
|
234
|
+
* output in CI/pipes.
|
|
235
|
+
*
|
|
236
|
+
* @param color - Whether color is enabled (typically `supportsColor()`).
|
|
237
|
+
* @param truecolor - Whether 24-bit output is enabled (typically `supportsTruecolor()`);
|
|
238
|
+
* only consulted by {@link Palette.pink}. Defaults to `false` (16-color magenta).
|
|
239
|
+
* @returns The bound color palette.
|
|
240
|
+
* @example
|
|
241
|
+
* const palette = makePalette(supportsColor(), supportsTruecolor());
|
|
242
|
+
* const line = palette.green("done");
|
|
243
|
+
*/
|
|
244
|
+
declare function makePalette(color: boolean, truecolor?: boolean): Palette;
|
|
245
|
+
/**
|
|
246
|
+
* Frame a list of already-rendered content lines in a box, padding each line to the
|
|
247
|
+
* widest visible line (or `minInnerWidth`, whichever is larger — so several boxes can be
|
|
248
|
+
* forced to a shared width). Uses Unicode borders when `color` is enabled and ASCII
|
|
249
|
+
* otherwise. Visible width ignores embedded ANSI so colored lines align.
|
|
250
|
+
*
|
|
251
|
+
* @param lines - The content lines (may contain ANSI color codes).
|
|
252
|
+
* @param color - Whether to use Unicode borders (and assume color-capable output).
|
|
253
|
+
* @param minInnerWidth - Minimum inner (content) width to pad every row to. Defaults to `0`.
|
|
254
|
+
* @returns The boxed lines (top border, content rows, bottom border).
|
|
255
|
+
* @example
|
|
256
|
+
* box(["Local: http://localhost:4173"], true, 62);
|
|
257
|
+
*/
|
|
258
|
+
declare function box(lines: string[], color: boolean, minInnerWidth?: number): string[];
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/cli/console.d.ts
|
|
261
|
+
/**
|
|
262
|
+
* Options for {@link createBrandConsole}. All optional: the defaults wire the console to
|
|
263
|
+
* `console.log`/`console.error` with auto-detected color/truecolor, while tests inject a
|
|
264
|
+
* capturing sink and force `color: false` for deterministic plain output.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* const lines: string[] = [];
|
|
268
|
+
* const ui = createBrandConsole({ write: line => lines.push(line), color: false });
|
|
269
|
+
*/
|
|
270
|
+
type BrandConsoleOptions = {
|
|
271
|
+
/** Sink for normal (stdout) lines. Defaults to `console.log`. */write?: (line: string) => void; /** Sink for warning/error (stderr) lines. Defaults to `console.error`. */
|
|
272
|
+
writeError?: (line: string) => void; /** Force color on/off. Defaults to `supportsColor()` (TTY + `NO_COLOR` unset). */
|
|
273
|
+
color?: boolean; /** Force 24-bit truecolor on/off. Defaults to `supportsTruecolor()` (`COLORTERM`). */
|
|
274
|
+
truecolor?: boolean; /** Total visible width the lockup rule spans / `railLine` aligns to. Defaults to `66`. */
|
|
275
|
+
width?: number;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* The fields of the `▟▙ moku <name>` lockup banner. Every part is optional except the
|
|
279
|
+
* wordmark, so a one-off tool can print just `▟▙ moku tool` while a framework adds a
|
|
280
|
+
* per-command label, a version (right-aligned) and a runtime-facts line beneath the rule.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ui.lockup({ wordmark: "moku worker", label: "deploy", version: "v1.2.0" });
|
|
284
|
+
*/
|
|
285
|
+
type LockupOptions = {
|
|
286
|
+
/** The product wordmark shown in bold brand pink (e.g. `moku web`). */wordmark: string; /** Optional dim per-command/context label shown beside the wordmark (e.g. `serve · dev`). */
|
|
287
|
+
label?: string; /** Optional dim version string right-aligned on the lockup line (e.g. `v1.2.0`). */
|
|
288
|
+
version?: string; /** Optional dim facts line shown beneath the rule (e.g. `node 24.3.0 · darwin arm64`). */
|
|
289
|
+
facts?: string;
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* The branded console surface: the shared brand vocabulary plus the `palette` and the
|
|
293
|
+
* `railLine`/`box` builders a project composes its own panels from.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* const ui = createBrandConsole();
|
|
297
|
+
* ui.lockup({ wordmark: "moku tool" });
|
|
298
|
+
* ui.info("ready");
|
|
299
|
+
*/
|
|
300
|
+
type BrandConsole = {
|
|
301
|
+
/** The bound color palette (the same one the lines are rendered with). */readonly palette: Palette; /** Whether this console emits color/Unicode. */
|
|
302
|
+
readonly color: boolean; /** The lockup/rail width this console aligns to. */
|
|
303
|
+
readonly width: number;
|
|
304
|
+
/**
|
|
305
|
+
* Write a pre-rendered line verbatim through the stdout sink.
|
|
306
|
+
*
|
|
307
|
+
* @param text - The line to write (defaults to an empty line).
|
|
308
|
+
* @returns Nothing.
|
|
309
|
+
* @example
|
|
310
|
+
* ui.line(" custom row");
|
|
311
|
+
*/
|
|
312
|
+
line(text?: string): void;
|
|
313
|
+
/**
|
|
314
|
+
* Render the `▟▙ <wordmark>` lockup: the cube + bold-pink wordmark and an optional dim
|
|
315
|
+
* label on the left with the version right-aligned, a dim hairline rule, and an optional
|
|
316
|
+
* dim facts line beneath it. The cube/rule degrade to ASCII (`*`/`-`) off a TTY.
|
|
317
|
+
*
|
|
318
|
+
* @param options - The lockup fields (see {@link LockupOptions}).
|
|
319
|
+
* @returns Nothing.
|
|
320
|
+
* @example
|
|
321
|
+
* ui.lockup({ wordmark: "moku web", label: "build", version: "v1.2.0" });
|
|
322
|
+
*/
|
|
323
|
+
lockup(options: LockupOptions): void;
|
|
324
|
+
/**
|
|
325
|
+
* Render a section heading: a blank line followed by a bold brand-pink label.
|
|
326
|
+
*
|
|
327
|
+
* @param text - The heading label.
|
|
328
|
+
* @returns Nothing.
|
|
329
|
+
* @example
|
|
330
|
+
* ui.heading("Diagnostics");
|
|
331
|
+
*/
|
|
332
|
+
heading(text: string): void;
|
|
333
|
+
/**
|
|
334
|
+
* Render a neutral informational line (`› message`). Continuation lines (after a `\n`)
|
|
335
|
+
* are indented under the first.
|
|
336
|
+
*
|
|
337
|
+
* @param message - The line to print.
|
|
338
|
+
* @returns Nothing.
|
|
339
|
+
* @example
|
|
340
|
+
* ui.info("watching for changes…");
|
|
341
|
+
*/
|
|
342
|
+
info(message: string): void;
|
|
343
|
+
/**
|
|
344
|
+
* Render a warning line (`⚠ message`, written to stderr).
|
|
345
|
+
*
|
|
346
|
+
* @param message - The warning to print.
|
|
347
|
+
* @returns Nothing.
|
|
348
|
+
* @example
|
|
349
|
+
* ui.warn("deploy skipped");
|
|
350
|
+
*/
|
|
351
|
+
warn(message: string): void;
|
|
352
|
+
/**
|
|
353
|
+
* Render an error line (`✗ message`, written to stderr), optionally with a cause printed
|
|
354
|
+
* beneath it.
|
|
355
|
+
*
|
|
356
|
+
* @param message - The error summary to print.
|
|
357
|
+
* @param cause - Optional underlying error/value to print beneath the summary.
|
|
358
|
+
* @returns Nothing.
|
|
359
|
+
* @example
|
|
360
|
+
* ui.error("build failed", err);
|
|
361
|
+
*/
|
|
362
|
+
error(message: string, cause?: unknown): void;
|
|
363
|
+
/**
|
|
364
|
+
* Render one diagnostic line: a green `✓` (pass) or red `✗` (fail) + label, with optional
|
|
365
|
+
* dim, indented detail beneath (e.g. a fix hint for a failing check).
|
|
366
|
+
*
|
|
367
|
+
* @param ok - Whether the check passed.
|
|
368
|
+
* @param label - The check label.
|
|
369
|
+
* @param detail - Optional multi-line guidance shown indented under the line.
|
|
370
|
+
* @returns Nothing.
|
|
371
|
+
* @example
|
|
372
|
+
* ui.check(false, "API_TOKEN is set", "Create one at …");
|
|
373
|
+
*/
|
|
374
|
+
check(ok: boolean, label: string, detail?: string): void;
|
|
375
|
+
/**
|
|
376
|
+
* Right-align `right` against `left` within `width`, measuring visible width so embedded
|
|
377
|
+
* ANSI never throws the alignment off. The building block for custom rail/panel rows.
|
|
378
|
+
*
|
|
379
|
+
* @param left - The left segment (may contain ANSI).
|
|
380
|
+
* @param right - The right segment (may contain ANSI).
|
|
381
|
+
* @param width - Total visible width to fill (defaults to the console width).
|
|
382
|
+
* @returns The padded line.
|
|
383
|
+
* @example
|
|
384
|
+
* ui.railLine(" ✓ pages", "· 12ms");
|
|
385
|
+
*/
|
|
386
|
+
railLine(left: string, right: string, width?: number): string;
|
|
387
|
+
/**
|
|
388
|
+
* Frame the given content lines in a brand box and write the result. Unicode borders on
|
|
389
|
+
* a TTY, ASCII off it; padded to the widest line or `minInnerWidth`.
|
|
390
|
+
*
|
|
391
|
+
* @param lines - The content lines (may contain ANSI).
|
|
392
|
+
* @param minInnerWidth - Minimum inner width to pad every row to. Defaults to `0`.
|
|
393
|
+
* @returns Nothing.
|
|
394
|
+
* @example
|
|
395
|
+
* ui.box(["Local http://localhost:4173"]);
|
|
396
|
+
*/
|
|
397
|
+
box(lines: string[], minInnerWidth?: number): void;
|
|
398
|
+
};
|
|
399
|
+
/**
|
|
400
|
+
* Create a {@link BrandConsole}. Output flows through the injected sink (default
|
|
401
|
+
* `console.log`/`console.error`) and is colorized only when color is enabled, so the
|
|
402
|
+
* identical render path yields branded color/Unicode on a TTY and plain ASCII in CI/pipes.
|
|
403
|
+
*
|
|
404
|
+
* @param options - Optional sinks, color/truecolor overrides, and width (see
|
|
405
|
+
* {@link BrandConsoleOptions}).
|
|
406
|
+
* @returns The branded console.
|
|
407
|
+
* @example
|
|
408
|
+
* const ui = createBrandConsole();
|
|
409
|
+
* ui.lockup({ wordmark: "moku tool", version: "v1.0.0" });
|
|
410
|
+
* ui.check(true, "config loaded");
|
|
411
|
+
*/
|
|
412
|
+
declare function createBrandConsole(options?: BrandConsoleOptions): BrandConsole;
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/plugins/log/types.d.ts
|
|
415
|
+
/** Severity level for a log entry. */
|
|
416
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
417
|
+
/**
|
|
418
|
+
* A single recorded log entry.
|
|
419
|
+
*/
|
|
420
|
+
type LogEntry = {
|
|
421
|
+
/** Severity level. */level: LogLevel; /** Event identifier (free-form string; convention: `domain:action`). */
|
|
422
|
+
event: string; /** Optional structured payload associated with the event. */
|
|
423
|
+
data?: unknown; /** Capture timestamp in epoch milliseconds (`Date.now()` at append time). */
|
|
424
|
+
ts: number; /** Optional originating plugin name. Reserved for future enrichment. */
|
|
425
|
+
plugin?: string;
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* Pluggable output target. Implement this to add console/file/JSON/etc. sinks
|
|
429
|
+
* WITHOUT changing the log API. Each logged entry is passed to `write` once,
|
|
430
|
+
* in registration order.
|
|
431
|
+
*/
|
|
432
|
+
type LogSink = {
|
|
433
|
+
/**
|
|
434
|
+
* Write a single entry to this sink.
|
|
435
|
+
*
|
|
436
|
+
* @param entry - The entry to emit.
|
|
437
|
+
*/
|
|
438
|
+
write(entry: LogEntry): void;
|
|
439
|
+
};
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/cli/log-sink.d.ts
|
|
442
|
+
/**
|
|
443
|
+
* Build a branded log {@link LogSink}: routes each entry to the matching brand line —
|
|
444
|
+
* `error` → `✗` (stderr), `warn` → `⚠` (stderr), `info` → `›`, `debug` → dim — with any
|
|
445
|
+
* structured `data` appended dim. Entries below `minLevel` are dropped (the in-memory
|
|
446
|
+
* trace still records everything). TTY/`NO_COLOR`-aware via the brand console.
|
|
447
|
+
*
|
|
448
|
+
* @param minLevel - Lowest severity to print. Defaults to `"debug"` (print all).
|
|
449
|
+
* @returns A {@link LogSink} that writes branded lines to stdout/stderr.
|
|
450
|
+
* @example
|
|
451
|
+
* ctx.log.clearSinks();
|
|
452
|
+
* ctx.log.addSink(brandedSink("info")); // suppress debug spam, branded output
|
|
453
|
+
*/
|
|
454
|
+
declare function brandedSink(minLevel?: LogLevel): LogSink;
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/cli/prompts.d.ts
|
|
457
|
+
/**
|
|
458
|
+
* Options for {@link createBrandPrompts}. All optional: the defaults read `process.stdin`
|
|
459
|
+
* and write to stdout with auto-detected color, while tests inject streams + a capturing
|
|
460
|
+
* choices-block sink.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* const prompts = createBrandPrompts({ color: false });
|
|
464
|
+
*/
|
|
465
|
+
type BrandPromptsOptions = {
|
|
466
|
+
/** Force color on/off. Defaults to `supportsColor()` (TTY + `NO_COLOR` unset). */color?: boolean; /** Force 24-bit truecolor on/off. Defaults to `supportsTruecolor()` (`COLORTERM`). */
|
|
467
|
+
truecolor?: boolean; /** Prompt rail width the styled hint right-aligns to. Defaults to `66`. */
|
|
468
|
+
width?: number; /** Readable stream the answer is read from. Defaults to `process.stdin`. */
|
|
469
|
+
input?: NodeJS.ReadableStream; /** Writable stream readline echoes to. Defaults to `process.stdout`. */
|
|
470
|
+
output?: NodeJS.WritableStream; /** Sink for the multi-line `select` choices block. Defaults to `console.log`. */
|
|
471
|
+
write?: (block: string) => void;
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* The branded prompts surface: a y/N {@link BrandPrompts.confirm} and a one-of-N
|
|
475
|
+
* {@link BrandPrompts.select}.
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* const prompts = createBrandPrompts();
|
|
479
|
+
* if (await prompts.confirm("Deploy?")) deploy();
|
|
480
|
+
*/
|
|
481
|
+
type BrandPrompts = {
|
|
482
|
+
/**
|
|
483
|
+
* Ask a yes/no question; resolves `true` only on an explicit `y`/`yes` (default `No`).
|
|
484
|
+
*
|
|
485
|
+
* @param question - The yes/no question to display.
|
|
486
|
+
* @returns Resolves `true` when the user answered yes.
|
|
487
|
+
* @example
|
|
488
|
+
* await prompts.confirm("Deploy dist/ to Cloudflare Pages?");
|
|
489
|
+
*/
|
|
490
|
+
confirm(question: string): Promise<boolean>;
|
|
491
|
+
/**
|
|
492
|
+
* Present `choices` numbered from 1 and resolve the chosen zero-based index (empty or
|
|
493
|
+
* out-of-range falls back to `0`).
|
|
494
|
+
*
|
|
495
|
+
* @param question - The prompt to display.
|
|
496
|
+
* @param choices - The selectable option labels.
|
|
497
|
+
* @returns Resolves the chosen zero-based index.
|
|
498
|
+
* @example
|
|
499
|
+
* await prompts.select("Trigger?", ["Auto on push", "Manual only"]);
|
|
500
|
+
*/
|
|
501
|
+
select(question: string, choices: readonly string[]): Promise<number>;
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Create {@link BrandPrompts} bound to a color mode + streams. Styling matches the brand
|
|
505
|
+
* console (the `◆` marker, dim hints, cyan caret); off a color TTY every prompt uses the
|
|
506
|
+
* plain `question [y/N]` / `question [1-N]` form.
|
|
507
|
+
*
|
|
508
|
+
* @param options - Optional color/width overrides and injectable streams/sink (see
|
|
509
|
+
* {@link BrandPromptsOptions}).
|
|
510
|
+
* @returns The branded prompts.
|
|
511
|
+
* @example
|
|
512
|
+
* const prompts = createBrandPrompts();
|
|
513
|
+
* const i = await prompts.select("Workflow?", ["Auto", "Manual"]);
|
|
514
|
+
*/
|
|
515
|
+
declare function createBrandPrompts(options?: BrandPromptsOptions): BrandPrompts;
|
|
516
|
+
//#endregion
|
|
517
|
+
export { ANSI, type AnsiCode, BRAND_PINK, type BoxGlyphs, type BrandConsole, type BrandConsoleOptions, type BrandPrompts, type BrandPromptsOptions, CLEAR_BELOW, CLEAR_LINE, type ColorStream, type LockupOptions, type Palette, SPINNER_FRAMES, box, boxGlyphs, brandedSink, createBrandConsole, createBrandPrompts, cursorUp, fg24, makePalette, spinnerFrameAt, supportsColor, supportsTruecolor, visibleWidth };
|