@tuicomponents/core 0.1.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/dist/index.cjs +629 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +715 -0
- package/dist/index.d.ts +715 -0
- package/dist/index.js +566 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
import { ZodType, ZodTypeDef } from 'zod';
|
|
2
|
+
import { Theme, Color, ThemeOptions } from 'chromaterm';
|
|
3
|
+
export { Color as ChromatermColor, Theme as ChromatermTheme, ThemeOptions } from 'chromaterm';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Semantic color mappings for TUI components.
|
|
7
|
+
* Maps component-level semantic names to chromaterm theme colors.
|
|
8
|
+
*/
|
|
9
|
+
interface SemanticColors {
|
|
10
|
+
/** Primary content color */
|
|
11
|
+
primary: Color;
|
|
12
|
+
/** Secondary/muted content */
|
|
13
|
+
secondary: Color;
|
|
14
|
+
/** Borders and separators */
|
|
15
|
+
border: Color;
|
|
16
|
+
/** Headers and titles */
|
|
17
|
+
header: Color;
|
|
18
|
+
/** Success state */
|
|
19
|
+
success: Color;
|
|
20
|
+
/** Warning state */
|
|
21
|
+
warning: Color;
|
|
22
|
+
/** Error state */
|
|
23
|
+
error: Color;
|
|
24
|
+
/** Informational text */
|
|
25
|
+
info: Color;
|
|
26
|
+
/** Added content (diffs) */
|
|
27
|
+
added: Color;
|
|
28
|
+
/** Removed content (diffs) */
|
|
29
|
+
removed: Color;
|
|
30
|
+
/** Modified content (diffs) */
|
|
31
|
+
modified: Color;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* TUI component theme combining chromaterm's theme with semantic mappings.
|
|
35
|
+
*/
|
|
36
|
+
interface TuiTheme {
|
|
37
|
+
/** Underlying chromaterm theme with ANSI colors */
|
|
38
|
+
chromaterm: Theme;
|
|
39
|
+
/** Semantic color mappings for components */
|
|
40
|
+
semantic: SemanticColors;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a synchronous T1 (ANSI-16) theme.
|
|
44
|
+
* Use this when you need a theme immediately without probing.
|
|
45
|
+
*
|
|
46
|
+
* @returns TUI theme with ANSI-16 colors
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const theme = createThemeSync();
|
|
51
|
+
* console.log(theme.semantic.error("Error message"));
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function createThemeSync(): TuiTheme;
|
|
55
|
+
/**
|
|
56
|
+
* Detect terminal capabilities and create an optimized theme.
|
|
57
|
+
* Uses OSC probing to detect the terminal's actual color palette.
|
|
58
|
+
*
|
|
59
|
+
* @param options - Theme detection options
|
|
60
|
+
* @returns Promise resolving to TUI theme with detected colors
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const theme = await detectTheme();
|
|
65
|
+
* console.log(theme.semantic.success("Success!"));
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare function detectTheme(options?: ThemeOptions): Promise<TuiTheme>;
|
|
69
|
+
/**
|
|
70
|
+
* Global default theme instance (T1 baseline).
|
|
71
|
+
* For full capability detection, use `detectTheme()` instead.
|
|
72
|
+
*/
|
|
73
|
+
declare const defaultTheme: TuiTheme;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Unified semantic styling for TUI components.
|
|
77
|
+
*
|
|
78
|
+
* Provides consistent styling across render modes:
|
|
79
|
+
* - ANSI mode: Uses theme semantic colors
|
|
80
|
+
* - Markdown mode: Uses markdown formatting (backticks, bold, etc.)
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Semantic styling functions that work across render modes.
|
|
85
|
+
*
|
|
86
|
+
* Components call these functions to apply semantic styling:
|
|
87
|
+
* - In ANSI mode: Applies theme colors
|
|
88
|
+
* - In markdown mode: Applies markdown formatting
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* // In a component render method:
|
|
93
|
+
* const styledText = context.style.secondary(sparklineBlocks);
|
|
94
|
+
* // ANSI mode: muted color
|
|
95
|
+
* // Markdown mode: `sparklineBlocks` (backtick wrapped)
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
interface StyleFunctions {
|
|
99
|
+
/** Primary content - default foreground */
|
|
100
|
+
primary: (text: string) => string;
|
|
101
|
+
/** Secondary/muted content - subdued style */
|
|
102
|
+
secondary: (text: string) => string;
|
|
103
|
+
/** Headers and titles - emphasized style */
|
|
104
|
+
header: (text: string) => string;
|
|
105
|
+
/** Borders and separators - subtle style */
|
|
106
|
+
border: (text: string) => string;
|
|
107
|
+
/** Success state - positive indicator */
|
|
108
|
+
success: (text: string) => string;
|
|
109
|
+
/** Warning state - caution indicator */
|
|
110
|
+
warning: (text: string) => string;
|
|
111
|
+
/** Error state - negative indicator */
|
|
112
|
+
error: (text: string) => string;
|
|
113
|
+
/** Informational text - neutral highlight */
|
|
114
|
+
info: (text: string) => string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create style functions appropriate for the render mode.
|
|
118
|
+
*
|
|
119
|
+
* @param renderMode - The current render mode ("ansi" or "markdown")
|
|
120
|
+
* @param theme - Optional theme for ANSI mode styling
|
|
121
|
+
* @returns StyleFunctions that apply mode-appropriate styling
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* // Markdown mode
|
|
126
|
+
* const style = createStyleFunctions("markdown");
|
|
127
|
+
* style.secondary("blocks") // Returns " `blocks`"
|
|
128
|
+
*
|
|
129
|
+
* // ANSI mode with theme
|
|
130
|
+
* const style = createStyleFunctions("ansi", theme);
|
|
131
|
+
* style.secondary("blocks") // Returns muted-colored text
|
|
132
|
+
*
|
|
133
|
+
* // ANSI mode without theme
|
|
134
|
+
* const style = createStyleFunctions("ansi");
|
|
135
|
+
* style.secondary("blocks") // Returns "blocks" unchanged
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function createStyleFunctions(renderMode: RenderMode, theme?: TuiTheme): StyleFunctions;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Render mode for component output.
|
|
142
|
+
*/
|
|
143
|
+
type RenderMode = "ansi" | "markdown";
|
|
144
|
+
/**
|
|
145
|
+
* Example input/output pair for a component.
|
|
146
|
+
*/
|
|
147
|
+
interface ComponentExample<TInput> {
|
|
148
|
+
/** Human-readable name for this example */
|
|
149
|
+
name: string;
|
|
150
|
+
/** Description of what this example demonstrates */
|
|
151
|
+
description?: string;
|
|
152
|
+
/** The input data for this example */
|
|
153
|
+
input: TInput;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Metadata describing a TUI component.
|
|
157
|
+
*/
|
|
158
|
+
interface ComponentMetadata<TInput> {
|
|
159
|
+
/** Unique name for this component (e.g., "table", "tree") */
|
|
160
|
+
name: string;
|
|
161
|
+
/** Human-readable description */
|
|
162
|
+
description: string;
|
|
163
|
+
/** Semantic version */
|
|
164
|
+
version: string;
|
|
165
|
+
/** Usage examples */
|
|
166
|
+
examples: ComponentExample<TInput>[];
|
|
167
|
+
/**
|
|
168
|
+
* Render modes this component supports.
|
|
169
|
+
* If not specified, defaults to ["ansi"].
|
|
170
|
+
*/
|
|
171
|
+
supportedModes?: RenderMode[];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Context provided to components during rendering.
|
|
175
|
+
*/
|
|
176
|
+
interface RenderContext {
|
|
177
|
+
/** Available terminal width in columns */
|
|
178
|
+
width: number;
|
|
179
|
+
/** Whether output is going to a TTY */
|
|
180
|
+
isTTY: boolean;
|
|
181
|
+
/** Color support level: 0=none, 1=basic, 2=256, 3=truecolor */
|
|
182
|
+
colorLevel: 0 | 1 | 2 | 3;
|
|
183
|
+
/** Optional theme for styled output. If not provided, components render without colors. */
|
|
184
|
+
theme?: TuiTheme;
|
|
185
|
+
/**
|
|
186
|
+
* Render mode for output.
|
|
187
|
+
* - "ansi": Full ANSI escape codes for rich terminals
|
|
188
|
+
* - "markdown": Markdown-friendly output for AI assistants
|
|
189
|
+
* @default "ansi"
|
|
190
|
+
*/
|
|
191
|
+
renderMode: RenderMode;
|
|
192
|
+
/**
|
|
193
|
+
* Semantic styling functions.
|
|
194
|
+
*
|
|
195
|
+
* Use these to apply consistent styling across render modes:
|
|
196
|
+
* - ANSI mode: Applies theme colors (or passthrough if no theme)
|
|
197
|
+
* - Markdown mode: Applies markdown formatting (backticks, bold, etc.)
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const styledBlocks = context.style.secondary(sparklineBlocks);
|
|
202
|
+
* // ANSI: muted color
|
|
203
|
+
* // Markdown: `sparklineBlocks`
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
style: StyleFunctions;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Result of rendering a component.
|
|
210
|
+
*/
|
|
211
|
+
interface RenderResult {
|
|
212
|
+
/** ANSI-formatted output string */
|
|
213
|
+
output: string;
|
|
214
|
+
/** Actual width of the widest line */
|
|
215
|
+
actualWidth: number;
|
|
216
|
+
/** Number of lines in the output */
|
|
217
|
+
lineCount: number;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* A TUI component that renders structured data to terminal output.
|
|
221
|
+
*/
|
|
222
|
+
interface TuiComponent<TInput, TSchema extends ZodType<TInput, ZodTypeDef, unknown> = ZodType<TInput, ZodTypeDef, unknown>> {
|
|
223
|
+
/** Component metadata */
|
|
224
|
+
readonly metadata: ComponentMetadata<TInput>;
|
|
225
|
+
/** Zod schema for input validation */
|
|
226
|
+
readonly schema: TSchema;
|
|
227
|
+
/**
|
|
228
|
+
* Render the component with the given input and context.
|
|
229
|
+
* @param input - Validated input data
|
|
230
|
+
* @param context - Rendering context
|
|
231
|
+
* @returns Rendered output with metadata
|
|
232
|
+
*/
|
|
233
|
+
render(input: TInput, context: RenderContext): RenderResult;
|
|
234
|
+
/**
|
|
235
|
+
* Get JSON Schema representation of the input schema.
|
|
236
|
+
* Used for CLI discovery and AI assistant integration.
|
|
237
|
+
*/
|
|
238
|
+
getJsonSchema(): object;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Factory function type for creating TUI components.
|
|
242
|
+
*/
|
|
243
|
+
type ComponentFactory<TInput, TSchema extends ZodType<TInput, ZodTypeDef, unknown>> = () => TuiComponent<TInput, TSchema>;
|
|
244
|
+
/**
|
|
245
|
+
* Base class helper for creating TUI components.
|
|
246
|
+
* Provides default implementations for common functionality.
|
|
247
|
+
*/
|
|
248
|
+
declare abstract class BaseTuiComponent<TInput, TSchema extends ZodType<TInput, ZodTypeDef, unknown>> implements TuiComponent<TInput, TSchema> {
|
|
249
|
+
abstract readonly metadata: ComponentMetadata<TInput>;
|
|
250
|
+
abstract readonly schema: TSchema;
|
|
251
|
+
abstract render(input: TInput, context: RenderContext): RenderResult;
|
|
252
|
+
getJsonSchema(): object;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Summary information about a registered component.
|
|
257
|
+
*/
|
|
258
|
+
interface ComponentInfo {
|
|
259
|
+
name: string;
|
|
260
|
+
description: string;
|
|
261
|
+
version: string;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* A registered component with unknown input type.
|
|
265
|
+
* Used internally by the registry.
|
|
266
|
+
*/
|
|
267
|
+
type AnyComponent = TuiComponent<any, ZodType<any, ZodTypeDef, any>>;
|
|
268
|
+
/**
|
|
269
|
+
* Global registry for TUI components.
|
|
270
|
+
* Enables CLI discovery and dynamic component lookup.
|
|
271
|
+
*/
|
|
272
|
+
declare class ComponentRegistry {
|
|
273
|
+
private components;
|
|
274
|
+
/**
|
|
275
|
+
* Register a component by invoking its factory function.
|
|
276
|
+
* @param factory - Factory function that creates the component
|
|
277
|
+
* @returns The created component instance
|
|
278
|
+
*/
|
|
279
|
+
register<TInput, TSchema extends ZodType<TInput, ZodTypeDef, unknown>>(factory: () => TuiComponent<TInput, TSchema>): TuiComponent<TInput, TSchema>;
|
|
280
|
+
/**
|
|
281
|
+
* Get a component by name.
|
|
282
|
+
* @param name - Component name
|
|
283
|
+
* @returns The component or undefined if not found
|
|
284
|
+
*/
|
|
285
|
+
get(name: string): AnyComponent | undefined;
|
|
286
|
+
/**
|
|
287
|
+
* Check if a component is registered.
|
|
288
|
+
* @param name - Component name
|
|
289
|
+
*/
|
|
290
|
+
has(name: string): boolean;
|
|
291
|
+
/**
|
|
292
|
+
* List all registered components.
|
|
293
|
+
* @returns Array of component info objects
|
|
294
|
+
*/
|
|
295
|
+
list(): ComponentInfo[];
|
|
296
|
+
/**
|
|
297
|
+
* Get all registered component names.
|
|
298
|
+
*/
|
|
299
|
+
names(): string[];
|
|
300
|
+
/**
|
|
301
|
+
* Clear all registered components.
|
|
302
|
+
* Primarily useful for testing.
|
|
303
|
+
*/
|
|
304
|
+
clear(): void;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Global component registry instance.
|
|
308
|
+
* Components register themselves here on import.
|
|
309
|
+
*/
|
|
310
|
+
declare const registry: ComponentRegistry;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Get the visual width of a string in terminal columns.
|
|
314
|
+
* Handles emoji, CJK characters, ANSI escape codes, and zero-width characters.
|
|
315
|
+
*
|
|
316
|
+
* @param str - The string to measure
|
|
317
|
+
* @returns Width in terminal columns
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* getStringWidth("hello"); // 5
|
|
322
|
+
* getStringWidth("你好"); // 4 (CJK characters are 2 columns each)
|
|
323
|
+
* getStringWidth("👋"); // 2 (emoji are typically 2 columns)
|
|
324
|
+
* getStringWidth("\x1b[31mred\x1b[0m"); // 3 (ANSI codes have 0 width)
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
declare function getStringWidth(str: string): number;
|
|
328
|
+
/**
|
|
329
|
+
* Options for padding operations.
|
|
330
|
+
*/
|
|
331
|
+
interface PadOptions {
|
|
332
|
+
/** Character to use for padding (default: space) */
|
|
333
|
+
padChar?: string;
|
|
334
|
+
/** Alignment direction */
|
|
335
|
+
align?: "left" | "right" | "center";
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Pad a string to a target width.
|
|
339
|
+
* If the string is already wider than the target, it is returned unchanged.
|
|
340
|
+
*
|
|
341
|
+
* @param str - The string to pad
|
|
342
|
+
* @param targetWidth - Target width in columns
|
|
343
|
+
* @param options - Padding options
|
|
344
|
+
* @returns Padded string
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* padToWidth("hi", 5); // "hi "
|
|
349
|
+
* padToWidth("hi", 5, { align: "right" }); // " hi"
|
|
350
|
+
* padToWidth("hi", 5, { align: "center" }); // " hi "
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
declare function padToWidth(str: string, targetWidth: number, options?: PadOptions): string;
|
|
354
|
+
/**
|
|
355
|
+
* Options for truncation operations.
|
|
356
|
+
*/
|
|
357
|
+
interface TruncateOptions {
|
|
358
|
+
/** String to append when truncating (default: "…") */
|
|
359
|
+
ellipsis?: string;
|
|
360
|
+
/** Where to truncate: end or middle */
|
|
361
|
+
position?: "end" | "middle";
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Truncate a string to fit within a target width.
|
|
365
|
+
* If the string already fits, it is returned unchanged.
|
|
366
|
+
*
|
|
367
|
+
* @param str - The string to truncate
|
|
368
|
+
* @param targetWidth - Maximum width in columns
|
|
369
|
+
* @param options - Truncation options
|
|
370
|
+
* @returns Truncated string
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* truncateToWidth("hello world", 8); // "hello w…"
|
|
375
|
+
* truncateToWidth("hello world", 8, { ellipsis: "..." }); // "hello..."
|
|
376
|
+
* truncateToWidth("hello world", 8, { position: "middle" }); // "hel…rld"
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare function truncateToWidth(str: string, targetWidth: number, options?: TruncateOptions): string;
|
|
380
|
+
/**
|
|
381
|
+
* Split a string into lines and measure each line's width.
|
|
382
|
+
*
|
|
383
|
+
* @param str - The string to analyze
|
|
384
|
+
* @returns Object with lines array and max width
|
|
385
|
+
*/
|
|
386
|
+
declare function measureLines(str: string): {
|
|
387
|
+
lines: string[];
|
|
388
|
+
maxWidth: number;
|
|
389
|
+
lineCount: number;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Default terminal dimensions when size cannot be determined.
|
|
394
|
+
*/
|
|
395
|
+
declare const DEFAULT_TERMINAL_WIDTH = 80;
|
|
396
|
+
declare const DEFAULT_TERMINAL_HEIGHT = 24;
|
|
397
|
+
/**
|
|
398
|
+
* Get the current terminal size.
|
|
399
|
+
*
|
|
400
|
+
* @returns Object with columns and rows
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts
|
|
404
|
+
* const { columns, rows } = getTerminalSize();
|
|
405
|
+
* console.log(`Terminal is ${columns}x${rows}`);
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
declare function getTerminalSize(): {
|
|
409
|
+
columns: number;
|
|
410
|
+
rows: number;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Get the current terminal width.
|
|
414
|
+
*
|
|
415
|
+
* @returns Width in columns
|
|
416
|
+
*/
|
|
417
|
+
declare function getTerminalWidth(): number;
|
|
418
|
+
/**
|
|
419
|
+
* Check if stdout is a TTY.
|
|
420
|
+
*
|
|
421
|
+
* @returns true if running in a TTY
|
|
422
|
+
*/
|
|
423
|
+
declare function isTTY(): boolean;
|
|
424
|
+
/**
|
|
425
|
+
* Detect the color support level of the terminal.
|
|
426
|
+
*
|
|
427
|
+
* @returns Color level: 0=none, 1=basic (16), 2=256, 3=truecolor (16m)
|
|
428
|
+
*/
|
|
429
|
+
declare function detectColorLevel(): 0 | 1 | 2 | 3;
|
|
430
|
+
/**
|
|
431
|
+
* Options for creating a render context.
|
|
432
|
+
*/
|
|
433
|
+
interface CreateRenderContextOptions {
|
|
434
|
+
/** Override the detected terminal width */
|
|
435
|
+
width?: number;
|
|
436
|
+
/** Provide a custom theme (default: defaultTheme if colors enabled) */
|
|
437
|
+
theme?: TuiTheme;
|
|
438
|
+
/** Disable colors even if terminal supports them */
|
|
439
|
+
noColor?: boolean;
|
|
440
|
+
/**
|
|
441
|
+
* Explicit render mode override.
|
|
442
|
+
* If set, disables auto-detection.
|
|
443
|
+
*/
|
|
444
|
+
renderMode?: RenderMode;
|
|
445
|
+
/**
|
|
446
|
+
* Whether to auto-detect render mode based on environment.
|
|
447
|
+
* When true (default), uses markdown mode in AI assistants.
|
|
448
|
+
* @default true
|
|
449
|
+
*/
|
|
450
|
+
autoDetectMode?: boolean;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Create a render context from current terminal state.
|
|
454
|
+
*
|
|
455
|
+
* @param options - Optional overrides for the context
|
|
456
|
+
* @returns A RenderContext ready for component rendering
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```ts
|
|
460
|
+
* // Auto-detect everything with theme
|
|
461
|
+
* const ctx = createRenderContext();
|
|
462
|
+
*
|
|
463
|
+
* // Force a specific width
|
|
464
|
+
* const ctx = createRenderContext({ width: 120 });
|
|
465
|
+
*
|
|
466
|
+
* // Disable colors
|
|
467
|
+
* const ctx = createRenderContext({ noColor: true });
|
|
468
|
+
*
|
|
469
|
+
* // Force markdown mode
|
|
470
|
+
* const ctx = createRenderContext({ renderMode: "markdown" });
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
declare function createRenderContext(options?: CreateRenderContextOptions): RenderContext;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Options for text wrapping.
|
|
477
|
+
*/
|
|
478
|
+
interface WrapOptions {
|
|
479
|
+
/** Whether to hard-wrap words that exceed the width */
|
|
480
|
+
hard?: boolean;
|
|
481
|
+
/** Whether to trim leading/trailing whitespace from each line */
|
|
482
|
+
trim?: boolean;
|
|
483
|
+
/** Whether to wrap at word boundaries (default: true) */
|
|
484
|
+
wordWrap?: boolean;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Wrap text to fit within a specified width.
|
|
488
|
+
* Preserves ANSI escape codes when wrapping.
|
|
489
|
+
*
|
|
490
|
+
* @param text - Text to wrap
|
|
491
|
+
* @param width - Maximum width in columns
|
|
492
|
+
* @param options - Wrapping options
|
|
493
|
+
* @returns Wrapped text with newlines
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```ts
|
|
497
|
+
* wrapText("The quick brown fox jumps over the lazy dog", 20);
|
|
498
|
+
* // "The quick brown fox\njumps over the lazy\ndog"
|
|
499
|
+
*
|
|
500
|
+
* // With ANSI codes preserved
|
|
501
|
+
* wrapText("\x1b[31mRed text that is very long\x1b[0m", 10);
|
|
502
|
+
* // "\x1b[31mRed text\x1b[0m\n\x1b[31mthat is\x1b[0m\n\x1b[31mvery long\x1b[0m"
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
declare function wrapText(text: string, width: number, options?: WrapOptions): string;
|
|
506
|
+
/**
|
|
507
|
+
* Wrap text and return information about the result.
|
|
508
|
+
*
|
|
509
|
+
* @param text - Text to wrap
|
|
510
|
+
* @param width - Maximum width in columns
|
|
511
|
+
* @param options - Wrapping options
|
|
512
|
+
* @returns Object with wrapped text and metadata
|
|
513
|
+
*/
|
|
514
|
+
declare function wrapTextWithInfo(text: string, width: number, options?: WrapOptions): {
|
|
515
|
+
text: string;
|
|
516
|
+
lines: string[];
|
|
517
|
+
lineCount: number;
|
|
518
|
+
maxWidth: number;
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Information about a process in the ancestry chain.
|
|
523
|
+
*/
|
|
524
|
+
interface ProcessAncestor {
|
|
525
|
+
pid: number;
|
|
526
|
+
command: string;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Result of environment detection.
|
|
530
|
+
*/
|
|
531
|
+
interface EnvironmentDetection {
|
|
532
|
+
/** Whether the environment is likely an AI assistant */
|
|
533
|
+
isAIAssistant: boolean;
|
|
534
|
+
/** Confidence level of the detection */
|
|
535
|
+
confidence: "high" | "medium" | "low";
|
|
536
|
+
/** Name of the detected assistant (if identified) */
|
|
537
|
+
detectedAssistant?: string;
|
|
538
|
+
/** Process tree from current process up to init */
|
|
539
|
+
processTree: ProcessAncestor[];
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Walk up the process tree to find parent processes.
|
|
543
|
+
* Only works on Unix-like systems (macOS, Linux).
|
|
544
|
+
*
|
|
545
|
+
* @returns Array of process ancestors from immediate parent up
|
|
546
|
+
*/
|
|
547
|
+
declare function getProcessTree(): ProcessAncestor[];
|
|
548
|
+
/**
|
|
549
|
+
* Detect the environment and determine if running in an AI assistant.
|
|
550
|
+
*
|
|
551
|
+
* Uses multiple heuristics:
|
|
552
|
+
* - Process tree analysis (most reliable)
|
|
553
|
+
* - TTY detection
|
|
554
|
+
* - Environment variables
|
|
555
|
+
* - Color support level
|
|
556
|
+
*
|
|
557
|
+
* @returns Detection result with confidence
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```ts
|
|
561
|
+
* const detection = detectEnvironment();
|
|
562
|
+
* if (detection.isAIAssistant) {
|
|
563
|
+
* console.log(`Running in ${detection.detectedAssistant}`);
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
declare function detectEnvironment(): EnvironmentDetection;
|
|
568
|
+
/**
|
|
569
|
+
* Simple check if running in an AI assistant environment.
|
|
570
|
+
*
|
|
571
|
+
* @returns true if likely running in an AI assistant
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```ts
|
|
575
|
+
* if (isRunningInAIAssistant()) {
|
|
576
|
+
* // Use markdown-friendly output
|
|
577
|
+
* }
|
|
578
|
+
* ```
|
|
579
|
+
*/
|
|
580
|
+
declare function isRunningInAIAssistant(): boolean;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Markdown rendering utilities for AI assistant-friendly output.
|
|
584
|
+
*
|
|
585
|
+
* These utilities help create output that renders well in environments
|
|
586
|
+
* that strip ANSI escape codes but support markdown rendering.
|
|
587
|
+
*/
|
|
588
|
+
/**
|
|
589
|
+
* Style types for the two-color markdown system.
|
|
590
|
+
* - "primary": Plain text (default terminal foreground)
|
|
591
|
+
* - "secondary": Inline code (`text`) - typically rendered with tan/yellow background
|
|
592
|
+
*/
|
|
593
|
+
type MarkdownStyle = "primary" | "secondary";
|
|
594
|
+
/**
|
|
595
|
+
* Default anchor character for line starts.
|
|
596
|
+
* Using │ (U+2502 BOX DRAWINGS LIGHT VERTICAL) as it's visually unobtrusive
|
|
597
|
+
* and prevents leading whitespace collapse in markdown rendering.
|
|
598
|
+
*/
|
|
599
|
+
declare const DEFAULT_ANCHOR = "\u2502";
|
|
600
|
+
/**
|
|
601
|
+
* Wrap text in inline code formatting.
|
|
602
|
+
*
|
|
603
|
+
* Adds a leading space before the opening backtick to compensate for
|
|
604
|
+
* the visual width difference when backticks are rendered as invisible.
|
|
605
|
+
*
|
|
606
|
+
* @param text - Text to wrap
|
|
607
|
+
* @returns Text wrapped in inline code with alignment compensation
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```ts
|
|
611
|
+
* inlineCode("hello") // Returns " `hello`"
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
declare function inlineCode(text: string): string;
|
|
615
|
+
/**
|
|
616
|
+
* Add an anchor character to the start of a line.
|
|
617
|
+
*
|
|
618
|
+
* Markdown renderers often collapse leading whitespace. Using an anchor
|
|
619
|
+
* character at the start of each line preserves alignment.
|
|
620
|
+
*
|
|
621
|
+
* @param content - Line content (without the anchor)
|
|
622
|
+
* @param anchor - Anchor character to use (defaults to │)
|
|
623
|
+
* @returns Line with anchor prefix
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```ts
|
|
627
|
+
* anchorLine(" Sales ████████") // "│ Sales ████████"
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
declare function anchorLine(content: string, anchor?: string): string;
|
|
631
|
+
/**
|
|
632
|
+
* Apply a markdown style to text.
|
|
633
|
+
*
|
|
634
|
+
* Implements the two-color system for markdown mode:
|
|
635
|
+
* - "primary": Returns text unchanged (plain foreground)
|
|
636
|
+
* - "secondary": Wraps text in inline code (typically tan/yellow background)
|
|
637
|
+
*
|
|
638
|
+
* @param text - Text to style
|
|
639
|
+
* @param style - Style to apply
|
|
640
|
+
* @returns Styled text
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```ts
|
|
644
|
+
* applyMarkdownStyle("Sales", "primary") // "Sales"
|
|
645
|
+
* applyMarkdownStyle("Support", "secondary") // " `Support`"
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
648
|
+
declare function applyMarkdownStyle(text: string, style: MarkdownStyle): string;
|
|
649
|
+
/**
|
|
650
|
+
* Join multiple lines with anchors.
|
|
651
|
+
*
|
|
652
|
+
* @param lines - Lines to join
|
|
653
|
+
* @param anchor - Anchor character to use
|
|
654
|
+
* @returns Lines joined with newlines, each prefixed with anchor
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```ts
|
|
658
|
+
* joinAnchoredLines(["line 1", "line 2"]) // "│line 1\n│line 2"
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
declare function joinAnchoredLines(lines: string[], anchor?: string): string;
|
|
662
|
+
/**
|
|
663
|
+
* Strip markdown formatting characters that will be consumed during rendering.
|
|
664
|
+
*
|
|
665
|
+
* This removes:
|
|
666
|
+
* - Inline code backticks: `text` → text
|
|
667
|
+
* - Bold markers: **text** or __text__ → text
|
|
668
|
+
* - Italic markers at word boundaries: *text* or _text_ → text
|
|
669
|
+
*
|
|
670
|
+
* It preserves:
|
|
671
|
+
* - Mid-word underscores: foo_bar stays as foo_bar
|
|
672
|
+
* - Asterisks with surrounding spaces: a * b stays as a * b
|
|
673
|
+
* - Unmatched markers without a closing pair
|
|
674
|
+
*
|
|
675
|
+
* @param str - String potentially containing markdown formatting
|
|
676
|
+
* @returns String with consumed formatting characters removed
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* stripMarkdownFormatting("`code`") // "code"
|
|
681
|
+
* stripMarkdownFormatting("**bold**") // "bold"
|
|
682
|
+
* stripMarkdownFormatting("_italic_") // "italic"
|
|
683
|
+
* stripMarkdownFormatting("foo_bar") // "foo_bar" (preserved)
|
|
684
|
+
* stripMarkdownFormatting("a * b") // "a * b" (preserved)
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
declare function stripMarkdownFormatting(str: string): string;
|
|
688
|
+
/**
|
|
689
|
+
* Get the visual width of a string after markdown rendering.
|
|
690
|
+
*
|
|
691
|
+
* This accounts for markdown formatting characters that will be consumed
|
|
692
|
+
* (become invisible) when rendered, such as backticks for inline code,
|
|
693
|
+
* asterisks for bold/italic, etc.
|
|
694
|
+
*
|
|
695
|
+
* Use this instead of getStringWidth() when calculating alignment for
|
|
696
|
+
* markdown output where formatting characters affect visual width.
|
|
697
|
+
*
|
|
698
|
+
* @param str - String potentially containing markdown formatting
|
|
699
|
+
* @returns Visual width in columns after markdown rendering
|
|
700
|
+
*
|
|
701
|
+
* @example
|
|
702
|
+
* ```ts
|
|
703
|
+
* getStringWidth("`code`") // 6 (counts backticks)
|
|
704
|
+
* getMarkdownRenderedWidth("`code`") // 4 (backticks will be invisible)
|
|
705
|
+
*
|
|
706
|
+
* getStringWidth("**bold**") // 8 (counts asterisks)
|
|
707
|
+
* getMarkdownRenderedWidth("**bold**") // 4 (asterisks will be invisible)
|
|
708
|
+
*
|
|
709
|
+
* getStringWidth("foo_bar") // 7
|
|
710
|
+
* getMarkdownRenderedWidth("foo_bar") // 7 (underscore preserved mid-word)
|
|
711
|
+
* ```
|
|
712
|
+
*/
|
|
713
|
+
declare function getMarkdownRenderedWidth(str: string): number;
|
|
714
|
+
|
|
715
|
+
export { BaseTuiComponent, type ComponentExample, type ComponentFactory, type ComponentInfo, type ComponentMetadata, ComponentRegistry, type CreateRenderContextOptions, DEFAULT_ANCHOR, DEFAULT_TERMINAL_HEIGHT, DEFAULT_TERMINAL_WIDTH, type EnvironmentDetection, type MarkdownStyle, type PadOptions, type ProcessAncestor, type RenderContext, type RenderMode, type RenderResult, type SemanticColors, type StyleFunctions, type TruncateOptions, type TuiComponent, type TuiTheme, type WrapOptions, anchorLine, applyMarkdownStyle, createRenderContext, createStyleFunctions, createThemeSync, defaultTheme, detectColorLevel, detectEnvironment, detectTheme, getMarkdownRenderedWidth, getProcessTree, getStringWidth, getTerminalSize, getTerminalWidth, inlineCode, isRunningInAIAssistant, isTTY, joinAnchoredLines, measureLines, padToWidth, registry, stripMarkdownFormatting, truncateToWidth, wrapText, wrapTextWithInfo };
|