duckdb-terminal 0.1.0

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/lib.d.ts ADDED
@@ -0,0 +1,2194 @@
1
+ export declare const BOLD = "\u001B[1m";
2
+
3
+ /**
4
+ * Apply bold style
5
+ */
6
+ export declare function bold(text: string): string;
7
+
8
+ /**
9
+ * Apply color to text.
10
+ * Accepts either a VT100 escape code constant (e.g., FG_RED) or a named color string (e.g., 'red').
11
+ *
12
+ * @param text - The text to colorize
13
+ * @param color - Either a VT100 escape code or a named color ('red', 'green', 'yellow', 'blue', 'cyan', 'magenta', 'white', 'black', or 'bright' variants)
14
+ * @returns The text wrapped with the color escape codes
15
+ *
16
+ * @example
17
+ * // Using VT100 constants
18
+ * colorize('Error', FG_RED)
19
+ *
20
+ * @example
21
+ * // Using named colors
22
+ * colorize('Success', 'green')
23
+ */
24
+ export declare function colorize(text: string, color: string): string;
25
+
26
+ /**
27
+ * Definition of a dot command
28
+ */
29
+ export declare interface Command {
30
+ /** Command name including the dot prefix */
31
+ name: string;
32
+ /** Short description of what the command does */
33
+ description: string;
34
+ /** Usage example */
35
+ usage?: string;
36
+ /** The function that handles the command */
37
+ handler: CommandHandler;
38
+ }
39
+
40
+ /**
41
+ * Interface for the terminal context needed by command handlers
42
+ */
43
+ export declare interface CommandContext {
44
+ /** Write text to terminal (no newline) */
45
+ write: (text: string) => void;
46
+ /** Write text to terminal with newline */
47
+ writeln: (text: string) => void;
48
+ /** Clear the terminal */
49
+ clear: () => void;
50
+ /** Get the database instance */
51
+ getDatabase: () => Database;
52
+ /** Get loaded files map */
53
+ getLoadedFiles: () => Map<string, FileInfo>;
54
+ /** Get last query result */
55
+ getLastQueryResult: () => QueryResult | null;
56
+ /** Get current output mode */
57
+ getOutputMode: () => 'table' | 'csv' | 'tsv' | 'json';
58
+ /** Set output mode */
59
+ setOutputMode: (mode: 'table' | 'csv' | 'tsv' | 'json') => void;
60
+ /** Get timer status */
61
+ getShowTimer: () => boolean;
62
+ /** Set timer status */
63
+ setShowTimer: (enabled: boolean) => void;
64
+ /** Get syntax highlighting status */
65
+ getSyntaxHighlighting: () => boolean;
66
+ /** Set syntax highlighting status */
67
+ setSyntaxHighlighting: (enabled: boolean) => void;
68
+ /** Get link provider */
69
+ getLinkProvider: () => LinkProvider;
70
+ /** Get page size */
71
+ getPageSize: () => number;
72
+ /** Set page size */
73
+ setPageSize: (size: number) => void;
74
+ /** Get current prompt */
75
+ getPrompt: () => string;
76
+ /** Get current continuation prompt */
77
+ getContinuationPrompt: () => string;
78
+ /** Set prompts */
79
+ setPrompts: (primary: string, continuation?: string) => void;
80
+ /** Get highlighted SQL */
81
+ getHighlightedSQL: (sql: string) => string;
82
+ /** Set theme */
83
+ setTheme: (theme: 'dark' | 'light') => void;
84
+ /** Get current theme name */
85
+ getThemeName: () => string;
86
+ /** Load a file */
87
+ loadFile: (file: File) => Promise<void>;
88
+ /** Remove a loaded file */
89
+ removeFile: (filename: string) => Promise<void>;
90
+ /** Reset the terminal state */
91
+ resetState: () => Promise<void>;
92
+ }
93
+
94
+ /**
95
+ * Handler function for a command
96
+ */
97
+ export declare type CommandHandler = (args: string[]) => Promise<void> | void;
98
+
99
+ /**
100
+ * An auto-completion suggestion.
101
+ */
102
+ declare interface CompletionSuggestion {
103
+ /** The suggested completion value */
104
+ value: string;
105
+ /** The type of suggestion (for display styling) */
106
+ type: 'keyword' | 'table' | 'column' | 'function';
107
+ }
108
+
109
+ /**
110
+ * URL link detection and handling for terminal output.
111
+ *
112
+ * This module provides utilities for detecting URLs in text and wrapping them
113
+ * in OSC 8 escape sequences to create clickable hyperlinks in supported terminals.
114
+ *
115
+ * OSC 8 (Operating System Command 8) is a standard escape sequence for hyperlinks:
116
+ * `\x1b]8;;URL\x07LINK_TEXT\x1b]8;;\x07`
117
+ *
118
+ * @module utils/link-provider
119
+ *
120
+ * @example Basic usage
121
+ * ```typescript
122
+ * import { linkifyText, containsURL } from './link-provider';
123
+ *
124
+ * const text = 'Visit https://example.com for more info';
125
+ * if (containsURL(text)) {
126
+ * const linkedText = linkifyText(text);
127
+ * // linkedText contains OSC 8 escape sequences
128
+ * }
129
+ * ```
130
+ */
131
+ /**
132
+ * Checks if text contains any URLs.
133
+ *
134
+ * @param text - The text to search for URLs
135
+ * @returns True if text contains at least one URL
136
+ */
137
+ export declare function containsURL(text: string): boolean;
138
+
139
+ /**
140
+ * Clipboard utilities for copy/paste support
141
+ */
142
+ /**
143
+ * Copy text to clipboard
144
+ */
145
+ export declare function copyToClipboard(text: string): Promise<boolean>;
146
+
147
+ /**
148
+ * Creates all command definitions for the terminal
149
+ */
150
+ export declare function createCommands(ctx: CommandContext): Map<string, Command>;
151
+
152
+ /**
153
+ * Creates and initializes a DuckDB terminal instance.
154
+ *
155
+ * This is the primary factory function for creating a terminal. It instantiates
156
+ * a new {@link DuckDBTerminal}, initializes all components (terminal adapter,
157
+ * database, history), and returns the ready-to-use terminal.
158
+ *
159
+ * @param config - Configuration options for the terminal
160
+ * @returns A promise that resolves to the initialized terminal instance
161
+ *
162
+ * @throws Error if the container element is not found
163
+ * @throws Error if DuckDB WASM initialization fails
164
+ *
165
+ * @example Create with a CSS selector
166
+ * ```typescript
167
+ * const terminal = await createTerminal({
168
+ * container: '#my-terminal',
169
+ * theme: 'dark',
170
+ * });
171
+ * ```
172
+ *
173
+ * @example Create with an HTML element
174
+ * ```typescript
175
+ * const container = document.getElementById('terminal');
176
+ * const terminal = await createTerminal({
177
+ * container,
178
+ * fontSize: 16,
179
+ * fontFamily: 'JetBrains Mono',
180
+ * theme: 'light',
181
+ * });
182
+ * ```
183
+ *
184
+ * @example Create with custom theme
185
+ * ```typescript
186
+ * const terminal = await createTerminal({
187
+ * container: '#terminal',
188
+ * theme: {
189
+ * name: 'my-theme',
190
+ * colors: {
191
+ * background: '#1a1b26',
192
+ * foreground: '#a9b1d6',
193
+ * // ... other colors
194
+ * },
195
+ * },
196
+ * });
197
+ * ```
198
+ *
199
+ * @example Create with custom prompts
200
+ * ```typescript
201
+ * const terminal = await createTerminal({
202
+ * container: '#terminal',
203
+ * prompt: 'SQL> ',
204
+ * continuationPrompt: '... ',
205
+ * });
206
+ * ```
207
+ */
208
+ export declare function createTerminal(config: TerminalConfig): Promise<DuckDBTerminal>;
209
+
210
+ /**
211
+ * Dark theme
212
+ */
213
+ export declare const darkTheme: Theme;
214
+
215
+ /**
216
+ * A wrapper around DuckDB WASM that provides a simplified interface for
217
+ * executing SQL queries and managing the database lifecycle.
218
+ *
219
+ * This class handles:
220
+ * - DuckDB WASM initialization and worker setup
221
+ * - Query execution and result formatting
222
+ * - Auto-completion suggestions for SQL keywords, tables, and functions
223
+ * - Virtual filesystem for loading external files (CSV, Parquet, JSON)
224
+ *
225
+ * @example Basic usage
226
+ * ```typescript
227
+ * const db = new Database({ storage: 'memory' });
228
+ * await db.init();
229
+ *
230
+ * const result = await db.executeQuery('SELECT 1 + 1 as answer;');
231
+ * console.log(result.rows); // [[2]]
232
+ *
233
+ * await db.close();
234
+ * ```
235
+ *
236
+ * @example With OPFS persistent storage
237
+ * ```typescript
238
+ * const db = new Database({
239
+ * storage: 'opfs',
240
+ * databasePath: '/mydata.duckdb',
241
+ * });
242
+ * await db.init();
243
+ * // Data persists across page refreshes
244
+ * ```
245
+ *
246
+ * @example Loading external files
247
+ * ```typescript
248
+ * const db = new Database();
249
+ * await db.init();
250
+ *
251
+ * // Register a file in DuckDB's virtual filesystem
252
+ * const csvData = new Uint8Array([...]); // CSV file contents
253
+ * await db.registerFile('data.csv', csvData);
254
+ *
255
+ * // Query the file
256
+ * const result = await db.executeQuery("SELECT * FROM read_csv('data.csv');");
257
+ * ```
258
+ */
259
+ export declare class Database {
260
+ private db;
261
+ private conn;
262
+ private worker;
263
+ private initialized;
264
+ private options;
265
+ constructor(options?: DatabaseOptions);
266
+ /**
267
+ * Initializes the DuckDB database.
268
+ *
269
+ * This method performs the following setup:
270
+ * 1. Downloads the appropriate DuckDB WASM bundle
271
+ * 2. Creates a Web Worker for database operations
272
+ * 3. Instantiates the DuckDB instance
273
+ * 4. Opens the database (in-memory or OPFS-backed)
274
+ * 5. Creates a connection for query execution
275
+ *
276
+ * @returns A promise that resolves when initialization is complete
277
+ *
278
+ * @throws Error if initialization fails (network issues, WASM loading, etc.)
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * const db = new Database();
283
+ * await db.init();
284
+ * console.log('Database ready:', db.isReady());
285
+ * ```
286
+ */
287
+ init(): Promise<void>;
288
+ /**
289
+ * Executes a SQL query and returns the results.
290
+ *
291
+ * @param sql - The SQL statement to execute
292
+ * @returns A promise that resolves to the query result containing columns, rows, row count, and duration
293
+ *
294
+ * @throws Error if the database is not initialized
295
+ * @throws Error if the SQL query is invalid or fails
296
+ *
297
+ * @example SELECT query
298
+ * ```typescript
299
+ * const result = await db.executeQuery('SELECT * FROM users WHERE age > 18;');
300
+ * console.log('Columns:', result.columns); // ['id', 'name', 'age']
301
+ * console.log('Rows:', result.rows); // [[1, 'Alice', 25], [2, 'Bob', 30]]
302
+ * console.log('Duration:', result.duration); // 5.23 (milliseconds)
303
+ * ```
304
+ *
305
+ * @example DDL statement
306
+ * ```typescript
307
+ * await db.executeQuery('CREATE TABLE products (id INTEGER, name VARCHAR);');
308
+ * ```
309
+ */
310
+ executeQuery(sql: string): Promise<QueryResult>;
311
+ /**
312
+ * Gets auto-completion suggestions for the current input.
313
+ *
314
+ * Provides suggestions for:
315
+ * - SQL keywords (SELECT, FROM, WHERE, etc.)
316
+ * - Table names from the current database
317
+ * - Common SQL functions
318
+ *
319
+ * @param text - The current input text
320
+ * @param cursorPosition - The cursor position within the text
321
+ * @returns A promise that resolves to an array of completion suggestions
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * const suggestions = await db.getCompletions('SEL', 3);
326
+ * console.log(suggestions);
327
+ * // [{ value: 'SELECT', type: 'keyword' }]
328
+ * ```
329
+ */
330
+ getCompletions(text: string, cursorPosition: number): Promise<CompletionSuggestion[]>;
331
+ /**
332
+ * Gets a list of all tables in the database.
333
+ *
334
+ * Queries the information_schema to retrieve table names from the 'main' schema.
335
+ *
336
+ * @returns A promise that resolves to an array of table names
337
+ *
338
+ * @example
339
+ * ```typescript
340
+ * const tables = await db.getTables();
341
+ * console.log('Tables:', tables); // ['users', 'products', 'orders']
342
+ * ```
343
+ */
344
+ getTables(): Promise<string[]>;
345
+ /**
346
+ * Gets the schema (column definitions) for a specific table.
347
+ *
348
+ * @param tableName - The name of the table to get the schema for
349
+ * @returns A promise that resolves to an array of column definitions
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * const schema = await db.getTableSchema('users');
354
+ * console.log(schema);
355
+ * // [
356
+ * // { name: 'id', type: 'INTEGER' },
357
+ * // { name: 'name', type: 'VARCHAR' },
358
+ * // { name: 'email', type: 'VARCHAR' }
359
+ * // ]
360
+ * ```
361
+ */
362
+ getTableSchema(tableName: string): Promise<{
363
+ name: string;
364
+ type: string;
365
+ }[]>;
366
+ /**
367
+ * Registers a file in DuckDB's virtual filesystem.
368
+ *
369
+ * This allows you to load external files (CSV, Parquet, JSON) into DuckDB
370
+ * and query them using functions like `read_csv()`, `read_parquet()`, etc.
371
+ *
372
+ * @param filename - The virtual filename to register (e.g., 'data.csv')
373
+ * @param data - The file contents as a Uint8Array
374
+ *
375
+ * @throws Error if the database is not initialized
376
+ *
377
+ * @example
378
+ * ```typescript
379
+ * // Load a CSV file
380
+ * const response = await fetch('https://example.com/data.csv');
381
+ * const data = new Uint8Array(await response.arrayBuffer());
382
+ * await db.registerFile('data.csv', data);
383
+ *
384
+ * // Query the file
385
+ * const result = await db.executeQuery("SELECT * FROM read_csv('data.csv');");
386
+ * ```
387
+ */
388
+ registerFile(filename: string, data: Uint8Array): Promise<void>;
389
+ /**
390
+ * Removes a file from DuckDB's virtual filesystem.
391
+ *
392
+ * @param filename - The filename to remove
393
+ *
394
+ * @throws Error if the database is not initialized
395
+ *
396
+ * @example
397
+ * ```typescript
398
+ * await db.dropFile('data.csv');
399
+ * ```
400
+ */
401
+ dropFile(filename: string): Promise<void>;
402
+ /**
403
+ * Checks if the database is initialized and ready for queries.
404
+ *
405
+ * @returns True if the database is ready, false otherwise
406
+ *
407
+ * @example
408
+ * ```typescript
409
+ * if (db.isReady()) {
410
+ * const result = await db.executeQuery('SELECT 1;');
411
+ * }
412
+ * ```
413
+ */
414
+ isReady(): boolean;
415
+ /**
416
+ * Closes the database connection and releases resources.
417
+ *
418
+ * This method:
419
+ * 1. Closes the database connection
420
+ * 2. Terminates the DuckDB instance
421
+ * 3. Terminates the Web Worker
422
+ *
423
+ * After calling this method, {@link init} must be called again before
424
+ * executing any queries.
425
+ *
426
+ * @returns A promise that resolves when cleanup is complete
427
+ *
428
+ * @example
429
+ * ```typescript
430
+ * await db.close();
431
+ * console.log('Database closed:', !db.isReady());
432
+ * ```
433
+ */
434
+ close(): Promise<void>;
435
+ }
436
+
437
+ /**
438
+ * Configuration options for the Database class.
439
+ */
440
+ declare interface DatabaseOptions {
441
+ /**
442
+ * The storage backend to use.
443
+ * - 'memory': In-memory database (default, data lost on page refresh)
444
+ * - 'opfs': Origin Private File System (persistent storage)
445
+ */
446
+ storage?: 'memory' | 'opfs';
447
+ /**
448
+ * The database file path when using OPFS storage.
449
+ * Defaults to ':memory:' for in-memory storage.
450
+ */
451
+ databasePath?: string;
452
+ }
453
+
454
+ export declare const DIM = "\u001B[2m";
455
+
456
+ /**
457
+ * Apply dim style
458
+ */
459
+ export declare function dim(text: string): string;
460
+
461
+ /**
462
+ * A browser-based SQL terminal for DuckDB, powered by Ghostty terminal emulator.
463
+ *
464
+ * DuckDBTerminal provides a full-featured SQL REPL (Read-Eval-Print Loop) that runs
465
+ * entirely in the browser using DuckDB WASM. It supports:
466
+ *
467
+ * - Multi-line SQL statements with syntax highlighting
468
+ * - Command history with arrow key navigation
469
+ * - Tab completion for SQL keywords, table names, and functions
470
+ * - Dot commands (`.help`, `.tables`, `.schema`, etc.)
471
+ * - Multiple output formats (table, CSV, JSON)
472
+ * - File loading via drag-and-drop or file picker
473
+ * - Result pagination for large datasets
474
+ * - Custom theming
475
+ * - Customizable prompts (via config or `.prompt` command)
476
+ * - Event system for integration with host applications
477
+ *
478
+ * @implements {TerminalInterface}
479
+ *
480
+ * @example Basic usage
481
+ * ```typescript
482
+ * const terminal = new DuckDBTerminal({
483
+ * container: '#terminal',
484
+ * theme: 'dark',
485
+ * });
486
+ * await terminal.start();
487
+ * ```
488
+ *
489
+ * @example With custom prompts
490
+ * ```typescript
491
+ * const terminal = new DuckDBTerminal({
492
+ * container: '#terminal',
493
+ * prompt: 'SQL> ',
494
+ * continuationPrompt: '... ',
495
+ * });
496
+ * await terminal.start();
497
+ * ```
498
+ *
499
+ * @example With event listeners
500
+ * ```typescript
501
+ * const terminal = new DuckDBTerminal({ container: '#terminal' });
502
+ *
503
+ * terminal.on('queryEnd', ({ sql, result, duration }) => {
504
+ * console.log(`Query "${sql}" completed in ${duration}ms`);
505
+ * });
506
+ *
507
+ * terminal.on('error', ({ message, source }) => {
508
+ * console.error(`Error from ${source}: ${message}`);
509
+ * });
510
+ *
511
+ * await terminal.start();
512
+ * ```
513
+ *
514
+ * @example Programmatic SQL execution
515
+ * ```typescript
516
+ * const terminal = new DuckDBTerminal({ container: '#terminal' });
517
+ * await terminal.start();
518
+ *
519
+ * const result = await terminal.executeSQL('SELECT * FROM users LIMIT 10;');
520
+ * console.log(result.columns); // ['id', 'name', 'email']
521
+ * console.log(result.rows); // [[1, 'Alice', 'alice@example.com'], ...]
522
+ * ```
523
+ */
524
+ export declare class DuckDBTerminal implements TerminalInterface {
525
+ private terminalAdapter;
526
+ private database;
527
+ private inputBuffer;
528
+ private history;
529
+ private state;
530
+ private collectedSQL;
531
+ private commands;
532
+ private showTimer;
533
+ private outputMode;
534
+ private currentThemeName;
535
+ private customTheme;
536
+ private config;
537
+ private loadedFiles;
538
+ private syntaxHighlighting;
539
+ private lastQueryResult;
540
+ private linkProvider;
541
+ private eventListeners;
542
+ private pageSize;
543
+ private paginationQuery;
544
+ private currentPage;
545
+ private totalRows;
546
+ private prompt;
547
+ private continuationPrompt;
548
+ private debouncedHighlight;
549
+ private queryQueue;
550
+ private dragDropCleanup;
551
+ constructor(config: TerminalConfig);
552
+ /**
553
+ * Subscribes to a terminal event.
554
+ *
555
+ * The terminal emits various events during its lifecycle that you can
556
+ * subscribe to for monitoring, logging, or integrating with your application.
557
+ *
558
+ * @typeParam K - The event type key from {@link TerminalEvents}
559
+ * @param event - The event name to subscribe to
560
+ * @param listener - The callback function to invoke when the event occurs
561
+ * @returns An unsubscribe function that removes the listener when called
562
+ *
563
+ * @example Subscribe to query events
564
+ * ```typescript
565
+ * const unsubscribe = terminal.on('queryEnd', ({ sql, result, duration }) => {
566
+ * console.log(`Query completed in ${duration}ms`);
567
+ * });
568
+ *
569
+ * // Later, to stop listening:
570
+ * unsubscribe();
571
+ * ```
572
+ *
573
+ * @example Monitor state changes
574
+ * ```typescript
575
+ * terminal.on('stateChange', ({ state, previous }) => {
576
+ * console.log(`Terminal state: ${previous} -> ${state}`);
577
+ * });
578
+ * ```
579
+ */
580
+ on<K extends keyof TerminalEvents>(event: K, listener: TerminalEventListener<K>): () => void;
581
+ /**
582
+ * Unsubscribes a listener from a terminal event.
583
+ *
584
+ * This is an alternative to using the unsubscribe function returned by {@link on}.
585
+ *
586
+ * @typeParam K - The event type key from {@link TerminalEvents}
587
+ * @param event - The event name to unsubscribe from
588
+ * @param listener - The callback function to remove
589
+ *
590
+ * @example
591
+ * ```typescript
592
+ * const handler = ({ sql }) => console.log(sql);
593
+ * terminal.on('queryStart', handler);
594
+ *
595
+ * // Later:
596
+ * terminal.off('queryStart', handler);
597
+ * ```
598
+ */
599
+ off<K extends keyof TerminalEvents>(event: K, listener: TerminalEventListener<K>): void;
600
+ /* Excluded from this release type: emit */
601
+ /* Excluded from this release type: setState */
602
+ /**
603
+ * Returns SQL with syntax highlighting applied.
604
+ *
605
+ * @param sql - The SQL string to highlight
606
+ * @returns The SQL with VT100 color codes applied, or the original SQL if highlighting is disabled
607
+ */
608
+ private getHighlightedSQL;
609
+ /**
610
+ * Redraws the current input line with syntax highlighting applied.
611
+ *
612
+ * This method clears the current line content and rewrites it with
613
+ * color codes for SQL keywords, strings, numbers, etc. Called on
614
+ * delimiter characters (space, semicolon, parentheses, comma) via debouncing.
615
+ */
616
+ private redrawLineHighlighted;
617
+ /**
618
+ * Returns the current theme object for terminal styling.
619
+ *
620
+ * @returns The custom theme if set, otherwise the built-in theme ('dark' or 'light')
621
+ */
622
+ private getCurrentThemeObject;
623
+ /**
624
+ * Initializes and starts the terminal.
625
+ *
626
+ * This method performs the following initialization steps:
627
+ * 1. Resolves the container element
628
+ * 2. Initializes the terminal adapter (Ghostty), database (DuckDB), and history store in parallel
629
+ * 3. Sets up input handling and drag-and-drop file loading
630
+ * 4. Displays the welcome message (if enabled)
631
+ * 5. Shows the command prompt
632
+ * 6. Emits the 'ready' event
633
+ *
634
+ * @returns A promise that resolves when the terminal is fully initialized
635
+ *
636
+ * @throws Error if the container element cannot be found
637
+ * @throws Error if DuckDB WASM initialization fails
638
+ *
639
+ * @example
640
+ * ```typescript
641
+ * const terminal = new DuckDBTerminal({ container: '#terminal' });
642
+ * await terminal.start();
643
+ * console.log('Terminal is ready!');
644
+ * ```
645
+ *
646
+ * @fires ready - Emitted when initialization is complete
647
+ */
648
+ start(): Promise<void>;
649
+ /**
650
+ * Cleans up resources and event listeners.
651
+ *
652
+ * Call this method when disposing of the terminal to prevent memory leaks.
653
+ * This removes drag-and-drop handlers and clears internal state.
654
+ */
655
+ destroy(): void;
656
+ /**
657
+ * Processes files dropped onto the terminal via drag-and-drop.
658
+ *
659
+ * Uses Promise.allSettled to ensure all files are attempted even if some fail.
660
+ *
661
+ * @param files - Array of File objects to load into DuckDB
662
+ */
663
+ private handleDroppedFiles;
664
+ /**
665
+ * Loads a file into DuckDB's virtual filesystem.
666
+ *
667
+ * Registers the file and displays usage hints for supported file types
668
+ * (CSV, Parquet, JSON). Emits a 'fileLoaded' event on success.
669
+ *
670
+ * @param file - The file to load
671
+ * @returns True if the file was loaded successfully, false otherwise
672
+ */
673
+ private loadFile;
674
+ /**
675
+ * Resolves the container element from the configuration.
676
+ *
677
+ * @returns The resolved HTML element to attach the terminal to
678
+ * @throws Error if the container selector doesn't match any element
679
+ */
680
+ private resolveContainer;
681
+ /**
682
+ * Registers all built-in dot commands (.help, .tables, .schema, etc.).
683
+ *
684
+ * Called during construction to populate the commands map with handlers
685
+ * for terminal commands.
686
+ */
687
+ private registerCommands;
688
+ /**
689
+ * Displays the command prompt (primary or continuation based on state).
690
+ *
691
+ * Sets terminal state to 'idle' if not currently collecting multi-line SQL.
692
+ */
693
+ private showPrompt;
694
+ /**
695
+ * Handles raw terminal input data.
696
+ *
697
+ * Routes input to the appropriate handler based on terminal state
698
+ * (executing, paginating, or normal input mode). Processes escape
699
+ * sequences separately from regular character input.
700
+ *
701
+ * @param data - The raw input data from the terminal
702
+ */
703
+ private handleInput;
704
+ /**
705
+ * Handles input during pagination mode.
706
+ *
707
+ * Supports: [n]ext page, [p]revious page, [q]uit, page number entry,
708
+ * and arrow keys for navigation.
709
+ *
710
+ * @param data - The input character or escape sequence
711
+ */
712
+ private handlePaginationInput;
713
+ /**
714
+ * Processes a single character of user input.
715
+ *
716
+ * Handles special characters (Enter, Backspace, Tab, Ctrl sequences)
717
+ * and regular printable characters including Unicode.
718
+ *
719
+ * @param char - The single character to process
720
+ */
721
+ private handleChar;
722
+ /**
723
+ * Checks if a character should trigger syntax highlighting redraw.
724
+ *
725
+ * @param char - The character to check
726
+ * @returns True if the character is a highlighting trigger (space, semicolon, parentheses, comma)
727
+ */
728
+ private isHighlightTrigger;
729
+ /**
730
+ * Processes VT100 escape sequences for special keys.
731
+ *
732
+ * Handles arrow keys (up/down for history, left/right for cursor),
733
+ * Home, End, and Delete keys.
734
+ *
735
+ * @param seq - The escape sequence string (e.g., '\x1b[A' for Arrow Up)
736
+ */
737
+ private handleEscapeSequence;
738
+ /**
739
+ * Handles the Enter key press.
740
+ *
741
+ * For dot commands, executes immediately. For SQL, collects lines until
742
+ * a semicolon terminates the statement, then executes.
743
+ */
744
+ private handleEnter;
745
+ /**
746
+ * Navigates to the previous command in history (Arrow Up).
747
+ */
748
+ private handleArrowUp;
749
+ /**
750
+ * Navigates to the next command in history (Arrow Down).
751
+ */
752
+ private handleArrowDown;
753
+ /**
754
+ * Handles Tab key for auto-completion.
755
+ *
756
+ * Provides suggestions for SQL keywords, table names, and functions.
757
+ * Single match is applied directly; multiple matches are displayed.
758
+ */
759
+ private handleTab;
760
+ /**
761
+ * Finds the longest common prefix among an array of strings.
762
+ *
763
+ * Used for auto-completion to expand to the longest unambiguous prefix.
764
+ *
765
+ * @param strings - Array of strings to find common prefix for
766
+ * @returns The longest common prefix (case-insensitive comparison)
767
+ */
768
+ private findCommonPrefix;
769
+ /**
770
+ * Handles Ctrl+C to cancel current input or multi-line collection.
771
+ */
772
+ private handleCtrlC;
773
+ /**
774
+ * Handles Ctrl+V to paste content from clipboard.
775
+ *
776
+ * Inserts text character-by-character, skipping newlines.
777
+ */
778
+ private handlePaste;
779
+ /**
780
+ * Copy last query result to clipboard
781
+ */
782
+ copyLastResult(): Promise<boolean>;
783
+ /**
784
+ * Executes a dot command (e.g., .help, .tables, .schema).
785
+ *
786
+ * Parses the command and arguments, looks up the handler, and executes it.
787
+ * Emits 'commandExecute' event on execution and 'error' on failure.
788
+ *
789
+ * @param input - The full command string including arguments
790
+ */
791
+ private executeCommand;
792
+ /**
793
+ * Executes a SQL query and displays the results.
794
+ *
795
+ * This method executes the provided SQL statement against the DuckDB database,
796
+ * displays the results in the configured output format (table, CSV, or JSON),
797
+ * and adds the query to the command history.
798
+ *
799
+ * For large result sets (when pagination is enabled via `.pagesize`), the method
800
+ * will automatically paginate the results and enter pagination mode.
801
+ *
802
+ * @param sql - The SQL statement to execute (should end with a semicolon)
803
+ * @returns A promise that resolves to the query result, or null if an error occurred
804
+ *
805
+ * @fires queryStart - Emitted before query execution begins
806
+ * @fires queryEnd - Emitted after query execution completes (success or failure)
807
+ * @fires error - Emitted if the query fails
808
+ *
809
+ * @example Execute a SELECT query
810
+ * ```typescript
811
+ * const result = await terminal.executeSQL('SELECT * FROM users;');
812
+ * if (result) {
813
+ * console.log(`Retrieved ${result.rowCount} rows in ${result.duration}ms`);
814
+ * console.log('Columns:', result.columns);
815
+ * console.log('First row:', result.rows[0]);
816
+ * }
817
+ * ```
818
+ *
819
+ * @example Execute DDL statements
820
+ * ```typescript
821
+ * await terminal.executeSQL('CREATE TABLE products (id INTEGER, name VARCHAR);');
822
+ * await terminal.executeSQL("INSERT INTO products VALUES (1, 'Widget');");
823
+ * ```
824
+ */
825
+ executeSQL(sql: string): Promise<QueryResult | null>;
826
+ /* Excluded from this release type: executeSQLInternal */
827
+ /**
828
+ * Executes the current paginated query for the current page.
829
+ *
830
+ * Adds LIMIT/OFFSET to the stored query and displays results with
831
+ * pagination controls.
832
+ *
833
+ * @returns The query result for the current page, or null on error
834
+ */
835
+ private executePaginatedQuery;
836
+ /**
837
+ * Exits pagination mode and resets pagination state.
838
+ */
839
+ private exitPagination;
840
+ /**
841
+ * Displays a query result in the current output mode.
842
+ *
843
+ * Formats and writes the result as table, CSV, TSV, or JSON based on
844
+ * the current outputMode setting.
845
+ *
846
+ * @param result - The query result to display
847
+ */
848
+ private displayResult;
849
+ private cmdHelp;
850
+ private cmdTables;
851
+ private cmdSchema;
852
+ private cmdTimer;
853
+ private cmdMode;
854
+ private cmdTheme;
855
+ private cmdExamples;
856
+ private cmdFiles;
857
+ private cmdOpen;
858
+ private cmdHighlight;
859
+ private cmdLinks;
860
+ private cmdPageSize;
861
+ private cmdReset;
862
+ private cmdPrompt;
863
+ /**
864
+ * Writes text to the terminal without a trailing newline.
865
+ *
866
+ * Use this method for inline output where you don't want to start a new line.
867
+ * The text is written directly to the terminal without any processing.
868
+ *
869
+ * @param text - The text to write to the terminal
870
+ *
871
+ * @example
872
+ * ```typescript
873
+ * terminal.write('Loading');
874
+ * terminal.write('...');
875
+ * terminal.write(' Done!\n');
876
+ * ```
877
+ */
878
+ write(text: string): void;
879
+ /**
880
+ * Writes text to the terminal followed by a newline.
881
+ *
882
+ * The text is processed for clickable URLs (if link detection is enabled)
883
+ * and newlines are normalized to CRLF for proper terminal display.
884
+ *
885
+ * @param text - The text to write to the terminal
886
+ *
887
+ * @example
888
+ * ```typescript
889
+ * terminal.writeln('Query completed successfully!');
890
+ * terminal.writeln('Visit https://duckdb.org for documentation');
891
+ * ```
892
+ */
893
+ writeln(text: string): void;
894
+ /**
895
+ * Clears the terminal screen.
896
+ *
897
+ * This removes all content from the terminal display and moves the cursor
898
+ * to the top-left corner.
899
+ *
900
+ * @example
901
+ * ```typescript
902
+ * terminal.clear();
903
+ * terminal.writeln('Screen cleared!');
904
+ * ```
905
+ */
906
+ clear(): void;
907
+ /**
908
+ * Sets the terminal color theme.
909
+ *
910
+ * You can set a built-in theme ('dark' or 'light') or provide a custom
911
+ * theme object with your own colors. Built-in theme preferences are
912
+ * persisted to localStorage.
913
+ *
914
+ * @param theme - The theme to apply: 'dark', 'light', or a custom Theme object
915
+ *
916
+ * @fires themeChange - Emitted after the theme is changed
917
+ *
918
+ * @example Set a built-in theme
919
+ * ```typescript
920
+ * terminal.setTheme('light');
921
+ * ```
922
+ *
923
+ * @example Set a custom theme
924
+ * ```typescript
925
+ * terminal.setTheme({
926
+ * name: 'my-theme',
927
+ * colors: {
928
+ * background: '#1a1b26',
929
+ * foreground: '#a9b1d6',
930
+ * cursor: '#c0caf5',
931
+ * // ... other color properties
932
+ * },
933
+ * });
934
+ * ```
935
+ */
936
+ setTheme(theme: 'dark' | 'light' | Theme): void;
937
+ /**
938
+ * Gets the current theme mode.
939
+ *
940
+ * Returns 'dark' or 'light' based on the current theme. For custom themes,
941
+ * this returns 'light' if the theme name is 'light', otherwise 'dark'.
942
+ *
943
+ * @returns The current theme mode: 'dark' or 'light'
944
+ *
945
+ * @example
946
+ * ```typescript
947
+ * const mode = terminal.getTheme();
948
+ * console.log(`Current theme mode: ${mode}`);
949
+ * ```
950
+ */
951
+ getTheme(): 'dark' | 'light';
952
+ }
953
+
954
+ /**
955
+ * Embeds a DuckDB terminal into a container element.
956
+ *
957
+ * This is an alias for {@link createTerminal} provided for semantic clarity
958
+ * when embedding the terminal into an existing page.
959
+ *
960
+ * @param config - Configuration options for the terminal
961
+ * @returns A promise that resolves to the initialized terminal instance
962
+ *
963
+ * @example
964
+ * ```typescript
965
+ * const terminal = await embed({
966
+ * container: '#sql-editor',
967
+ * theme: 'dark',
968
+ * welcomeMessage: false,
969
+ * });
970
+ * ```
971
+ */
972
+ export declare function embed(config: TerminalConfig): Promise<DuckDBTerminal>;
973
+
974
+ /**
975
+ * Extracts all URLs from text.
976
+ *
977
+ * @param text - The text to extract URLs from
978
+ * @returns Array of URLs found in the text
979
+ */
980
+ export declare function extractURLs(text: string): string[];
981
+
982
+ export declare const FG_BLUE = "\u001B[34m";
983
+
984
+ export declare const FG_CYAN = "\u001B[36m";
985
+
986
+ export declare const FG_GREEN = "\u001B[32m";
987
+
988
+ export declare const FG_RED = "\u001B[31m";
989
+
990
+ export declare const FG_WHITE = "\u001B[37m";
991
+
992
+ export declare const FG_YELLOW = "\u001B[33m";
993
+
994
+ declare interface FileInfo {
995
+ name: string;
996
+ size: number;
997
+ type: string;
998
+ lastModified: Date;
999
+ }
1000
+
1001
+ /**
1002
+ * Format query results as CSV
1003
+ */
1004
+ export declare function formatCSV(columns: string[], rows: unknown[][]): string;
1005
+
1006
+ /**
1007
+ * Format query results as JSON.
1008
+ * Uses jsonSafeReplacer to handle BigInt values that JSON.stringify
1009
+ * cannot serialize natively.
1010
+ */
1011
+ export declare function formatJSON(columns: string[], rows: unknown[][]): string;
1012
+
1013
+ /**
1014
+ * Format query results as ASCII table
1015
+ */
1016
+ export declare function formatTable(columns: string[], rows: unknown[][], options?: TableOptions): string;
1017
+
1018
+ /**
1019
+ * Format query results as TSV (Tab-Separated Values)
1020
+ */
1021
+ export declare function formatTSV(columns: string[], rows: unknown[][]): string;
1022
+
1023
+ /**
1024
+ * Get saved theme preference
1025
+ */
1026
+ export declare function getSavedTheme(): 'dark' | 'light';
1027
+
1028
+ /**
1029
+ * Get theme by name
1030
+ */
1031
+ export declare function getTheme(name: 'dark' | 'light'): Theme;
1032
+
1033
+ /**
1034
+ * Highlight SQL string with ANSI colors
1035
+ */
1036
+ export declare function highlightSQL(sql: string): string;
1037
+
1038
+ /**
1039
+ * Command history store using IndexedDB for persistence.
1040
+ *
1041
+ * This module provides a persistent command history that survives browser
1042
+ * refreshes. History is stored in IndexedDB and falls back to in-memory
1043
+ * storage if IndexedDB is unavailable.
1044
+ *
1045
+ * @module utils/history
1046
+ */
1047
+ /**
1048
+ * A persistent command history store backed by IndexedDB.
1049
+ *
1050
+ * Features:
1051
+ * - Persists command history to IndexedDB
1052
+ * - Falls back to in-memory storage if IndexedDB is unavailable
1053
+ * - Supports navigation through history with previous/next
1054
+ * - Automatically limits history size to prevent unbounded growth
1055
+ * - Deduplicates consecutive identical commands
1056
+ *
1057
+ * @example Basic usage
1058
+ * ```typescript
1059
+ * const history = new HistoryStore();
1060
+ * await history.init();
1061
+ *
1062
+ * // Add commands to history
1063
+ * await history.add('SELECT * FROM users;');
1064
+ * await history.add('SELECT count(*) FROM orders;');
1065
+ *
1066
+ * // Navigate history
1067
+ * const prev = history.previous(''); // Returns 'SELECT count(*) FROM orders;'
1068
+ * const prev2 = history.previous(''); // Returns 'SELECT * FROM users;'
1069
+ * const next = history.next(); // Returns 'SELECT count(*) FROM orders;'
1070
+ * ```
1071
+ *
1072
+ * @example With input preservation
1073
+ * ```typescript
1074
+ * const history = new HistoryStore();
1075
+ * await history.init();
1076
+ *
1077
+ * // Current input is preserved when navigating
1078
+ * const prev = history.previous('SELECT '); // Saves 'SELECT ' as current input
1079
+ * // ... user navigates through history ...
1080
+ * const current = history.next(); // Eventually returns 'SELECT '
1081
+ * ```
1082
+ */
1083
+ export declare class HistoryStore {
1084
+ private db;
1085
+ private history;
1086
+ private cursor;
1087
+ private currentInput;
1088
+ private initialized;
1089
+ /**
1090
+ * Initializes the history store by opening IndexedDB and loading existing history.
1091
+ *
1092
+ * This method must be called before using other methods. It loads any
1093
+ * previously stored commands from IndexedDB. If IndexedDB is unavailable
1094
+ * (e.g., in private browsing), the store falls back to in-memory storage.
1095
+ *
1096
+ * @returns A promise that resolves when initialization is complete
1097
+ *
1098
+ * @example
1099
+ * ```typescript
1100
+ * const history = new HistoryStore();
1101
+ * await history.init();
1102
+ * // Now ready to use
1103
+ * ```
1104
+ */
1105
+ init(): Promise<void>;
1106
+ /**
1107
+ * Open IndexedDB database
1108
+ */
1109
+ private openDatabase;
1110
+ /**
1111
+ * Load history from IndexedDB
1112
+ */
1113
+ private loadHistory;
1114
+ /**
1115
+ * Adds a command to the history.
1116
+ *
1117
+ * The command is stored both in memory and persisted to IndexedDB.
1118
+ * Empty commands and consecutive duplicates are ignored.
1119
+ *
1120
+ * @param command - The command to add to history
1121
+ * @returns A promise that resolves when the command has been persisted
1122
+ *
1123
+ * @example
1124
+ * ```typescript
1125
+ * await history.add('SELECT * FROM users;');
1126
+ * await history.add('SELECT * FROM users;'); // Ignored (duplicate)
1127
+ * await history.add(''); // Ignored (empty)
1128
+ * ```
1129
+ */
1130
+ add(command: string): Promise<void>;
1131
+ /**
1132
+ * Save command to IndexedDB
1133
+ */
1134
+ private saveCommand;
1135
+ /**
1136
+ * Trim history in IndexedDB to max size.
1137
+ *
1138
+ * Uses a single transaction for all deletions for better performance.
1139
+ */
1140
+ private trimHistory;
1141
+ /**
1142
+ * Navigates to the previous command in history.
1143
+ *
1144
+ * When called from the end of history (most recent position), this method
1145
+ * saves the current input so it can be restored when navigating forward.
1146
+ *
1147
+ * @param currentInput - The current input buffer content to preserve
1148
+ * @returns The previous command, or null if at the beginning of history
1149
+ *
1150
+ * @example
1151
+ * ```typescript
1152
+ * // Assuming history has ['SELECT 1;', 'SELECT 2;']
1153
+ * const cmd1 = history.previous('SELECT 3'); // Returns 'SELECT 2;'
1154
+ * const cmd2 = history.previous(''); // Returns 'SELECT 1;'
1155
+ * const cmd3 = history.previous(''); // Returns null (at beginning)
1156
+ * ```
1157
+ */
1158
+ previous(currentInput: string): string | null;
1159
+ /**
1160
+ * Navigates to the next command in history.
1161
+ *
1162
+ * When reaching the end of history, returns the previously saved current input.
1163
+ *
1164
+ * @returns The next command, the saved current input if at the end, or null if beyond
1165
+ *
1166
+ * @example
1167
+ * ```typescript
1168
+ * // After navigating backward with previous()
1169
+ * const cmd1 = history.next(); // Returns next newer command
1170
+ * const cmd2 = history.next(); // Returns original input when at end
1171
+ * ```
1172
+ */
1173
+ next(): string | null;
1174
+ /**
1175
+ * Resets the history cursor to the end and clears the saved current input.
1176
+ *
1177
+ * This should be called after a command is executed to prepare for new navigation.
1178
+ */
1179
+ reset(): void;
1180
+ /**
1181
+ * Returns a copy of all commands in history.
1182
+ *
1183
+ * @returns An array of all stored commands, oldest first
1184
+ */
1185
+ getAll(): string[];
1186
+ /**
1187
+ * Clears all history from both memory and IndexedDB.
1188
+ *
1189
+ * @returns A promise that resolves when the history has been cleared
1190
+ */
1191
+ clear(): Promise<void>;
1192
+ }
1193
+
1194
+ /**
1195
+ * A text buffer with cursor management for terminal line editing.
1196
+ *
1197
+ * The InputBuffer maintains both the current text content and cursor position,
1198
+ * providing methods for common editing operations. Each editing method returns
1199
+ * the VT100 escape sequences needed to update the terminal display.
1200
+ *
1201
+ * Features:
1202
+ * - Character insertion at cursor position
1203
+ * - Backspace and delete key handling
1204
+ * - Cursor movement (left, right, home, end)
1205
+ * - Line clearing operations
1206
+ * - Word-based operations for auto-completion
1207
+ *
1208
+ * @example Basic usage
1209
+ * ```typescript
1210
+ * const buffer = new InputBuffer();
1211
+ *
1212
+ * // Type "hello"
1213
+ * terminal.write(buffer.insert('h'));
1214
+ * terminal.write(buffer.insert('e'));
1215
+ * terminal.write(buffer.insert('l'));
1216
+ * terminal.write(buffer.insert('l'));
1217
+ * terminal.write(buffer.insert('o'));
1218
+ *
1219
+ * console.log(buffer.getContent()); // 'hello'
1220
+ * console.log(buffer.getCursorPos()); // 5
1221
+ *
1222
+ * // Delete last character
1223
+ * terminal.write(buffer.backspace()); // Buffer is now 'hell'
1224
+ * ```
1225
+ *
1226
+ * @example Cursor movement
1227
+ * ```typescript
1228
+ * const buffer = new InputBuffer();
1229
+ * buffer.setContent('hello world');
1230
+ *
1231
+ * terminal.write(buffer.moveToStart()); // Cursor at position 0
1232
+ * terminal.write(buffer.moveRight()); // Cursor at position 1
1233
+ * terminal.write(buffer.moveToEnd()); // Cursor at position 11
1234
+ * ```
1235
+ *
1236
+ * @example Auto-completion
1237
+ * ```typescript
1238
+ * const buffer = new InputBuffer();
1239
+ * buffer.setContent('SELECT * FROM us');
1240
+ *
1241
+ * const word = buffer.getWordBeforeCursor(); // 'us'
1242
+ * terminal.write(buffer.replaceWordBeforeCursor('users'));
1243
+ * console.log(buffer.getContent()); // 'SELECT * FROM users'
1244
+ * ```
1245
+ */
1246
+ export declare class InputBuffer {
1247
+ private buffer;
1248
+ private cursorPos;
1249
+ private maxSize;
1250
+ /**
1251
+ * Set the prompt length for cursor calculations (reserved for future use)
1252
+ */
1253
+ setPromptLength(_length: number): void;
1254
+ /**
1255
+ * Sets the maximum buffer size.
1256
+ *
1257
+ * @param size - Maximum size in bytes (defaults to MAX_BUFFER_SIZE)
1258
+ */
1259
+ setMaxSize(size: number): void;
1260
+ /**
1261
+ * Returns the maximum buffer size.
1262
+ *
1263
+ * @returns The maximum size in bytes
1264
+ */
1265
+ getMaxSize(): number;
1266
+ /**
1267
+ * Returns the current buffer content.
1268
+ *
1269
+ * @returns The full text content of the buffer
1270
+ */
1271
+ getContent(): string;
1272
+ /**
1273
+ * Returns the current cursor position within the buffer.
1274
+ *
1275
+ * @returns The zero-based cursor position
1276
+ */
1277
+ getCursorPos(): number;
1278
+ /**
1279
+ * Clears the buffer and resets cursor to position 0.
1280
+ */
1281
+ clear(): void;
1282
+ /**
1283
+ * Sets the buffer content and moves cursor to end.
1284
+ *
1285
+ * Used for history navigation when replacing the current line with a previous command.
1286
+ *
1287
+ * @param content - The new buffer content
1288
+ */
1289
+ setContent(content: string): void;
1290
+ /**
1291
+ * Inserts text at the cursor position.
1292
+ *
1293
+ * @param char - The character(s) to insert
1294
+ * @returns VT100 escape sequences to update the terminal display
1295
+ */
1296
+ insert(char: string): string;
1297
+ /**
1298
+ * Deletes the character before the cursor (backspace operation).
1299
+ *
1300
+ * @returns VT100 escape sequences to update the terminal display, or empty string if at start
1301
+ */
1302
+ backspace(): string;
1303
+ /**
1304
+ * Deletes the character at the cursor position (delete key operation).
1305
+ *
1306
+ * @returns VT100 escape sequences to update the terminal display, or empty string if at end
1307
+ */
1308
+ delete(): string;
1309
+ /**
1310
+ * Moves the cursor one position to the left.
1311
+ *
1312
+ * @returns VT100 escape sequence, or empty string if already at start
1313
+ */
1314
+ moveLeft(): string;
1315
+ /**
1316
+ * Moves the cursor one position to the right.
1317
+ *
1318
+ * @returns VT100 escape sequence, or empty string if already at end
1319
+ */
1320
+ moveRight(): string;
1321
+ /**
1322
+ * Moves the cursor to the start of the line (Home key / Ctrl+A).
1323
+ *
1324
+ * @returns VT100 escape sequence, or empty string if already at start
1325
+ */
1326
+ moveToStart(): string;
1327
+ /**
1328
+ * Moves the cursor to the end of the line (End key / Ctrl+E).
1329
+ *
1330
+ * @returns VT100 escape sequence, or empty string if already at end
1331
+ */
1332
+ moveToEnd(): string;
1333
+ /**
1334
+ * Clears from cursor position to end of line (Ctrl+K).
1335
+ *
1336
+ * @returns VT100 escape sequence to clear the terminal
1337
+ */
1338
+ clearToEnd(): string;
1339
+ /**
1340
+ * Clears the entire line and resets buffer (Ctrl+U).
1341
+ *
1342
+ * @returns VT100 escape sequences to clear the terminal line
1343
+ */
1344
+ clearLine(): string;
1345
+ /**
1346
+ * Returns the word immediately before the cursor for auto-completion.
1347
+ *
1348
+ * A word is defined as a sequence of word characters (`\w`) and dots.
1349
+ *
1350
+ * @returns The word before cursor, or empty string if none
1351
+ */
1352
+ getWordBeforeCursor(): string;
1353
+ /**
1354
+ * Replaces the word before the cursor with a completion string.
1355
+ *
1356
+ * @param completion - The completion string to insert
1357
+ * @returns VT100 escape sequences to update the terminal display
1358
+ */
1359
+ replaceWordBeforeCursor(completion: string): string;
1360
+ /**
1361
+ * Checks if the buffer is empty.
1362
+ *
1363
+ * @returns True if buffer has no content
1364
+ */
1365
+ isEmpty(): boolean;
1366
+ /**
1367
+ * Checks if the buffer contains only whitespace.
1368
+ *
1369
+ * @returns True if buffer is empty or contains only whitespace
1370
+ */
1371
+ isBlank(): boolean;
1372
+ }
1373
+
1374
+ /**
1375
+ * Check if clipboard API is available
1376
+ */
1377
+ export declare function isClipboardAvailable(): boolean;
1378
+
1379
+ /**
1380
+ * Check if SQL appears complete (ends with semicolon outside of string/comment)
1381
+ */
1382
+ export declare function isSQLComplete(sql: string): boolean;
1383
+
1384
+ /**
1385
+ * Validates if a string is a valid URL.
1386
+ *
1387
+ * @param str - The string to validate
1388
+ * @returns True if the string is a valid URL
1389
+ */
1390
+ export declare function isValidURL(str: string): boolean;
1391
+
1392
+ /**
1393
+ * Light theme
1394
+ */
1395
+ export declare const lightTheme: Theme;
1396
+
1397
+ /**
1398
+ * Processes text and makes all URLs clickable using OSC 8 escape sequences.
1399
+ *
1400
+ * @param text - The text to process
1401
+ * @returns The text with URLs wrapped in hyperlink escape sequences
1402
+ */
1403
+ export declare function linkifyText(text: string): string;
1404
+
1405
+ /**
1406
+ * A class for processing text output and adding clickable hyperlinks.
1407
+ *
1408
+ * The LinkProvider wraps the utility functions in a stateful class that
1409
+ * can be enabled/disabled and configured with a maximum URL display length.
1410
+ *
1411
+ * @example
1412
+ * ```typescript
1413
+ * const provider = new LinkProvider();
1414
+ *
1415
+ * // Process text with links
1416
+ * const output = provider.process('See https://example.com');
1417
+ *
1418
+ * // Disable link processing
1419
+ * provider.setEnabled(false);
1420
+ * ```
1421
+ */
1422
+ export declare class LinkProvider {
1423
+ private enabled;
1424
+ private maxURLLength;
1425
+ /**
1426
+ * Enable or disable URL linking
1427
+ */
1428
+ setEnabled(enabled: boolean): void;
1429
+ /**
1430
+ * Check if URL linking is enabled
1431
+ */
1432
+ isEnabled(): boolean;
1433
+ /**
1434
+ * Set maximum URL display length
1435
+ */
1436
+ setMaxURLLength(length: number): void;
1437
+ /**
1438
+ * Process text and add hyperlinks to URLs
1439
+ */
1440
+ process(text: string): string;
1441
+ /**
1442
+ * Process text with truncated URL display
1443
+ */
1444
+ processWithTruncation(text: string): string;
1445
+ }
1446
+
1447
+ /**
1448
+ * Interface for the terminal context needed by pagination
1449
+ */
1450
+ export declare interface PaginationContext {
1451
+ /** Write text to terminal (no newline) */
1452
+ write: (text: string) => void;
1453
+ /** Write text to terminal with newline */
1454
+ writeln: (text: string) => void;
1455
+ /** Get the database instance */
1456
+ getDatabase: () => Database;
1457
+ /** Display query result */
1458
+ displayResult: (result: QueryResult, showTiming: boolean) => void;
1459
+ /** Get input buffer content */
1460
+ getInputContent: () => string;
1461
+ /** Clear input buffer */
1462
+ clearInput: () => void;
1463
+ /** Insert character into input buffer */
1464
+ insertChar: (char: string) => string;
1465
+ /** Backspace in input buffer */
1466
+ backspace: () => string;
1467
+ }
1468
+
1469
+ /**
1470
+ * PaginationHandler manages the pagination of large query results
1471
+ */
1472
+ export declare class PaginationHandler {
1473
+ private state;
1474
+ private ctx;
1475
+ constructor(ctx: PaginationContext);
1476
+ /**
1477
+ * Initialize pagination for a query
1478
+ */
1479
+ start(query: string, totalRows: number, pageSize: number): void;
1480
+ /**
1481
+ * Exit pagination mode
1482
+ */
1483
+ exit(): void;
1484
+ /**
1485
+ * Check if pagination is currently active
1486
+ */
1487
+ isActive(): boolean;
1488
+ /**
1489
+ * Get current state
1490
+ */
1491
+ getState(): Readonly<PaginationState>;
1492
+ /**
1493
+ * Get the total number of pages
1494
+ */
1495
+ getTotalPages(): number;
1496
+ /**
1497
+ * Get current page (1-indexed for display)
1498
+ */
1499
+ getCurrentPageDisplay(): number;
1500
+ /**
1501
+ * Execute the paginated query for the current page
1502
+ */
1503
+ executeCurrentPage(): Promise<void>;
1504
+ /**
1505
+ * Show navigation hint
1506
+ */
1507
+ showNavigationHint(): void;
1508
+ /**
1509
+ * Handle user input during pagination
1510
+ * @returns true if the input was handled, false otherwise
1511
+ */
1512
+ handleInput(data: string): Promise<boolean>;
1513
+ /**
1514
+ * Check if a query should use pagination
1515
+ * @param sql The SQL query
1516
+ * @param rowCount The total row count
1517
+ * @param pageSize The configured page size (0 = disabled)
1518
+ * @returns Whether pagination should be enabled
1519
+ */
1520
+ static shouldPaginate(sql: string, rowCount: number, pageSize: number): boolean;
1521
+ /**
1522
+ * Strip trailing semicolon from SQL for pagination
1523
+ */
1524
+ static prepareQuery(sql: string): string;
1525
+ }
1526
+
1527
+ /**
1528
+ * State for pagination
1529
+ */
1530
+ export declare interface PaginationState {
1531
+ /** The original query being paginated */
1532
+ query: string | null;
1533
+ /** Current page index (0-based) */
1534
+ currentPage: number;
1535
+ /** Total number of rows in result */
1536
+ totalRows: number;
1537
+ /** Number of rows per page */
1538
+ pageSize: number;
1539
+ /** Whether pagination is active */
1540
+ isActive: boolean;
1541
+ }
1542
+
1543
+ /**
1544
+ * The result of executing a SQL query.
1545
+ *
1546
+ * @example
1547
+ * ```typescript
1548
+ * const result: QueryResult = {
1549
+ * columns: ['id', 'name', 'email'],
1550
+ * rows: [
1551
+ * [1, 'Alice', 'alice@example.com'],
1552
+ * [2, 'Bob', 'bob@example.com'],
1553
+ * ],
1554
+ * rowCount: 2,
1555
+ * duration: 5.23,
1556
+ * };
1557
+ * ```
1558
+ */
1559
+ declare interface QueryResult {
1560
+ /** Column names from the query result */
1561
+ columns: string[];
1562
+ /** Row data as a 2D array */
1563
+ rows: unknown[][];
1564
+ /** Total number of rows returned */
1565
+ rowCount: number;
1566
+ /** Query execution time in milliseconds */
1567
+ duration: number;
1568
+ }
1569
+
1570
+ /**
1571
+ * Read text from clipboard
1572
+ */
1573
+ export declare function readFromClipboard(): Promise<string | null>;
1574
+
1575
+ /**
1576
+ * VT100/ANSI escape code utilities
1577
+ */
1578
+ export declare const RESET = "\u001B[0m";
1579
+
1580
+ /**
1581
+ * Save theme preference
1582
+ */
1583
+ export declare function saveTheme(theme: 'dark' | 'light'): void;
1584
+
1585
+ declare interface TableOptions {
1586
+ maxWidth?: number;
1587
+ maxColumnWidth?: number;
1588
+ nullValue?: string;
1589
+ }
1590
+
1591
+ /**
1592
+ * An adapter that wraps the Ghostty terminal emulator for web use.
1593
+ *
1594
+ * This class provides a simplified interface for:
1595
+ * - Initializing the Ghostty WASM terminal
1596
+ * - Writing text and handling input
1597
+ * - Managing themes and dimensions
1598
+ * - Auto-fitting to container size
1599
+ *
1600
+ * The adapter handles all the low-level details of working with the Ghostty
1601
+ * terminal emulator, including WASM initialization, addon loading, and
1602
+ * event handling.
1603
+ *
1604
+ * @example Basic usage
1605
+ * ```typescript
1606
+ * const adapter = new TerminalAdapter();
1607
+ * await adapter.init(document.getElementById('container'), {
1608
+ * fontSize: 16,
1609
+ * theme: darkTheme,
1610
+ * });
1611
+ *
1612
+ * adapter.write('Hello, World!');
1613
+ * adapter.onData((input) => {
1614
+ * console.log('User typed:', input);
1615
+ * });
1616
+ * ```
1617
+ *
1618
+ * @example Theme switching
1619
+ * ```typescript
1620
+ * const adapter = new TerminalAdapter();
1621
+ * await adapter.init(container);
1622
+ *
1623
+ * adapter.setTheme(darkTheme);
1624
+ * // Later...
1625
+ * adapter.setTheme(lightTheme);
1626
+ * ```
1627
+ */
1628
+ export declare class TerminalAdapter {
1629
+ private terminal;
1630
+ private fitAddon;
1631
+ private ghostty;
1632
+ private dataHandler?;
1633
+ private resizeHandler?;
1634
+ private currentTheme;
1635
+ private initialized;
1636
+ private container;
1637
+ private options;
1638
+ private resizeObserver;
1639
+ private mobileInput;
1640
+ /**
1641
+ * Initializes the Ghostty terminal and mounts it to the container.
1642
+ *
1643
+ * This method:
1644
+ * 1. Initializes the Ghostty WASM module
1645
+ * 2. Creates the terminal with the specified options
1646
+ * 3. Loads the FitAddon for auto-resizing
1647
+ * 4. Mounts the terminal to the container
1648
+ * 5. Sets up resize observers
1649
+ *
1650
+ * @param container - The HTML element to mount the terminal into
1651
+ * @param options - Configuration options for the terminal
1652
+ * @returns A promise that resolves when initialization is complete
1653
+ *
1654
+ * @example
1655
+ * ```typescript
1656
+ * const adapter = new TerminalAdapter();
1657
+ * await adapter.init(document.getElementById('terminal'), {
1658
+ * fontSize: 14,
1659
+ * fontFamily: 'JetBrains Mono',
1660
+ * theme: darkTheme,
1661
+ * });
1662
+ * ```
1663
+ */
1664
+ init(container: HTMLElement, options?: TerminalOptions): Promise<void>;
1665
+ /* Excluded from this release type: createTerminal */
1666
+ /* Excluded from this release type: setupMobileInput */
1667
+ /* Excluded from this release type: setupMobileKeyboard */
1668
+ /* Excluded from this release type: setupTouchScrolling */
1669
+ /* Excluded from this release type: themeToGhostty */
1670
+ /* Excluded from this release type: handleResize */
1671
+ /**
1672
+ * Fits the terminal to its container dimensions.
1673
+ *
1674
+ * This method should be called when the container size changes.
1675
+ * It's automatically called on window resize, but you may need
1676
+ * to call it manually after dynamic layout changes.
1677
+ *
1678
+ * @example
1679
+ * ```typescript
1680
+ * // After changing container size
1681
+ * container.style.height = '500px';
1682
+ * adapter.fit();
1683
+ * ```
1684
+ */
1685
+ fit(): void;
1686
+ /**
1687
+ * Writes text to the terminal without a trailing newline.
1688
+ *
1689
+ * @param text - The text to write
1690
+ *
1691
+ * @example
1692
+ * ```typescript
1693
+ * adapter.write('Hello');
1694
+ * adapter.write(' World');
1695
+ * ```
1696
+ */
1697
+ write(text: string): void;
1698
+ /**
1699
+ * Writes text to the terminal followed by a newline.
1700
+ *
1701
+ * @param text - The text to write
1702
+ *
1703
+ * @example
1704
+ * ```typescript
1705
+ * adapter.writeln('First line');
1706
+ * adapter.writeln('Second line');
1707
+ * ```
1708
+ */
1709
+ writeln(text: string): void;
1710
+ /**
1711
+ * Clears the terminal screen and moves cursor to top-left.
1712
+ *
1713
+ * @example
1714
+ * ```typescript
1715
+ * adapter.clear();
1716
+ * adapter.writeln('Fresh start!');
1717
+ * ```
1718
+ */
1719
+ clear(): void;
1720
+ /**
1721
+ * Gives keyboard focus to the terminal.
1722
+ * On mobile devices, focuses the hidden input to trigger the virtual keyboard.
1723
+ *
1724
+ * @example
1725
+ * ```typescript
1726
+ * adapter.focus();
1727
+ * ```
1728
+ */
1729
+ focus(): void;
1730
+ /* Excluded from this release type: isTouchDevice */
1731
+ /**
1732
+ * Registers a callback to receive user input data.
1733
+ *
1734
+ * The callback is invoked whenever the user types in the terminal.
1735
+ * This includes regular characters, control sequences, and escape codes.
1736
+ *
1737
+ * @param handler - The callback function to handle input data
1738
+ *
1739
+ * @example
1740
+ * ```typescript
1741
+ * adapter.onData((data) => {
1742
+ * if (data === '\r') {
1743
+ * console.log('User pressed Enter');
1744
+ * } else {
1745
+ * console.log('User typed:', data);
1746
+ * }
1747
+ * });
1748
+ * ```
1749
+ */
1750
+ onData(handler: (data: string) => void): void;
1751
+ /**
1752
+ * Registers a callback to receive terminal resize events.
1753
+ *
1754
+ * @param handler - The callback function receiving new dimensions
1755
+ *
1756
+ * @example
1757
+ * ```typescript
1758
+ * adapter.onResize((cols, rows) => {
1759
+ * console.log(`Terminal resized to ${cols}x${rows}`);
1760
+ * });
1761
+ * ```
1762
+ */
1763
+ onResize(handler: (cols: number, rows: number) => void): void;
1764
+ /**
1765
+ * The number of columns (characters per line) in the terminal.
1766
+ *
1767
+ * @returns The current column count, or 80 if not initialized
1768
+ */
1769
+ get cols(): number;
1770
+ /**
1771
+ * The number of rows (lines) in the terminal.
1772
+ *
1773
+ * @returns The current row count, or 24 if not initialized
1774
+ */
1775
+ get rows(): number;
1776
+ /**
1777
+ * Sets the terminal color theme.
1778
+ *
1779
+ * Since Ghostty-web doesn't fully support runtime theme changes,
1780
+ * this method recreates the terminal with the new theme.
1781
+ *
1782
+ * @param theme - The theme to apply
1783
+ *
1784
+ * @example
1785
+ * ```typescript
1786
+ * adapter.setTheme({
1787
+ * name: 'dark',
1788
+ * colors: {
1789
+ * background: '#1e1e1e',
1790
+ * foreground: '#d4d4d4',
1791
+ * // ... other colors
1792
+ * },
1793
+ * });
1794
+ * ```
1795
+ */
1796
+ setTheme(theme: Theme): void;
1797
+ /**
1798
+ * Gets the current terminal theme.
1799
+ *
1800
+ * @returns The current theme, or null if no theme is set
1801
+ */
1802
+ getTheme(): Theme | null;
1803
+ /**
1804
+ * Disposes of the terminal and cleans up resources.
1805
+ *
1806
+ * After calling this method, the adapter cannot be used again.
1807
+ * Create a new instance if you need another terminal.
1808
+ *
1809
+ * @example
1810
+ * ```typescript
1811
+ * adapter.dispose();
1812
+ * // adapter is no longer usable
1813
+ * ```
1814
+ */
1815
+ dispose(): void;
1816
+ }
1817
+
1818
+ /**
1819
+ * Configuration options for creating a DuckDB terminal.
1820
+ *
1821
+ * @example Minimal configuration
1822
+ * ```typescript
1823
+ * const config: TerminalConfig = {
1824
+ * container: '#terminal',
1825
+ * };
1826
+ * ```
1827
+ *
1828
+ * @example Full configuration
1829
+ * ```typescript
1830
+ * const config: TerminalConfig = {
1831
+ * container: document.getElementById('terminal'),
1832
+ * fontFamily: 'JetBrains Mono',
1833
+ * fontSize: 16,
1834
+ * theme: 'dark',
1835
+ * storage: 'opfs',
1836
+ * databasePath: '/mydata.duckdb',
1837
+ * welcomeMessage: true,
1838
+ * prompt: 'SQL> ',
1839
+ * continuationPrompt: '... ',
1840
+ * linkDetection: true,
1841
+ * };
1842
+ * ```
1843
+ */
1844
+ export declare interface TerminalConfig {
1845
+ /**
1846
+ * The container element or CSS selector where the terminal will be mounted.
1847
+ * Can be an HTMLElement or a CSS selector string (e.g., '#terminal', '.container').
1848
+ */
1849
+ container: HTMLElement | string;
1850
+ /**
1851
+ * Font family for the terminal text.
1852
+ * @defaultValue '"Fira Code", "Cascadia Code", "JetBrains Mono", Consolas, monospace'
1853
+ */
1854
+ fontFamily?: string;
1855
+ /**
1856
+ * Font size in pixels.
1857
+ * @defaultValue 14
1858
+ */
1859
+ fontSize?: number;
1860
+ /**
1861
+ * The color theme for the terminal.
1862
+ * Can be 'dark', 'light', or a custom Theme object.
1863
+ * @defaultValue 'dark'
1864
+ */
1865
+ theme?: 'dark' | 'light' | Theme;
1866
+ /**
1867
+ * The storage backend for the database.
1868
+ * - 'memory': In-memory storage (data lost on page refresh)
1869
+ * - 'opfs': Origin Private File System (persistent storage)
1870
+ * @defaultValue 'memory'
1871
+ */
1872
+ storage?: 'memory' | 'opfs';
1873
+ /**
1874
+ * The database file path when using OPFS storage.
1875
+ * Only used when storage is 'opfs'.
1876
+ */
1877
+ databasePath?: string;
1878
+ /**
1879
+ * Whether to display the welcome message on startup.
1880
+ * @defaultValue true
1881
+ */
1882
+ welcomeMessage?: boolean;
1883
+ /**
1884
+ * The primary prompt string displayed before each command.
1885
+ * @defaultValue '🦆 '
1886
+ */
1887
+ prompt?: string;
1888
+ /**
1889
+ * The continuation prompt displayed for multi-line SQL statements.
1890
+ * @defaultValue ' > '
1891
+ */
1892
+ continuationPrompt?: string;
1893
+ /**
1894
+ * Whether to automatically detect and make URLs clickable in output.
1895
+ * @defaultValue true
1896
+ */
1897
+ linkDetection?: boolean;
1898
+ /**
1899
+ * Scrollback buffer size in bytes. Larger values allow more history but use more memory.
1900
+ * @defaultValue 10485760 (10MB)
1901
+ */
1902
+ scrollback?: number;
1903
+ }
1904
+
1905
+ /**
1906
+ * Type for event listener callbacks.
1907
+ *
1908
+ * @typeParam K - The event name from {@link TerminalEvents}
1909
+ *
1910
+ * @example
1911
+ * ```typescript
1912
+ * const listener: TerminalEventListener<'queryEnd'> = (event) => {
1913
+ * console.log(event.duration);
1914
+ * };
1915
+ * ```
1916
+ */
1917
+ export declare type TerminalEventListener<K extends keyof TerminalEvents> = (event: TerminalEvents[K]) => void;
1918
+
1919
+ /**
1920
+ * Event payload types for all terminal events.
1921
+ *
1922
+ * Use with {@link DuckDBTerminal.on} to subscribe to events.
1923
+ *
1924
+ * @example
1925
+ * ```typescript
1926
+ * terminal.on('queryEnd', (event: TerminalEvents['queryEnd']) => {
1927
+ * console.log(`Query took ${event.duration}ms`);
1928
+ * });
1929
+ * ```
1930
+ */
1931
+ export declare interface TerminalEvents {
1932
+ /**
1933
+ * Emitted when the terminal is fully initialized and ready for input.
1934
+ * The payload is an empty object.
1935
+ */
1936
+ ready: Record<string, never>;
1937
+ /**
1938
+ * Emitted when a SQL query starts executing.
1939
+ */
1940
+ queryStart: {
1941
+ /** The SQL statement being executed */
1942
+ sql: string;
1943
+ };
1944
+ /**
1945
+ * Emitted when a SQL query completes (success or failure).
1946
+ */
1947
+ queryEnd: {
1948
+ /** The SQL statement that was executed */
1949
+ sql: string;
1950
+ /** The query result, or null if the query failed */
1951
+ result: QueryResult | null;
1952
+ /** Error message if the query failed */
1953
+ error?: string;
1954
+ /** Execution time in milliseconds */
1955
+ duration: number;
1956
+ };
1957
+ /**
1958
+ * Emitted when a dot command is executed.
1959
+ */
1960
+ commandExecute: {
1961
+ /** The command name (e.g., '.help') */
1962
+ command: string;
1963
+ /** Command arguments */
1964
+ args: string[];
1965
+ };
1966
+ /**
1967
+ * Emitted when a file is loaded via drag-and-drop or file picker.
1968
+ */
1969
+ fileLoaded: {
1970
+ /** The filename */
1971
+ filename: string;
1972
+ /** File size in bytes */
1973
+ size: number;
1974
+ /** File extension/type */
1975
+ type: string;
1976
+ };
1977
+ /**
1978
+ * Emitted when the terminal theme changes.
1979
+ */
1980
+ themeChange: {
1981
+ /** The new theme */
1982
+ theme: Theme;
1983
+ /** The previous theme (null if this is the initial theme) */
1984
+ previous: Theme | null;
1985
+ };
1986
+ /**
1987
+ * Emitted when an error occurs.
1988
+ */
1989
+ error: {
1990
+ /** The error message */
1991
+ message: string;
1992
+ /** Where the error originated (e.g., 'query', 'command') */
1993
+ source: string;
1994
+ };
1995
+ /**
1996
+ * Emitted when the terminal state changes.
1997
+ */
1998
+ stateChange: {
1999
+ /** The new state */
2000
+ state: TerminalState;
2001
+ /** The previous state */
2002
+ previous: TerminalState;
2003
+ };
2004
+ }
2005
+
2006
+ /**
2007
+ * Interface for interacting with the terminal from commands.
2008
+ *
2009
+ * This interface is passed to command handlers and provides methods
2010
+ * for writing output and executing SQL.
2011
+ */
2012
+ export declare interface TerminalInterface {
2013
+ /**
2014
+ * Writes text to the terminal without a newline.
2015
+ * @param text - The text to write
2016
+ */
2017
+ write(text: string): void;
2018
+ /**
2019
+ * Writes text to the terminal followed by a newline.
2020
+ * @param text - The text to write
2021
+ */
2022
+ writeln(text: string): void;
2023
+ /**
2024
+ * Clears the terminal screen.
2025
+ */
2026
+ clear(): void;
2027
+ /**
2028
+ * Executes a SQL query and returns the result.
2029
+ * @param sql - The SQL statement to execute
2030
+ * @returns The query result, or null if an error occurred
2031
+ */
2032
+ executeSQL(sql: string): Promise<QueryResult | null>;
2033
+ /**
2034
+ * Sets the terminal theme.
2035
+ * @param theme - The theme to apply ('dark' or 'light')
2036
+ */
2037
+ setTheme(theme: 'dark' | 'light'): void;
2038
+ /**
2039
+ * Gets the current theme mode.
2040
+ * @returns The current theme mode
2041
+ */
2042
+ getTheme(): 'dark' | 'light';
2043
+ }
2044
+
2045
+ /**
2046
+ * Configuration options for the terminal adapter.
2047
+ */
2048
+ declare interface TerminalOptions {
2049
+ /**
2050
+ * Font family for the terminal text.
2051
+ * Defaults to a stack of monospace fonts.
2052
+ */
2053
+ fontFamily?: string;
2054
+ /**
2055
+ * Font size in pixels.
2056
+ * @defaultValue 14
2057
+ */
2058
+ fontSize?: number;
2059
+ /**
2060
+ * The color theme to apply to the terminal.
2061
+ */
2062
+ theme?: Theme;
2063
+ /**
2064
+ * Scrollback buffer size in bytes.
2065
+ * @defaultValue 10485760 (10MB)
2066
+ */
2067
+ scrollback?: number;
2068
+ }
2069
+
2070
+ /**
2071
+ * The current state of the terminal.
2072
+ *
2073
+ * - `idle`: Waiting for user input
2074
+ * - `collecting`: Collecting multi-line SQL input
2075
+ * - `executing`: Running a query
2076
+ * - `paginating`: Displaying paginated results
2077
+ */
2078
+ declare type TerminalState = 'idle' | 'collecting' | 'executing' | 'paginating';
2079
+
2080
+ /**
2081
+ * A complete terminal theme definition.
2082
+ *
2083
+ * @example
2084
+ * ```typescript
2085
+ * const myTheme: Theme = {
2086
+ * name: 'my-dark-theme',
2087
+ * colors: {
2088
+ * background: '#1a1b26',
2089
+ * foreground: '#a9b1d6',
2090
+ * // ... other colors
2091
+ * },
2092
+ * };
2093
+ * ```
2094
+ */
2095
+ export declare interface Theme {
2096
+ /** Unique name for the theme */
2097
+ name: string;
2098
+ /** Color definitions for the theme */
2099
+ colors: ThemeColors;
2100
+ }
2101
+
2102
+ /**
2103
+ * Color definitions for a terminal theme.
2104
+ *
2105
+ * Includes the standard 16 ANSI colors plus special terminal colors
2106
+ * (background, foreground, cursor, selection).
2107
+ *
2108
+ * @example
2109
+ * ```typescript
2110
+ * const colors: ThemeColors = {
2111
+ * background: '#1e1e1e',
2112
+ * foreground: '#d4d4d4',
2113
+ * cursor: '#aeafad',
2114
+ * selection: '#264f78',
2115
+ * black: '#000000',
2116
+ * red: '#cd3131',
2117
+ * green: '#0dbc79',
2118
+ * yellow: '#e5e510',
2119
+ * blue: '#2472c8',
2120
+ * magenta: '#bc3fbc',
2121
+ * cyan: '#11a8cd',
2122
+ * white: '#e5e5e5',
2123
+ * brightBlack: '#666666',
2124
+ * brightRed: '#f14c4c',
2125
+ * brightGreen: '#23d18b',
2126
+ * brightYellow: '#f5f543',
2127
+ * brightBlue: '#3b8eea',
2128
+ * brightMagenta: '#d670d6',
2129
+ * brightCyan: '#29b8db',
2130
+ * brightWhite: '#e5e5e5',
2131
+ * };
2132
+ * ```
2133
+ */
2134
+ export declare interface ThemeColors {
2135
+ /** Terminal background color */
2136
+ background: string;
2137
+ /** Default text (foreground) color */
2138
+ foreground: string;
2139
+ /** Cursor color */
2140
+ cursor: string;
2141
+ /** Text selection highlight color */
2142
+ selection: string;
2143
+ /** ANSI black (color 0) */
2144
+ black: string;
2145
+ /** ANSI red (color 1) */
2146
+ red: string;
2147
+ /** ANSI green (color 2) */
2148
+ green: string;
2149
+ /** ANSI yellow (color 3) */
2150
+ yellow: string;
2151
+ /** ANSI blue (color 4) */
2152
+ blue: string;
2153
+ /** ANSI magenta (color 5) */
2154
+ magenta: string;
2155
+ /** ANSI cyan (color 6) */
2156
+ cyan: string;
2157
+ /** ANSI white (color 7) */
2158
+ white: string;
2159
+ /** ANSI bright black (color 8) */
2160
+ brightBlack: string;
2161
+ /** ANSI bright red (color 9) */
2162
+ brightRed: string;
2163
+ /** ANSI bright green (color 10) */
2164
+ brightGreen: string;
2165
+ /** ANSI bright yellow (color 11) */
2166
+ brightYellow: string;
2167
+ /** ANSI bright blue (color 12) */
2168
+ brightBlue: string;
2169
+ /** ANSI bright magenta (color 13) */
2170
+ brightMagenta: string;
2171
+ /** ANSI bright cyan (color 14) */
2172
+ brightCyan: string;
2173
+ /** ANSI bright white (color 15) */
2174
+ brightWhite: string;
2175
+ }
2176
+
2177
+ declare interface Token {
2178
+ type: TokenType;
2179
+ value: string;
2180
+ start: number;
2181
+ end: number;
2182
+ }
2183
+
2184
+ /**
2185
+ * Tokenize SQL string
2186
+ */
2187
+ export declare function tokenize(sql: string): Token[];
2188
+
2189
+ /**
2190
+ * SQL Syntax Highlighting
2191
+ */
2192
+ declare type TokenType = 'keyword' | 'type' | 'function' | 'string' | 'number' | 'comment' | 'operator' | 'identifier' | 'whitespace';
2193
+
2194
+ export { }