ink-sdl 0.2.0 → 0.3.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/README.md +58 -27
- package/dist/chunk-BOQYTA3S.js +2822 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +437 -0
- package/dist/index.d.ts +412 -245
- package/dist/index.js +25 -2269
- package/package.json +6 -2
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ interface SdlKeyEvent {
|
|
|
18
18
|
/**
|
|
19
19
|
* SDL2 FFI Bindings
|
|
20
20
|
*
|
|
21
|
-
* Provides minimal SDL2
|
|
21
|
+
* Provides minimal SDL2 bindings for window-based rendering
|
|
22
22
|
* using koffi for foreign function interface.
|
|
23
23
|
*/
|
|
24
24
|
|
|
@@ -27,7 +27,7 @@ interface SdlKeyEvent {
|
|
|
27
27
|
*
|
|
28
28
|
* Provides type-safe access to SDL2 functions for window rendering.
|
|
29
29
|
*/
|
|
30
|
-
declare class
|
|
30
|
+
declare class Sdl2 {
|
|
31
31
|
private lib;
|
|
32
32
|
private initialized;
|
|
33
33
|
private _SDL_Init;
|
|
@@ -38,6 +38,8 @@ declare class SDL2API {
|
|
|
38
38
|
private _SDL_SetWindowTitle;
|
|
39
39
|
private _SDL_GetWindowSize;
|
|
40
40
|
private _SDL_RaiseWindow;
|
|
41
|
+
private _SDL_SetWindowMinimumSize;
|
|
42
|
+
private _SDL_SetWindowMaximumSize;
|
|
41
43
|
private _SDL_CreateRenderer;
|
|
42
44
|
private _SDL_DestroyRenderer;
|
|
43
45
|
private _SDL_RenderClear;
|
|
@@ -93,6 +95,14 @@ declare class SDL2API {
|
|
|
93
95
|
* Raise window to front and give it keyboard focus
|
|
94
96
|
*/
|
|
95
97
|
raiseWindow(window: SDLPointer): void;
|
|
98
|
+
/**
|
|
99
|
+
* Set the minimum size of a window
|
|
100
|
+
*/
|
|
101
|
+
setWindowMinimumSize(window: SDLPointer, minW: number, minH: number): void;
|
|
102
|
+
/**
|
|
103
|
+
* Set the maximum size of a window
|
|
104
|
+
*/
|
|
105
|
+
setWindowMaximumSize(window: SDLPointer, maxW: number, maxH: number): void;
|
|
96
106
|
/**
|
|
97
107
|
* Create a renderer for a window
|
|
98
108
|
*/
|
|
@@ -193,253 +203,15 @@ declare class SDL2API {
|
|
|
193
203
|
/**
|
|
194
204
|
* Get the SDL2 API singleton
|
|
195
205
|
*/
|
|
196
|
-
declare const
|
|
206
|
+
declare const getSdl2: () => Sdl2;
|
|
197
207
|
/**
|
|
198
208
|
* Check if SDL2 is available without throwing
|
|
199
209
|
*/
|
|
200
|
-
declare const
|
|
210
|
+
declare const isSdl2Available: () => boolean;
|
|
201
211
|
/**
|
|
202
212
|
* Create an SDL_Rect buffer for use with SDL functions
|
|
203
213
|
*/
|
|
204
214
|
declare const createSDLRect: (x: number, y: number, w: number, h: number) => Buffer;
|
|
205
|
-
/**
|
|
206
|
-
* SDL_ttf API wrapper class for TrueType font rendering
|
|
207
|
-
*/
|
|
208
|
-
declare class SDL_ttfAPI {
|
|
209
|
-
private lib;
|
|
210
|
-
private initialized;
|
|
211
|
-
private _TTF_Init;
|
|
212
|
-
private _TTF_Quit;
|
|
213
|
-
private _TTF_OpenFont;
|
|
214
|
-
private _TTF_CloseFont;
|
|
215
|
-
private _TTF_RenderUTF8_Blended;
|
|
216
|
-
private _TTF_SizeUTF8;
|
|
217
|
-
constructor();
|
|
218
|
-
private bindFunctions;
|
|
219
|
-
/**
|
|
220
|
-
* Initialize SDL_ttf
|
|
221
|
-
*/
|
|
222
|
-
init(): boolean;
|
|
223
|
-
/**
|
|
224
|
-
* Shutdown SDL_ttf
|
|
225
|
-
*/
|
|
226
|
-
quit(): void;
|
|
227
|
-
/**
|
|
228
|
-
* Get the last SDL_ttf error message
|
|
229
|
-
*/
|
|
230
|
-
getError(): string;
|
|
231
|
-
/**
|
|
232
|
-
* Open a TrueType font file
|
|
233
|
-
*/
|
|
234
|
-
openFont(file: string, ptsize: number): SDLPointer;
|
|
235
|
-
/**
|
|
236
|
-
* Close a font
|
|
237
|
-
*/
|
|
238
|
-
closeFont(font: SDLPointer): void;
|
|
239
|
-
/**
|
|
240
|
-
* Render UTF-8 text to a surface with blended (anti-aliased) rendering
|
|
241
|
-
*/
|
|
242
|
-
renderTextBlended(font: SDLPointer, text: string, r: number, g: number, b: number, a?: number): SDLPointer;
|
|
243
|
-
/**
|
|
244
|
-
* Get the dimensions of rendered text without actually rendering
|
|
245
|
-
*/
|
|
246
|
-
sizeText(font: SDLPointer, text: string): {
|
|
247
|
-
width: number;
|
|
248
|
-
height: number;
|
|
249
|
-
};
|
|
250
|
-
/**
|
|
251
|
-
* Check if SDL_ttf is initialized
|
|
252
|
-
*/
|
|
253
|
-
isInitialized(): boolean;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Get the SDL_ttf API singleton
|
|
257
|
-
*/
|
|
258
|
-
declare const getSDL_ttf: () => SDL_ttfAPI;
|
|
259
|
-
/**
|
|
260
|
-
* Check if SDL_ttf is available without throwing
|
|
261
|
-
*/
|
|
262
|
-
declare const isSDL_ttfAvailable: () => boolean;
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* ANSI Parser for SDL UI Rendering
|
|
266
|
-
*
|
|
267
|
-
* Parses terminal ANSI escape sequences and converts them to draw commands
|
|
268
|
-
* for rendering in an SDL window.
|
|
269
|
-
*/
|
|
270
|
-
/** RGB color value */
|
|
271
|
-
interface Color {
|
|
272
|
-
r: number;
|
|
273
|
-
g: number;
|
|
274
|
-
b: number;
|
|
275
|
-
}
|
|
276
|
-
/** Types of draw commands */
|
|
277
|
-
type DrawCommandType = "text" | "clear_screen" | "clear_line" | "cursor_move" | "set_fg" | "set_bg" | "reset_style" | "set_bold" | "set_dim" | "set_reverse";
|
|
278
|
-
/** A single draw command from parsed ANSI output */
|
|
279
|
-
interface DrawCommand {
|
|
280
|
-
type: DrawCommandType;
|
|
281
|
-
text?: string;
|
|
282
|
-
row?: number;
|
|
283
|
-
col?: number;
|
|
284
|
-
color?: Color;
|
|
285
|
-
enabled?: boolean;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* ANSI sequence parser
|
|
289
|
-
*
|
|
290
|
-
* Parses ANSI escape sequences from terminal output and produces
|
|
291
|
-
* draw commands for SDL rendering.
|
|
292
|
-
*/
|
|
293
|
-
declare class AnsiParser {
|
|
294
|
-
private cursorRow;
|
|
295
|
-
private cursorCol;
|
|
296
|
-
private fgColor;
|
|
297
|
-
private bgColor;
|
|
298
|
-
private bold;
|
|
299
|
-
/**
|
|
300
|
-
* Parse an ANSI string and return draw commands
|
|
301
|
-
*/
|
|
302
|
-
parse(input: string): DrawCommand[];
|
|
303
|
-
/**
|
|
304
|
-
* Process an escape sequence and emit draw commands
|
|
305
|
-
*/
|
|
306
|
-
private processEscapeSequence;
|
|
307
|
-
/**
|
|
308
|
-
* Process cursor position sequence
|
|
309
|
-
*/
|
|
310
|
-
private processCursorPosition;
|
|
311
|
-
/**
|
|
312
|
-
* Process erase display sequence
|
|
313
|
-
*/
|
|
314
|
-
private processEraseDisplay;
|
|
315
|
-
/**
|
|
316
|
-
* Process erase line sequence
|
|
317
|
-
*/
|
|
318
|
-
private processEraseLine;
|
|
319
|
-
/**
|
|
320
|
-
* Process SGR (Select Graphic Rendition) sequence
|
|
321
|
-
*/
|
|
322
|
-
private processSGR;
|
|
323
|
-
/**
|
|
324
|
-
* Parse extended color (256-color or 24-bit)
|
|
325
|
-
*/
|
|
326
|
-
private parseExtendedColor;
|
|
327
|
-
/**
|
|
328
|
-
* Reset all styles to default
|
|
329
|
-
*/
|
|
330
|
-
private resetStyle;
|
|
331
|
-
/**
|
|
332
|
-
* Get current cursor position
|
|
333
|
-
*/
|
|
334
|
-
getCursor(): {
|
|
335
|
-
row: number;
|
|
336
|
-
col: number;
|
|
337
|
-
};
|
|
338
|
-
/**
|
|
339
|
-
* Get current foreground color
|
|
340
|
-
*/
|
|
341
|
-
getFgColor(): Color;
|
|
342
|
-
/**
|
|
343
|
-
* Get current background color
|
|
344
|
-
*/
|
|
345
|
-
getBgColor(): Color;
|
|
346
|
-
/**
|
|
347
|
-
* Reset parser state
|
|
348
|
-
*/
|
|
349
|
-
reset(): void;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* SDL Text Renderer
|
|
354
|
-
*
|
|
355
|
-
* Handles TrueType font loading and text rendering with glyph caching
|
|
356
|
-
* for efficient SDL UI rendering.
|
|
357
|
-
*/
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* SDL Text Renderer
|
|
361
|
-
*
|
|
362
|
-
* Loads TTF fonts and renders text with glyph caching for performance.
|
|
363
|
-
* Supports HiDPI displays by scaling font size based on scale factor.
|
|
364
|
-
*/
|
|
365
|
-
declare class TextRenderer {
|
|
366
|
-
private sdl;
|
|
367
|
-
private ttf;
|
|
368
|
-
private font;
|
|
369
|
-
private renderer;
|
|
370
|
-
private baseFontSize;
|
|
371
|
-
private scaleFactor;
|
|
372
|
-
private glyphCache;
|
|
373
|
-
private accessCounter;
|
|
374
|
-
private charWidth;
|
|
375
|
-
private charHeight;
|
|
376
|
-
constructor(renderer: SDLPointer, options?: {
|
|
377
|
-
fontSize?: number;
|
|
378
|
-
scaleFactor?: number;
|
|
379
|
-
fontPath?: string;
|
|
380
|
-
});
|
|
381
|
-
/**
|
|
382
|
-
* Get the path to the bundled Cozette font
|
|
383
|
-
*/
|
|
384
|
-
private getDefaultFontPath;
|
|
385
|
-
/**
|
|
386
|
-
* Load a TTF font at the current scaled size
|
|
387
|
-
*/
|
|
388
|
-
private loadFont;
|
|
389
|
-
/**
|
|
390
|
-
* Update scale factor (for HiDPI display changes)
|
|
391
|
-
*/
|
|
392
|
-
updateScaleFactor(scaleFactor: number): void;
|
|
393
|
-
/**
|
|
394
|
-
* Get character dimensions
|
|
395
|
-
*/
|
|
396
|
-
getCharDimensions(): {
|
|
397
|
-
width: number;
|
|
398
|
-
height: number;
|
|
399
|
-
};
|
|
400
|
-
/**
|
|
401
|
-
* Generate cache key for a glyph
|
|
402
|
-
*/
|
|
403
|
-
private getCacheKey;
|
|
404
|
-
/**
|
|
405
|
-
* Get or create a cached glyph texture
|
|
406
|
-
*/
|
|
407
|
-
private getGlyph;
|
|
408
|
-
/**
|
|
409
|
-
* Evict least recently used glyphs
|
|
410
|
-
*/
|
|
411
|
-
private evictOldGlyphs;
|
|
412
|
-
/**
|
|
413
|
-
* Render a single character at the specified position
|
|
414
|
-
*/
|
|
415
|
-
renderChar(char: string, x: number, y: number, color: Color): void;
|
|
416
|
-
/**
|
|
417
|
-
* Render a string of text at the specified position
|
|
418
|
-
*/
|
|
419
|
-
renderText(text: string, x: number, y: number, color: Color): void;
|
|
420
|
-
/**
|
|
421
|
-
* Get text dimensions
|
|
422
|
-
*/
|
|
423
|
-
measureText(text: string): {
|
|
424
|
-
width: number;
|
|
425
|
-
height: number;
|
|
426
|
-
};
|
|
427
|
-
/**
|
|
428
|
-
* Clear the glyph cache
|
|
429
|
-
*/
|
|
430
|
-
clearCache(): void;
|
|
431
|
-
/**
|
|
432
|
-
* Get cache statistics
|
|
433
|
-
*/
|
|
434
|
-
getCacheStats(): {
|
|
435
|
-
size: number;
|
|
436
|
-
maxSize: number;
|
|
437
|
-
};
|
|
438
|
-
/**
|
|
439
|
-
* Clean up resources
|
|
440
|
-
*/
|
|
441
|
-
destroy(): void;
|
|
442
|
-
}
|
|
443
215
|
|
|
444
216
|
/**
|
|
445
217
|
* SDL UI Renderer
|
|
@@ -455,6 +227,31 @@ interface SdlUiRendererOptions {
|
|
|
455
227
|
vsync?: boolean;
|
|
456
228
|
fontSize?: number;
|
|
457
229
|
scaleFactor?: number | null;
|
|
230
|
+
/** Use system font instead of bundled Cozette font */
|
|
231
|
+
systemFont?: boolean;
|
|
232
|
+
/** Path to a custom TTF font file */
|
|
233
|
+
fontPath?: string;
|
|
234
|
+
/** Font name to search for in system font directories */
|
|
235
|
+
fontName?: string;
|
|
236
|
+
/** Background color as RGB tuple [r, g, b] or hex string "#RRGGBB" */
|
|
237
|
+
backgroundColor?: [number, number, number] | string | undefined;
|
|
238
|
+
/** Fullscreen mode: true for exclusive fullscreen, "desktop" for borderless fullscreen */
|
|
239
|
+
fullscreen?: boolean | "desktop" | undefined;
|
|
240
|
+
/** Remove window decorations (title bar, borders) */
|
|
241
|
+
borderless?: boolean | undefined;
|
|
242
|
+
/** Minimum window width in pixels */
|
|
243
|
+
minWidth?: number | undefined;
|
|
244
|
+
/** Minimum window height in pixels */
|
|
245
|
+
minHeight?: number | undefined;
|
|
246
|
+
}
|
|
247
|
+
/** Result from processing SDL events */
|
|
248
|
+
interface ProcessEventsResult {
|
|
249
|
+
/** Key events that occurred */
|
|
250
|
+
keyEvents: SdlKeyEvent[];
|
|
251
|
+
/** Whether a resize event occurred */
|
|
252
|
+
resized: boolean;
|
|
253
|
+
/** Whether focus was lost (modifier keys should be reset) */
|
|
254
|
+
focusLost: boolean;
|
|
458
255
|
}
|
|
459
256
|
/**
|
|
460
257
|
* SDL UI Renderer
|
|
@@ -467,6 +264,7 @@ declare class SdlUiRenderer {
|
|
|
467
264
|
private window;
|
|
468
265
|
private renderer;
|
|
469
266
|
private textRenderer;
|
|
267
|
+
private renderTarget;
|
|
470
268
|
private ansiParser;
|
|
471
269
|
private inputBridge;
|
|
472
270
|
private windowWidth;
|
|
@@ -477,8 +275,12 @@ declare class SdlUiRenderer {
|
|
|
477
275
|
private charHeight;
|
|
478
276
|
private fgColor;
|
|
479
277
|
private bgColor;
|
|
278
|
+
private defaultBgColor;
|
|
480
279
|
private bold;
|
|
481
280
|
private dim;
|
|
281
|
+
private italic;
|
|
282
|
+
private underline;
|
|
283
|
+
private strikethrough;
|
|
482
284
|
private reverse;
|
|
483
285
|
private shouldQuit;
|
|
484
286
|
private pendingCommands;
|
|
@@ -500,6 +302,10 @@ declare class SdlUiRenderer {
|
|
|
500
302
|
columns: number;
|
|
501
303
|
rows: number;
|
|
502
304
|
};
|
|
305
|
+
/**
|
|
306
|
+
* Create or recreate the render target texture
|
|
307
|
+
*/
|
|
308
|
+
private createRenderTarget;
|
|
503
309
|
/**
|
|
504
310
|
* Process ANSI output from Ink
|
|
505
311
|
*/
|
|
@@ -508,6 +314,14 @@ declare class SdlUiRenderer {
|
|
|
508
314
|
* Render pending commands and present
|
|
509
315
|
*/
|
|
510
316
|
present(): void;
|
|
317
|
+
/**
|
|
318
|
+
* Refresh the display by copying the render target to the screen
|
|
319
|
+
*
|
|
320
|
+
* Call this periodically to keep the display updated even when no new
|
|
321
|
+
* content is being rendered. Required for SDL's double-buffering to work
|
|
322
|
+
* correctly - without continuous presents, the window can go black.
|
|
323
|
+
*/
|
|
324
|
+
refreshDisplay(): void;
|
|
511
325
|
/**
|
|
512
326
|
* Execute a single draw command
|
|
513
327
|
*/
|
|
@@ -527,7 +341,7 @@ declare class SdlUiRenderer {
|
|
|
527
341
|
/**
|
|
528
342
|
* Process SDL events
|
|
529
343
|
*/
|
|
530
|
-
processEvents():
|
|
344
|
+
processEvents(): ProcessEventsResult;
|
|
531
345
|
/**
|
|
532
346
|
* Convert SDL key event to terminal sequence
|
|
533
347
|
*/
|
|
@@ -571,6 +385,21 @@ declare class SdlUiRenderer {
|
|
|
571
385
|
* Reset state for reuse
|
|
572
386
|
*/
|
|
573
387
|
reset(): void;
|
|
388
|
+
/**
|
|
389
|
+
* Reset input state (modifier keys)
|
|
390
|
+
*
|
|
391
|
+
* Call this when focus is lost to prevent "stuck" modifier keys.
|
|
392
|
+
*/
|
|
393
|
+
resetInputState(): void;
|
|
394
|
+
/**
|
|
395
|
+
* Get glyph cache statistics
|
|
396
|
+
*
|
|
397
|
+
* Useful for profiling and tuning cache size.
|
|
398
|
+
*/
|
|
399
|
+
getCacheStats(): {
|
|
400
|
+
size: number;
|
|
401
|
+
maxSize: number;
|
|
402
|
+
} | null;
|
|
574
403
|
}
|
|
575
404
|
|
|
576
405
|
/**
|
|
@@ -683,7 +512,7 @@ declare class SdlInputStream extends Readable {
|
|
|
683
512
|
}
|
|
684
513
|
|
|
685
514
|
/**
|
|
686
|
-
* SDL Streams for Ink
|
|
515
|
+
* SDL Window and Streams for Ink
|
|
687
516
|
*
|
|
688
517
|
* Factory function to create stdin/stdout streams that render to SDL.
|
|
689
518
|
*/
|
|
@@ -704,6 +533,22 @@ interface SdlStreamsOptions {
|
|
|
704
533
|
fontSize?: number;
|
|
705
534
|
/** Override scale factor (null = auto-detect) */
|
|
706
535
|
scaleFactor?: number | null;
|
|
536
|
+
/** Use system font instead of bundled Cozette font */
|
|
537
|
+
systemFont?: boolean;
|
|
538
|
+
/** Path to a custom TTF font file */
|
|
539
|
+
fontPath?: string;
|
|
540
|
+
/** Font name to search for in system font directories */
|
|
541
|
+
fontName?: string;
|
|
542
|
+
/** Background color as RGB tuple [r, g, b] or hex string "#RRGGBB" */
|
|
543
|
+
backgroundColor?: [number, number, number] | string | undefined;
|
|
544
|
+
/** Fullscreen mode: true for exclusive fullscreen, "desktop" for borderless fullscreen */
|
|
545
|
+
fullscreen?: boolean | "desktop" | undefined;
|
|
546
|
+
/** Remove window decorations (title bar, borders) */
|
|
547
|
+
borderless?: boolean | undefined;
|
|
548
|
+
/** Minimum window width in pixels */
|
|
549
|
+
minWidth?: number | undefined;
|
|
550
|
+
/** Minimum window height in pixels */
|
|
551
|
+
minHeight?: number | undefined;
|
|
707
552
|
}
|
|
708
553
|
/**
|
|
709
554
|
* SDL Window wrapper that emits events
|
|
@@ -746,6 +591,23 @@ declare class SdlWindow extends EventEmitter {
|
|
|
746
591
|
* Get the output stream
|
|
747
592
|
*/
|
|
748
593
|
getOutputStream(): SdlOutputStream;
|
|
594
|
+
/**
|
|
595
|
+
* Get glyph cache statistics
|
|
596
|
+
*
|
|
597
|
+
* Useful for profiling and tuning cache performance.
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```typescript
|
|
601
|
+
* const stats = window.getCacheStats();
|
|
602
|
+
* if (stats) {
|
|
603
|
+
* console.log(`Cache: ${stats.size}/${stats.maxSize} glyphs`);
|
|
604
|
+
* }
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
getCacheStats(): {
|
|
608
|
+
size: number;
|
|
609
|
+
maxSize: number;
|
|
610
|
+
} | null;
|
|
749
611
|
}
|
|
750
612
|
/**
|
|
751
613
|
* Result of createSdlStreams
|
|
@@ -757,6 +619,8 @@ interface SdlStreams {
|
|
|
757
619
|
stdout: SdlOutputStream;
|
|
758
620
|
/** SDL window wrapper with events */
|
|
759
621
|
window: SdlWindow;
|
|
622
|
+
/** UI renderer (for advanced use) */
|
|
623
|
+
renderer: SdlUiRenderer;
|
|
760
624
|
}
|
|
761
625
|
/**
|
|
762
626
|
* Create SDL streams for use with Ink
|
|
@@ -785,6 +649,309 @@ interface SdlStreams {
|
|
|
785
649
|
*/
|
|
786
650
|
declare const createSdlStreams: (options?: SdlStreamsOptions) => SdlStreams;
|
|
787
651
|
|
|
652
|
+
/**
|
|
653
|
+
* SDL2_ttf FFI Bindings
|
|
654
|
+
*
|
|
655
|
+
* Provides SDL2_ttf bindings for TrueType font rendering
|
|
656
|
+
* using koffi for foreign function interface.
|
|
657
|
+
*/
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* SDL_ttf API wrapper class for TrueType font rendering
|
|
661
|
+
*/
|
|
662
|
+
declare class SdlTtf {
|
|
663
|
+
private lib;
|
|
664
|
+
private initialized;
|
|
665
|
+
private _TTF_Init;
|
|
666
|
+
private _TTF_Quit;
|
|
667
|
+
private _TTF_OpenFont;
|
|
668
|
+
private _TTF_CloseFont;
|
|
669
|
+
private _TTF_RenderUTF8_Blended;
|
|
670
|
+
private _TTF_SizeUTF8;
|
|
671
|
+
private _TTF_SetFontStyle;
|
|
672
|
+
private _TTF_GetFontStyle;
|
|
673
|
+
private _TTF_GlyphIsProvided32;
|
|
674
|
+
constructor();
|
|
675
|
+
private bindFunctions;
|
|
676
|
+
/**
|
|
677
|
+
* Initialize SDL_ttf
|
|
678
|
+
*/
|
|
679
|
+
init(): boolean;
|
|
680
|
+
/**
|
|
681
|
+
* Shutdown SDL_ttf
|
|
682
|
+
*/
|
|
683
|
+
quit(): void;
|
|
684
|
+
/**
|
|
685
|
+
* Get the last SDL_ttf error message
|
|
686
|
+
*/
|
|
687
|
+
getError(): string;
|
|
688
|
+
/**
|
|
689
|
+
* Open a TrueType font file
|
|
690
|
+
*/
|
|
691
|
+
openFont(file: string, ptsize: number): SDLPointer;
|
|
692
|
+
/**
|
|
693
|
+
* Close a font
|
|
694
|
+
*/
|
|
695
|
+
closeFont(font: SDLPointer): void;
|
|
696
|
+
/**
|
|
697
|
+
* Render UTF-8 text to a surface with blended (anti-aliased) rendering
|
|
698
|
+
*/
|
|
699
|
+
renderTextBlended(font: SDLPointer, text: string, r: number, g: number, b: number, a?: number): SDLPointer;
|
|
700
|
+
/**
|
|
701
|
+
* Get the dimensions of rendered text without actually rendering
|
|
702
|
+
*/
|
|
703
|
+
sizeText(font: SDLPointer, text: string): {
|
|
704
|
+
width: number;
|
|
705
|
+
height: number;
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
708
|
+
* Check if SDL_ttf is initialized
|
|
709
|
+
*/
|
|
710
|
+
isInitialized(): boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Set font style (bold, italic, underline, strikethrough)
|
|
713
|
+
*/
|
|
714
|
+
setFontStyle(font: SDLPointer, style: number): void;
|
|
715
|
+
/**
|
|
716
|
+
* Get current font style
|
|
717
|
+
*/
|
|
718
|
+
getFontStyle(font: SDLPointer): number;
|
|
719
|
+
/**
|
|
720
|
+
* Check if a font provides a glyph for the given Unicode codepoint
|
|
721
|
+
*/
|
|
722
|
+
glyphIsProvided(font: SDLPointer, codepoint: number): boolean;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Get the SDL_ttf API singleton
|
|
726
|
+
*/
|
|
727
|
+
declare const getSdlTtf: () => SdlTtf;
|
|
728
|
+
/**
|
|
729
|
+
* Check if SDL_ttf is available without throwing
|
|
730
|
+
*/
|
|
731
|
+
declare const isSdlTtfAvailable: () => boolean;
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* ANSI Parser for SDL UI Rendering
|
|
735
|
+
*
|
|
736
|
+
* Parses terminal ANSI escape sequences and converts them to draw commands
|
|
737
|
+
* for rendering in an SDL window.
|
|
738
|
+
*/
|
|
739
|
+
/** RGB color value */
|
|
740
|
+
interface Color {
|
|
741
|
+
r: number;
|
|
742
|
+
g: number;
|
|
743
|
+
b: number;
|
|
744
|
+
}
|
|
745
|
+
/** Types of draw commands */
|
|
746
|
+
type DrawCommandType = "text" | "clear_screen" | "clear_line" | "cursor_move" | "set_fg" | "set_bg" | "reset_style" | "set_bold" | "set_dim" | "set_italic" | "set_underline" | "set_strikethrough" | "set_reverse";
|
|
747
|
+
/** A single draw command from parsed ANSI output */
|
|
748
|
+
interface DrawCommand {
|
|
749
|
+
type: DrawCommandType;
|
|
750
|
+
text?: string;
|
|
751
|
+
row?: number;
|
|
752
|
+
col?: number;
|
|
753
|
+
color?: Color;
|
|
754
|
+
enabled?: boolean;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* ANSI sequence parser
|
|
758
|
+
*
|
|
759
|
+
* Parses ANSI escape sequences from terminal output and produces
|
|
760
|
+
* draw commands for SDL rendering.
|
|
761
|
+
*/
|
|
762
|
+
declare class AnsiParser {
|
|
763
|
+
private cursorRow;
|
|
764
|
+
private cursorCol;
|
|
765
|
+
private fgColor;
|
|
766
|
+
private bgColor;
|
|
767
|
+
private bold;
|
|
768
|
+
/**
|
|
769
|
+
* Parse an ANSI string and return draw commands
|
|
770
|
+
*/
|
|
771
|
+
parse(input: string): DrawCommand[];
|
|
772
|
+
/**
|
|
773
|
+
* Process an escape sequence and emit draw commands
|
|
774
|
+
*/
|
|
775
|
+
private processEscapeSequence;
|
|
776
|
+
/**
|
|
777
|
+
* Process cursor position sequence
|
|
778
|
+
*/
|
|
779
|
+
private processCursorPosition;
|
|
780
|
+
/**
|
|
781
|
+
* Process erase display sequence
|
|
782
|
+
*/
|
|
783
|
+
private processEraseDisplay;
|
|
784
|
+
/**
|
|
785
|
+
* Process erase line sequence
|
|
786
|
+
*/
|
|
787
|
+
private processEraseLine;
|
|
788
|
+
/**
|
|
789
|
+
* Process SGR (Select Graphic Rendition) sequence
|
|
790
|
+
*/
|
|
791
|
+
private processSGR;
|
|
792
|
+
/**
|
|
793
|
+
* Parse extended color (256-color or 24-bit)
|
|
794
|
+
*/
|
|
795
|
+
private parseExtendedColor;
|
|
796
|
+
/**
|
|
797
|
+
* Reset all styles to default
|
|
798
|
+
*/
|
|
799
|
+
private resetStyle;
|
|
800
|
+
/**
|
|
801
|
+
* Get current cursor position
|
|
802
|
+
*/
|
|
803
|
+
getCursor(): {
|
|
804
|
+
row: number;
|
|
805
|
+
col: number;
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* Get current foreground color
|
|
809
|
+
*/
|
|
810
|
+
getFgColor(): Color;
|
|
811
|
+
/**
|
|
812
|
+
* Get current background color
|
|
813
|
+
*/
|
|
814
|
+
getBgColor(): Color;
|
|
815
|
+
/**
|
|
816
|
+
* Reset parser state
|
|
817
|
+
*/
|
|
818
|
+
reset(): void;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* SDL Text Renderer
|
|
823
|
+
*
|
|
824
|
+
* Handles TrueType font loading and text rendering with glyph caching
|
|
825
|
+
* for efficient SDL UI rendering.
|
|
826
|
+
*/
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* SDL Text Renderer
|
|
830
|
+
*
|
|
831
|
+
* Loads TTF fonts and renders text with glyph caching for performance.
|
|
832
|
+
* Supports HiDPI displays by scaling font size based on scale factor.
|
|
833
|
+
*/
|
|
834
|
+
declare class TextRenderer {
|
|
835
|
+
private sdl;
|
|
836
|
+
private ttf;
|
|
837
|
+
private font;
|
|
838
|
+
private fallbackFont;
|
|
839
|
+
private renderer;
|
|
840
|
+
private baseFontSize;
|
|
841
|
+
private scaleFactor;
|
|
842
|
+
private glyphCache;
|
|
843
|
+
private accessCounter;
|
|
844
|
+
private charWidth;
|
|
845
|
+
private charHeight;
|
|
846
|
+
private currentFontPath;
|
|
847
|
+
constructor(renderer: SDLPointer, options?: {
|
|
848
|
+
fontSize?: number;
|
|
849
|
+
scaleFactor?: number;
|
|
850
|
+
fontPath?: string;
|
|
851
|
+
fontName?: string;
|
|
852
|
+
systemFont?: boolean;
|
|
853
|
+
});
|
|
854
|
+
/**
|
|
855
|
+
* Get system font directories for the current platform
|
|
856
|
+
*/
|
|
857
|
+
private getSystemFontDirectories;
|
|
858
|
+
/**
|
|
859
|
+
* Get system font paths for the default font filename
|
|
860
|
+
*/
|
|
861
|
+
private getSystemFontPaths;
|
|
862
|
+
/**
|
|
863
|
+
* Find a font by name in system font directories
|
|
864
|
+
*
|
|
865
|
+
* Searches for common font file extensions (.ttf, .ttc, .otf)
|
|
866
|
+
*/
|
|
867
|
+
private findFontByName;
|
|
868
|
+
/**
|
|
869
|
+
* Get the path to the Cozette font (system or bundled)
|
|
870
|
+
*/
|
|
871
|
+
private getDefaultFontPath;
|
|
872
|
+
/**
|
|
873
|
+
* Get fallback fonts for the current platform
|
|
874
|
+
*/
|
|
875
|
+
private getFallbackFontPaths;
|
|
876
|
+
/**
|
|
877
|
+
* Find an available font, trying default first then fallbacks
|
|
878
|
+
*/
|
|
879
|
+
private findAvailableFont;
|
|
880
|
+
/**
|
|
881
|
+
* Find a system font, skipping the default bundled font
|
|
882
|
+
*/
|
|
883
|
+
private findSystemFont;
|
|
884
|
+
/**
|
|
885
|
+
* Get emoji font paths for the current platform
|
|
886
|
+
*/
|
|
887
|
+
private getEmojiFontPaths;
|
|
888
|
+
/**
|
|
889
|
+
* Find an available emoji font
|
|
890
|
+
*/
|
|
891
|
+
private findEmojiFont;
|
|
892
|
+
/**
|
|
893
|
+
* Load the fallback emoji font if available
|
|
894
|
+
*/
|
|
895
|
+
private loadFallbackFont;
|
|
896
|
+
/**
|
|
897
|
+
* Load a TTF font at the current scaled size
|
|
898
|
+
*/
|
|
899
|
+
private loadFont;
|
|
900
|
+
/**
|
|
901
|
+
* Update scale factor (for HiDPI display changes)
|
|
902
|
+
*/
|
|
903
|
+
updateScaleFactor(scaleFactor: number): void;
|
|
904
|
+
/**
|
|
905
|
+
* Get character dimensions
|
|
906
|
+
*/
|
|
907
|
+
getCharDimensions(): {
|
|
908
|
+
width: number;
|
|
909
|
+
height: number;
|
|
910
|
+
};
|
|
911
|
+
/**
|
|
912
|
+
* Generate cache key for a glyph
|
|
913
|
+
*/
|
|
914
|
+
private getCacheKey;
|
|
915
|
+
/**
|
|
916
|
+
* Get or create a cached glyph texture
|
|
917
|
+
*/
|
|
918
|
+
private getGlyph;
|
|
919
|
+
/**
|
|
920
|
+
* Evict least recently used glyphs
|
|
921
|
+
*/
|
|
922
|
+
private evictOldGlyphs;
|
|
923
|
+
/**
|
|
924
|
+
* Render a single character at the specified position
|
|
925
|
+
*/
|
|
926
|
+
renderChar(char: string, x: number, y: number, color: Color, italic?: boolean): void;
|
|
927
|
+
/**
|
|
928
|
+
* Render a string of text at the specified position
|
|
929
|
+
*/
|
|
930
|
+
renderText(text: string, x: number, y: number, color: Color, italic?: boolean): void;
|
|
931
|
+
/**
|
|
932
|
+
* Get text dimensions
|
|
933
|
+
*/
|
|
934
|
+
measureText(text: string): {
|
|
935
|
+
width: number;
|
|
936
|
+
height: number;
|
|
937
|
+
};
|
|
938
|
+
/**
|
|
939
|
+
* Clear the glyph cache
|
|
940
|
+
*/
|
|
941
|
+
clearCache(): void;
|
|
942
|
+
/**
|
|
943
|
+
* Get cache statistics
|
|
944
|
+
*/
|
|
945
|
+
getCacheStats(): {
|
|
946
|
+
size: number;
|
|
947
|
+
maxSize: number;
|
|
948
|
+
};
|
|
949
|
+
/**
|
|
950
|
+
* Clean up resources
|
|
951
|
+
*/
|
|
952
|
+
destroy(): void;
|
|
953
|
+
}
|
|
954
|
+
|
|
788
955
|
/**
|
|
789
956
|
* SDL Input Bridge
|
|
790
957
|
*
|
|
@@ -888,4 +1055,4 @@ declare class InputBridge {
|
|
|
888
1055
|
*/
|
|
889
1056
|
declare const isSdlAvailable: () => boolean;
|
|
890
1057
|
|
|
891
|
-
export { AnsiParser, type Color, type DrawCommand, type InkKeyEvent, InputBridge,
|
|
1058
|
+
export { AnsiParser, type Color, type DrawCommand, type InkKeyEvent, InputBridge, type SDLPointer, Sdl2, SdlInputStream, type SdlKeyEvent, SdlOutputStream, type SdlStreams, type SdlStreamsOptions, SdlTtf, SdlUiRenderer, type SdlUiRendererOptions, SdlWindow, TextRenderer, createSDLRect, createSdlStreams, getSdl2, getSdlTtf, isSdl2Available, isSdlAvailable, isSdlTtfAvailable };
|