@gkoreli/ghostty-vt-js 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -0
  3. package/THIRD_PARTY_NOTICES.md +45 -0
  4. package/dist/browser-terminal/buffer.d.ts +93 -0
  5. package/dist/browser-terminal/buffer.d.ts.map +1 -0
  6. package/dist/browser-terminal/buffer.js +337 -0
  7. package/dist/browser-terminal/buffer.js.map +1 -0
  8. package/dist/browser-terminal/encoding.d.ts +17 -0
  9. package/dist/browser-terminal/encoding.d.ts.map +1 -0
  10. package/dist/browser-terminal/encoding.js +22 -0
  11. package/dist/browser-terminal/encoding.js.map +1 -0
  12. package/dist/browser-terminal/event-emitter.d.ts +8 -0
  13. package/dist/browser-terminal/event-emitter.d.ts.map +1 -0
  14. package/dist/browser-terminal/event-emitter.js +27 -0
  15. package/dist/browser-terminal/event-emitter.js.map +1 -0
  16. package/dist/browser-terminal/frame-hold.d.ts +13 -0
  17. package/dist/browser-terminal/frame-hold.d.ts.map +1 -0
  18. package/dist/browser-terminal/frame-hold.js +17 -0
  19. package/dist/browser-terminal/frame-hold.js.map +1 -0
  20. package/dist/browser-terminal/geometry.d.ts +229 -0
  21. package/dist/browser-terminal/geometry.d.ts.map +1 -0
  22. package/dist/browser-terminal/geometry.js +299 -0
  23. package/dist/browser-terminal/geometry.js.map +1 -0
  24. package/dist/browser-terminal/ghostty.d.ts +478 -0
  25. package/dist/browser-terminal/ghostty.d.ts.map +1 -0
  26. package/dist/browser-terminal/ghostty.js +1212 -0
  27. package/dist/browser-terminal/ghostty.js.map +1 -0
  28. package/dist/browser-terminal/gpu/adapter.d.ts +70 -0
  29. package/dist/browser-terminal/gpu/adapter.d.ts.map +1 -0
  30. package/dist/browser-terminal/gpu/adapter.js +260 -0
  31. package/dist/browser-terminal/gpu/adapter.js.map +1 -0
  32. package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.d.ts +33 -0
  33. package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.d.ts.map +1 -0
  34. package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.js +159 -0
  35. package/dist/browser-terminal/gpu/core/canvas-glyph-rasterizer.js.map +1 -0
  36. package/dist/browser-terminal/gpu/core/context-loss-watchdog.d.ts +35 -0
  37. package/dist/browser-terminal/gpu/core/context-loss-watchdog.d.ts.map +1 -0
  38. package/dist/browser-terminal/gpu/core/context-loss-watchdog.js +73 -0
  39. package/dist/browser-terminal/gpu/core/context-loss-watchdog.js.map +1 -0
  40. package/dist/browser-terminal/gpu/core/frame.d.ts +68 -0
  41. package/dist/browser-terminal/gpu/core/frame.d.ts.map +1 -0
  42. package/dist/browser-terminal/gpu/core/frame.js +167 -0
  43. package/dist/browser-terminal/gpu/core/frame.js.map +1 -0
  44. package/dist/browser-terminal/gpu/core/glyph-atlas.d.ts +136 -0
  45. package/dist/browser-terminal/gpu/core/glyph-atlas.d.ts.map +1 -0
  46. package/dist/browser-terminal/gpu/core/glyph-atlas.js +281 -0
  47. package/dist/browser-terminal/gpu/core/glyph-atlas.js.map +1 -0
  48. package/dist/browser-terminal/gpu/core/procedural-shapes.d.ts +24 -0
  49. package/dist/browser-terminal/gpu/core/procedural-shapes.d.ts.map +1 -0
  50. package/dist/browser-terminal/gpu/core/procedural-shapes.js +316 -0
  51. package/dist/browser-terminal/gpu/core/procedural-shapes.js.map +1 -0
  52. package/dist/browser-terminal/gpu/core/webgl2-renderer.d.ts +107 -0
  53. package/dist/browser-terminal/gpu/core/webgl2-renderer.d.ts.map +1 -0
  54. package/dist/browser-terminal/gpu/core/webgl2-renderer.js +698 -0
  55. package/dist/browser-terminal/gpu/core/webgl2-renderer.js.map +1 -0
  56. package/dist/browser-terminal/gpu/create-renderer.d.ts +15 -0
  57. package/dist/browser-terminal/gpu/create-renderer.d.ts.map +1 -0
  58. package/dist/browser-terminal/gpu/create-renderer.js +33 -0
  59. package/dist/browser-terminal/gpu/create-renderer.js.map +1 -0
  60. package/dist/browser-terminal/index.d.ts +47 -0
  61. package/dist/browser-terminal/index.d.ts.map +1 -0
  62. package/dist/browser-terminal/index.js +75 -0
  63. package/dist/browser-terminal/index.js.map +1 -0
  64. package/dist/browser-terminal/input-handler.d.ts +262 -0
  65. package/dist/browser-terminal/input-handler.d.ts.map +1 -0
  66. package/dist/browser-terminal/input-handler.js +978 -0
  67. package/dist/browser-terminal/input-handler.js.map +1 -0
  68. package/dist/browser-terminal/interfaces.d.ts +230 -0
  69. package/dist/browser-terminal/interfaces.d.ts.map +1 -0
  70. package/dist/browser-terminal/interfaces.js +5 -0
  71. package/dist/browser-terminal/interfaces.js.map +1 -0
  72. package/dist/browser-terminal/link-detector.d.ts +76 -0
  73. package/dist/browser-terminal/link-detector.d.ts.map +1 -0
  74. package/dist/browser-terminal/link-detector.js +165 -0
  75. package/dist/browser-terminal/link-detector.js.map +1 -0
  76. package/dist/browser-terminal/providers/osc8-link-provider.d.ts +56 -0
  77. package/dist/browser-terminal/providers/osc8-link-provider.d.ts.map +1 -0
  78. package/dist/browser-terminal/providers/osc8-link-provider.js +204 -0
  79. package/dist/browser-terminal/providers/osc8-link-provider.js.map +1 -0
  80. package/dist/browser-terminal/providers/url-regex-provider.d.ts +68 -0
  81. package/dist/browser-terminal/providers/url-regex-provider.d.ts.map +1 -0
  82. package/dist/browser-terminal/providers/url-regex-provider.js +107 -0
  83. package/dist/browser-terminal/providers/url-regex-provider.js.map +1 -0
  84. package/dist/browser-terminal/renderer-interface.d.ts +59 -0
  85. package/dist/browser-terminal/renderer-interface.d.ts.map +1 -0
  86. package/dist/browser-terminal/renderer-interface.js +2 -0
  87. package/dist/browser-terminal/renderer-interface.js.map +1 -0
  88. package/dist/browser-terminal/renderer.d.ts +254 -0
  89. package/dist/browser-terminal/renderer.d.ts.map +1 -0
  90. package/dist/browser-terminal/renderer.js +905 -0
  91. package/dist/browser-terminal/renderer.js.map +1 -0
  92. package/dist/browser-terminal/scrollbar-overlay.d.ts +45 -0
  93. package/dist/browser-terminal/scrollbar-overlay.d.ts.map +1 -0
  94. package/dist/browser-terminal/scrollbar-overlay.js +89 -0
  95. package/dist/browser-terminal/scrollbar-overlay.js.map +1 -0
  96. package/dist/browser-terminal/selection-manager.d.ts +180 -0
  97. package/dist/browser-terminal/selection-manager.d.ts.map +1 -0
  98. package/dist/browser-terminal/selection-manager.js +913 -0
  99. package/dist/browser-terminal/selection-manager.js.map +1 -0
  100. package/dist/browser-terminal/terminal.d.ts +423 -0
  101. package/dist/browser-terminal/terminal.d.ts.map +1 -0
  102. package/dist/browser-terminal/terminal.js +1754 -0
  103. package/dist/browser-terminal/terminal.js.map +1 -0
  104. package/dist/browser-terminal/types.d.ts +595 -0
  105. package/dist/browser-terminal/types.d.ts.map +1 -0
  106. package/dist/browser-terminal/types.js +467 -0
  107. package/dist/browser-terminal/types.js.map +1 -0
  108. package/dist/browser-terminal/viewport-scroller.d.ts +94 -0
  109. package/dist/browser-terminal/viewport-scroller.d.ts.map +1 -0
  110. package/dist/browser-terminal/viewport-scroller.js +159 -0
  111. package/dist/browser-terminal/viewport-scroller.js.map +1 -0
  112. package/dist/browser-terminal/vt/effects.d.ts +114 -0
  113. package/dist/browser-terminal/vt/effects.d.ts.map +1 -0
  114. package/dist/browser-terminal/vt/effects.js +143 -0
  115. package/dist/browser-terminal/vt/effects.js.map +1 -0
  116. package/dist/browser-terminal/vt/enums.d.ts +155 -0
  117. package/dist/browser-terminal/vt/enums.d.ts.map +1 -0
  118. package/dist/browser-terminal/vt/enums.js +161 -0
  119. package/dist/browser-terminal/vt/enums.js.map +1 -0
  120. package/dist/browser-terminal/vt/mouse.d.ts +166 -0
  121. package/dist/browser-terminal/vt/mouse.d.ts.map +1 -0
  122. package/dist/browser-terminal/vt/mouse.js +259 -0
  123. package/dist/browser-terminal/vt/mouse.js.map +1 -0
  124. package/dist/browser-terminal/vt/paste.d.ts +53 -0
  125. package/dist/browser-terminal/vt/paste.d.ts.map +1 -0
  126. package/dist/browser-terminal/vt/paste.js +89 -0
  127. package/dist/browser-terminal/vt/paste.js.map +1 -0
  128. package/dist/browser-terminal/vt/render-state.d.ts +208 -0
  129. package/dist/browser-terminal/vt/render-state.d.ts.map +1 -0
  130. package/dist/browser-terminal/vt/render-state.js +776 -0
  131. package/dist/browser-terminal/vt/render-state.js.map +1 -0
  132. package/dist/browser-terminal/vt/style.d.ts +54 -0
  133. package/dist/browser-terminal/vt/style.d.ts.map +1 -0
  134. package/dist/browser-terminal/vt/style.js +92 -0
  135. package/dist/browser-terminal/vt/style.js.map +1 -0
  136. package/dist/browser-terminal/wasm-loader.d.ts +39 -0
  137. package/dist/browser-terminal/wasm-loader.d.ts.map +1 -0
  138. package/dist/browser-terminal/wasm-loader.js +73 -0
  139. package/dist/browser-terminal/wasm-loader.js.map +1 -0
  140. package/dist/browser-terminal/write-buffer.d.ts +40 -0
  141. package/dist/browser-terminal/write-buffer.d.ts.map +1 -0
  142. package/dist/browser-terminal/write-buffer.js +144 -0
  143. package/dist/browser-terminal/write-buffer.js.map +1 -0
  144. package/dist/protocol/index.d.ts +135 -0
  145. package/dist/protocol/index.d.ts.map +1 -0
  146. package/dist/protocol/index.js +76 -0
  147. package/dist/protocol/index.js.map +1 -0
  148. package/dist/react/index.d.ts +59 -0
  149. package/dist/react/index.d.ts.map +1 -0
  150. package/dist/react/index.js +146 -0
  151. package/dist/react/index.js.map +1 -0
  152. package/dist/server/index.d.ts +130 -0
  153. package/dist/server/index.d.ts.map +1 -0
  154. package/dist/server/index.js +191 -0
  155. package/dist/server/index.js.map +1 -0
  156. package/dist/terminal-screen-emulator/emulator.d.ts +66 -0
  157. package/dist/terminal-screen-emulator/emulator.d.ts.map +1 -0
  158. package/dist/terminal-screen-emulator/emulator.js +286 -0
  159. package/dist/terminal-screen-emulator/emulator.js.map +1 -0
  160. package/dist/terminal-screen-emulator/index.d.ts +82 -0
  161. package/dist/terminal-screen-emulator/index.d.ts.map +1 -0
  162. package/dist/terminal-screen-emulator/index.js +92 -0
  163. package/dist/terminal-screen-emulator/index.js.map +1 -0
  164. package/dist/terminal-screen-emulator/types.d.ts +382 -0
  165. package/dist/terminal-screen-emulator/types.d.ts.map +1 -0
  166. package/dist/terminal-screen-emulator/types.js +91 -0
  167. package/dist/terminal-screen-emulator/types.js.map +1 -0
  168. package/dist/terminal-screen-emulator/wasm-loader.d.ts +71 -0
  169. package/dist/terminal-screen-emulator/wasm-loader.d.ts.map +1 -0
  170. package/dist/terminal-screen-emulator/wasm-loader.js +162 -0
  171. package/dist/terminal-screen-emulator/wasm-loader.js.map +1 -0
  172. package/dist/themes/index.d.ts +6 -0
  173. package/dist/themes/index.d.ts.map +1 -0
  174. package/dist/themes/index.js +51 -0
  175. package/dist/themes/index.js.map +1 -0
  176. package/dist/wasm/alloc.d.ts +170 -0
  177. package/dist/wasm/alloc.d.ts.map +1 -0
  178. package/dist/wasm/alloc.js +307 -0
  179. package/dist/wasm/alloc.js.map +1 -0
  180. package/dist/wasm/compile.d.ts +73 -0
  181. package/dist/wasm/compile.d.ts.map +1 -0
  182. package/dist/wasm/compile.js +82 -0
  183. package/dist/wasm/compile.js.map +1 -0
  184. package/dist/wasm/exports.d.ts +234 -0
  185. package/dist/wasm/exports.d.ts.map +1 -0
  186. package/dist/wasm/exports.js +15 -0
  187. package/dist/wasm/exports.js.map +1 -0
  188. package/dist/wasm/fn-table.d.ts +119 -0
  189. package/dist/wasm/fn-table.d.ts.map +1 -0
  190. package/dist/wasm/fn-table.js +168 -0
  191. package/dist/wasm/fn-table.js.map +1 -0
  192. package/dist/wasm/memory.d.ts +59 -0
  193. package/dist/wasm/memory.d.ts.map +1 -0
  194. package/dist/wasm/memory.js +89 -0
  195. package/dist/wasm/memory.js.map +1 -0
  196. package/dist/wasm/type-layouts.d.ts +61 -0
  197. package/dist/wasm/type-layouts.d.ts.map +1 -0
  198. package/dist/wasm/type-layouts.js +32 -0
  199. package/dist/wasm/type-layouts.js.map +1 -0
  200. package/package.json +94 -0
  201. package/wasm/ghostty-vt.wasm +0 -0
@@ -0,0 +1,92 @@
1
+ /**
2
+ * # Terminal Screen Emulator
3
+ *
4
+ * A virtual terminal that processes raw VT/ANSI escape sequences and renders
5
+ * the screen content as plain text, styled HTML, or preserved escape sequences.
6
+ *
7
+ * Powered by [Ghostty](https://github.com/ghostty-org/ghostty)'s terminal
8
+ * emulator compiled to WebAssembly — the same engine that renders Ghostty's
9
+ * actual terminal UI, running in Node.js.
10
+ *
11
+ * ## What It Does
12
+ *
13
+ * Feed it raw bytes (as if from a PTY or terminal process) and it maintains
14
+ * a complete in-memory terminal screen — cursor position, colors, text
15
+ * attributes, line wrapping, scrollback, alternate buffer, and all.
16
+ *
17
+ * Then ask it to render the screen in any format:
18
+ * - **PlainText** — just the visible characters (for AI agents, search, logs)
19
+ * - **Html** — styled `<span>` elements with inline CSS (for web UIs)
20
+ * - **AnsiEscapes** — preserved VT sequences (for piping to another terminal)
21
+ *
22
+ * ## Quick Start
23
+ *
24
+ * ```typescript
25
+ * import {
26
+ * createTerminalScreen,
27
+ * OutputFormat,
28
+ * } from "@gkoreli/ghostty-vt-js/terminal-screen-emulator";
29
+ *
30
+ * // Create a virtual 120×40 terminal
31
+ * const screen = await createTerminalScreen({ columns: 120, rows: 40 });
32
+ *
33
+ * // Feed it terminal output (raw bytes with escape sequences)
34
+ * screen.write("\x1b[1;31mERROR\x1b[0m: connection refused\r\n");
35
+ * screen.write("\x1b[32m✓\x1b[0m 42 tests passed\r\n");
36
+ *
37
+ * // Render as plain text (for AI consumption)
38
+ * const text = screen.render(OutputFormat.PlainText);
39
+ * // → "ERROR: connection refused\n✓ 42 tests passed\n"
40
+ *
41
+ * // Render as HTML (for web display)
42
+ * const html = screen.render(OutputFormat.Html);
43
+ * // → '<span style="font-weight: bold; color: #ff0000">ERROR</span>: ...'
44
+ *
45
+ * // Resize the terminal (reflows content)
46
+ * screen.resize(80, 24);
47
+ *
48
+ * // Clean up WASM memory when done
49
+ * screen.dispose();
50
+ * ```
51
+ *
52
+ * ## Architecture
53
+ *
54
+ * ```
55
+ * ┌─────────────────────────────────────────────────────────┐
56
+ * │ Your Code │
57
+ * │ screen.write(bytes) → screen.render(format) │
58
+ * ├─────────────────────────────────────────────────────────┤
59
+ * │ Terminal Screen Emulator (this module) │
60
+ * │ TypeScript wrapper — types, validation, memory mgmt │
61
+ * ├─────────────────────────────────────────────────────────┤
62
+ * │ ghostty-vt.wasm (542KB) │
63
+ * │ Ghostty's terminal emulator compiled to WebAssembly │
64
+ * │ Full VT100/VT220/xterm protocol implementation │
65
+ * └─────────────────────────────────────────────────────────┘
66
+ * ```
67
+ *
68
+ * ## Design Principles
69
+ *
70
+ * - **Declarative** — describe what you want (format, dimensions), not how
71
+ * - **Zero manual memory management** — all WASM pointers handled internally
72
+ * - **Self-describing** — adapts to Ghostty version changes via runtime introspection
73
+ * - **Independent instances** — each screen has its own WASM memory, no shared state
74
+ * - **Fail-fast** — clear errors with context, never silent corruption
75
+ *
76
+ * @module terminal-screen-emulator
77
+ * @packageDocumentation
78
+ */
79
+ // ─── Public API ──────────────────────────────────────────────────────────────
80
+ // Factory function
81
+ export { createTerminalScreen } from "./emulator.js";
82
+ // Compile-time embedder seam. Standalone-binary builders (Bun `--compile`)
83
+ // can pre-load the WASM bytes once at boot to bypass the on-disk search
84
+ // that fails inside `/$bunfs/...`. See `wasm-loader.ts` for the rationale.
85
+ export { preloadEmulatorWasm } from "./wasm-loader.js";
86
+ // Types and enums (everything a consumer needs)
87
+ export {
88
+ // Rendering
89
+ OutputFormat,
90
+ // Text styling (for consumers who want to inspect styled output)
91
+ UnderlineStyle, } from "./types.js";
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/terminal-screen-emulator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AAEH,gFAAgF;AAEhF,mBAAmB;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,2EAA2E;AAC3E,wEAAwE;AACxE,2EAA2E;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,gDAAgD;AAChD,OAAO;AAKL,YAAY;AACZ,YAAY;AAGZ,iEAAiE;AACjE,cAAc,GAKf,MAAM,YAAY,CAAC"}
@@ -0,0 +1,382 @@
1
+ /**
2
+ * @module terminal-screen-emulator/types
3
+ *
4
+ * Core type definitions for the Terminal Screen Emulator.
5
+ *
6
+ * This module defines the public interface for a virtual terminal that:
7
+ * 1. Accepts raw byte streams containing VT/ANSI escape sequences
8
+ * 2. Maintains an in-memory screen buffer (like a real terminal would)
9
+ * 3. Renders the screen content in multiple output formats
10
+ *
11
+ * The emulator faithfully implements the VT100/VT220/xterm protocol —
12
+ * cursor movement, colors (16, 256, RGB), text attributes, line wrapping,
13
+ * scrollback, alternate screen buffer, and more.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { createTerminalScreen } from "@gkoreli/ghostty-vt-js/terminal-screen-emulator";
18
+ *
19
+ * const screen = await createTerminalScreen({ columns: 120, rows: 40 });
20
+ * screen.write("\x1b[1;31mERROR\x1b[0m: connection refused\r\n");
21
+ *
22
+ * const plainText = screen.render(OutputFormat.PlainText);
23
+ * const styledHtml = screen.render(OutputFormat.Html);
24
+ *
25
+ * screen.dispose();
26
+ * ```
27
+ */
28
+ /**
29
+ * Determines how the terminal screen content is rendered to a string.
30
+ *
31
+ * Each format serves a different consumer:
32
+ * - `PlainText` — for AI agents that need just the text content
33
+ * - `AnsiEscapes` — for piping to another terminal or tool that understands VT
34
+ * - `Html` — for rendering in a browser, documentation, or rich UI
35
+ */
36
+ export declare enum OutputFormat {
37
+ /**
38
+ * Plain text with no formatting.
39
+ *
40
+ * All escape sequences are stripped. Only the visible character content
41
+ * remains. Useful for text search, AI agent consumption, or logging.
42
+ *
43
+ * @example "ERROR: connection refused\nRetrying in 5s..."
44
+ */
45
+ PlainText = 0,
46
+ /**
47
+ * ANSI/VT escape sequences preserved.
48
+ *
49
+ * The output contains the same escape sequences that produced the screen
50
+ * content. Useful for piping to another terminal, `less -R`, or tools
51
+ * that understand ANSI color codes.
52
+ *
53
+ * @example "\x1b[1;31mERROR\x1b[0m: connection refused"
54
+ */
55
+ AnsiEscapes = 1,
56
+ /**
57
+ * HTML with inline CSS styles.
58
+ *
59
+ * Each styled span becomes a `<span style="...">` element. Colors are
60
+ * rendered as CSS `color` and `background-color`. Bold, italic, underline,
61
+ * and other attributes become corresponding CSS properties.
62
+ *
63
+ * @example '<span style="font-weight: bold; color: #ff0000">ERROR</span>: connection refused'
64
+ */
65
+ Html = 2
66
+ }
67
+ /**
68
+ * Options that control how the terminal screen is rendered to a string.
69
+ *
70
+ * These options apply to all output formats and control post-processing
71
+ * of the rendered content.
72
+ */
73
+ export interface RenderOptions {
74
+ /**
75
+ * The output format to use.
76
+ *
77
+ * @default OutputFormat.PlainText
78
+ */
79
+ format: OutputFormat;
80
+ /**
81
+ * Whether to unwrap soft-wrapped lines into single logical lines.
82
+ *
83
+ * When a terminal wraps a long line at the column boundary, it creates
84
+ * a "soft wrap." With `unwrapSoftWraps: true`, these are joined back
85
+ * into the original long line. Hard line breaks (explicit \n) are preserved.
86
+ *
87
+ * @default false
88
+ */
89
+ unwrapSoftWraps?: boolean;
90
+ /**
91
+ * Whether to trim trailing whitespace from each line.
92
+ *
93
+ * Terminal screens are padded with spaces to fill the full width.
94
+ * With `trimTrailingWhitespace: true`, these padding spaces are removed.
95
+ *
96
+ * @default true
97
+ */
98
+ trimTrailingWhitespace?: boolean;
99
+ }
100
+ /**
101
+ * Configuration for creating a new terminal screen emulator instance.
102
+ *
103
+ * These dimensions define the virtual terminal's visible area. They can
104
+ * be changed later via {@link TerminalScreen.resize}.
105
+ */
106
+ export interface TerminalScreenConfig {
107
+ /**
108
+ * Width of the terminal in character columns.
109
+ *
110
+ * This determines where soft line wrapping occurs. Standard terminal
111
+ * widths are 80 (traditional) or 120 (modern widescreen).
112
+ *
113
+ * @default 80
114
+ */
115
+ columns?: number;
116
+ /**
117
+ * Height of the terminal in character rows.
118
+ *
119
+ * This determines how many lines are visible at once. Standard terminal
120
+ * heights are 24 (traditional) or 40-50 (modern).
121
+ *
122
+ * @default 24
123
+ */
124
+ rows?: number;
125
+ /**
126
+ * Maximum number of lines retained in the scrollback buffer.
127
+ *
128
+ * When content scrolls off the top of the visible area, it's preserved
129
+ * in the scrollback buffer up to this limit. Set to 0 to disable
130
+ * scrollback entirely (only the visible screen is retained).
131
+ *
132
+ * @default 0
133
+ */
134
+ maxScrollbackLines?: number;
135
+ }
136
+ /**
137
+ * A virtual terminal screen emulator.
138
+ *
139
+ * This is the primary interface for interacting with the terminal emulator.
140
+ * It maintains an in-memory representation of a terminal screen and processes
141
+ * raw byte streams containing VT/ANSI escape sequences — exactly like a real
142
+ * terminal (Ghostty, iTerm2, xterm) would.
143
+ *
144
+ * The emulator handles:
145
+ * - **Cursor movement** — absolute positioning, relative moves, save/restore
146
+ * - **Text attributes** — bold, italic, faint, underline, strikethrough, blink
147
+ * - **Colors** — 16 standard, 256 palette, and 24-bit RGB (via SGR sequences)
148
+ * - **Line operations** — insert, delete, scroll, soft/hard wrapping
149
+ * - **Screen operations** — clear, alternate buffer, resize
150
+ * - **Character sets** — UTF-8, special graphics characters
151
+ *
152
+ * Internally powered by Ghostty's terminal emulator compiled to WebAssembly.
153
+ * All WASM memory management is handled automatically — you never touch pointers.
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const screen = await createTerminalScreen({ columns: 80, rows: 24 });
158
+ *
159
+ * // Feed it raw terminal output (as if it came from a PTY)
160
+ * screen.write("$ npm test\r\n");
161
+ * screen.write("\x1b[32m✓\x1b[0m 42 tests passed\r\n");
162
+ * screen.write("\x1b[1;31m✗\x1b[0m 1 test failed\r\n");
163
+ *
164
+ * // Render the screen content
165
+ * const text = screen.render(OutputFormat.PlainText);
166
+ * // "$ npm test\n✓ 42 tests passed\n✗ 1 test failed\n"
167
+ *
168
+ * const html = screen.render(OutputFormat.Html);
169
+ * // '<span style="color: #00ff00">✓</span> 42 tests passed\n...'
170
+ *
171
+ * // Resize (e.g., user resized their terminal window)
172
+ * screen.resize(120, 40);
173
+ *
174
+ * // Clean up WASM resources when done
175
+ * screen.dispose();
176
+ * ```
177
+ */
178
+ export interface TerminalScreen {
179
+ /**
180
+ * Write raw bytes into the terminal emulator.
181
+ *
182
+ * The input is processed exactly as a real terminal would — escape sequences
183
+ * are interpreted, the cursor moves, colors are applied, text wraps at the
184
+ * column boundary, and the screen buffer is updated.
185
+ *
186
+ * You can call `write()` multiple times — the terminal maintains state between
187
+ * calls (cursor position, active colors, etc.), just like a real terminal
188
+ * receiving a continuous byte stream from a PTY.
189
+ *
190
+ * @param data - Raw terminal output. Can be a string (UTF-8 encoded internally)
191
+ * or a Uint8Array of raw bytes. May contain any mix of printable
192
+ * characters and VT/ANSI escape sequences.
193
+ *
194
+ * @throws {Error} If the screen has been disposed.
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * // String input (most common)
199
+ * screen.write("Hello, world!\r\n");
200
+ * screen.write("\x1b[1;31mERROR\x1b[0m: something broke\r\n");
201
+ *
202
+ * // Raw bytes (e.g., from a PTY read)
203
+ * const ptyOutput = new Uint8Array([0x1b, 0x5b, 0x31, 0x6d, 0x48, 0x69]);
204
+ * screen.write(ptyOutput);
205
+ * ```
206
+ */
207
+ write(data: string | Uint8Array): void;
208
+ /**
209
+ * Render the current terminal screen content as a formatted string.
210
+ *
211
+ * This captures the visible screen area (not scrollback) and converts it
212
+ * to the requested output format. The terminal state is not modified —
213
+ * you can call `render()` multiple times and get the same result.
214
+ *
215
+ * @param options - Either an {@link OutputFormat} enum value for quick usage,
216
+ * or a full {@link RenderOptions} object for fine-grained control.
217
+ * @returns The rendered screen content as a string.
218
+ *
219
+ * @throws {Error} If the screen has been disposed.
220
+ * @throws {Error} If the WASM formatter fails (should not happen in normal use).
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * // Quick: just pass the format
225
+ * const text = screen.render(OutputFormat.PlainText);
226
+ * const html = screen.render(OutputFormat.Html);
227
+ *
228
+ * // Detailed: pass full options
229
+ * const unwrapped = screen.render({
230
+ * format: OutputFormat.PlainText,
231
+ * unwrapSoftWraps: true,
232
+ * trimTrailingWhitespace: true,
233
+ * });
234
+ * ```
235
+ */
236
+ render(options?: RenderOptions | OutputFormat): string;
237
+ /**
238
+ * Resize the terminal screen to new dimensions.
239
+ *
240
+ * This reflows content exactly as a real terminal would when you drag the
241
+ * window edge. Soft-wrapped lines are re-wrapped to the new width. The
242
+ * cursor position is adjusted to remain valid.
243
+ *
244
+ * @param columns - New width in character columns (must be > 0).
245
+ * @param rows - New height in character rows (must be > 0).
246
+ *
247
+ * @throws {Error} If the screen has been disposed.
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * screen.resize(120, 40); // Widescreen layout
252
+ * screen.resize(80, 24); // Back to standard
253
+ * ```
254
+ */
255
+ resize(columns: number, rows: number): void;
256
+ /**
257
+ * Reset the terminal to its initial state.
258
+ *
259
+ * Clears the screen, resets all text attributes, moves the cursor to (0,0),
260
+ * clears scrollback, and resets all terminal modes. Equivalent to the
261
+ * `ESC c` (RIS — Reset to Initial State) escape sequence.
262
+ *
263
+ * The terminal remains usable after reset — it's like opening a fresh terminal.
264
+ *
265
+ * @throws {Error} If the screen has been disposed.
266
+ */
267
+ reset(): void;
268
+ /**
269
+ * Release all WASM memory associated with this terminal screen.
270
+ *
271
+ * After calling `dispose()`, the instance is permanently unusable — all
272
+ * methods will throw. This is necessary because WASM memory is not
273
+ * garbage-collected by the JavaScript runtime.
274
+ *
275
+ * Safe to call multiple times (subsequent calls are no-ops).
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * const screen = await createTerminalScreen();
280
+ * try {
281
+ * screen.write(data);
282
+ * return screen.render(OutputFormat.PlainText);
283
+ * } finally {
284
+ * screen.dispose(); // Always clean up
285
+ * }
286
+ * ```
287
+ */
288
+ dispose(): void;
289
+ }
290
+ /**
291
+ * An RGB color value with 8-bit channels.
292
+ *
293
+ * Used to represent foreground, background, and underline colors
294
+ * in terminal text attributes. Corresponds to 24-bit "true color"
295
+ * as set by SGR sequences like `ESC[38;2;R;G;Bm`.
296
+ */
297
+ export interface RgbColor {
298
+ /** Red channel (0–255). */
299
+ red: number;
300
+ /** Green channel (0–255). */
301
+ green: number;
302
+ /** Blue channel (0–255). */
303
+ blue: number;
304
+ }
305
+ /**
306
+ * The style of underline decoration applied to text.
307
+ *
308
+ * Modern terminals support multiple underline styles via the SGR 4:x
309
+ * sub-parameter syntax (e.g., `ESC[4:3m` for curly underline).
310
+ */
311
+ export declare enum UnderlineStyle {
312
+ /** No underline. */
313
+ None = 0,
314
+ /** Standard single underline (SGR 4). */
315
+ Single = 1,
316
+ /** Double underline (SGR 21 or SGR 4:2). */
317
+ Double = 2,
318
+ /** Curly/wavy underline (SGR 4:3) — commonly used for spelling errors. */
319
+ Curly = 3,
320
+ /** Dotted underline (SGR 4:4). */
321
+ Dotted = 4,
322
+ /** Dashed underline (SGR 4:5). */
323
+ Dashed = 5
324
+ }
325
+ /**
326
+ * Complete set of text styling attributes for a span of terminal text.
327
+ *
328
+ * These correspond to SGR (Select Graphic Rendition) parameters in the
329
+ * VT/ANSI escape sequence protocol. A real terminal applies these attributes
330
+ * to each character cell; this interface represents the computed style.
331
+ */
332
+ export interface TextAttributes {
333
+ /** Bold / increased intensity (SGR 1). */
334
+ bold: boolean;
335
+ /** Italic (SGR 3). */
336
+ italic: boolean;
337
+ /** Faint / decreased intensity (SGR 2). */
338
+ faint: boolean;
339
+ /** Blinking text (SGR 5). */
340
+ blink: boolean;
341
+ /** Inverse / reverse video — swap foreground and background (SGR 7). */
342
+ inverse: boolean;
343
+ /** Invisible / hidden text (SGR 8). */
344
+ invisible: boolean;
345
+ /** Strikethrough / crossed-out (SGR 9). */
346
+ strikethrough: boolean;
347
+ /** Overline (SGR 53). */
348
+ overline: boolean;
349
+ /** Underline style and presence. */
350
+ underline: UnderlineStyle;
351
+ /** Foreground (text) color, or null for the terminal's default. */
352
+ foregroundColor: RgbColor | null;
353
+ /** Background color, or null for the terminal's default. */
354
+ backgroundColor: RgbColor | null;
355
+ /** Underline color (independent of text color), or null for default. */
356
+ underlineColor: RgbColor | null;
357
+ }
358
+ /**
359
+ * A contiguous span of text with uniform styling.
360
+ *
361
+ * The terminal screen is composed of lines, each containing one or more
362
+ * styled spans. Within a span, every character has the same attributes.
363
+ * A new span begins whenever any attribute changes.
364
+ */
365
+ export interface StyledTextSpan {
366
+ /** The text content of this span. */
367
+ text: string;
368
+ /** The visual attributes applied to every character in this span. */
369
+ attributes: TextAttributes;
370
+ }
371
+ /**
372
+ * A single line of terminal output, composed of styled spans.
373
+ *
374
+ * Each line represents one row of the terminal screen. The spans within
375
+ * a line are ordered left-to-right and their text concatenation equals
376
+ * the full line content.
377
+ */
378
+ export interface StyledTextLine {
379
+ /** Ordered spans composing this line, left to right. */
380
+ spans: StyledTextSpan[];
381
+ }
382
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/terminal-screen-emulator/types.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @module terminal-screen-emulator/types
3
+ *
4
+ * Core type definitions for the Terminal Screen Emulator.
5
+ *
6
+ * This module defines the public interface for a virtual terminal that:
7
+ * 1. Accepts raw byte streams containing VT/ANSI escape sequences
8
+ * 2. Maintains an in-memory screen buffer (like a real terminal would)
9
+ * 3. Renders the screen content in multiple output formats
10
+ *
11
+ * The emulator faithfully implements the VT100/VT220/xterm protocol —
12
+ * cursor movement, colors (16, 256, RGB), text attributes, line wrapping,
13
+ * scrollback, alternate screen buffer, and more.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { createTerminalScreen } from "@gkoreli/ghostty-vt-js/terminal-screen-emulator";
18
+ *
19
+ * const screen = await createTerminalScreen({ columns: 120, rows: 40 });
20
+ * screen.write("\x1b[1;31mERROR\x1b[0m: connection refused\r\n");
21
+ *
22
+ * const plainText = screen.render(OutputFormat.PlainText);
23
+ * const styledHtml = screen.render(OutputFormat.Html);
24
+ *
25
+ * screen.dispose();
26
+ * ```
27
+ */
28
+ // ─── Output Format ───────────────────────────────────────────────────────────
29
+ /**
30
+ * Determines how the terminal screen content is rendered to a string.
31
+ *
32
+ * Each format serves a different consumer:
33
+ * - `PlainText` — for AI agents that need just the text content
34
+ * - `AnsiEscapes` — for piping to another terminal or tool that understands VT
35
+ * - `Html` — for rendering in a browser, documentation, or rich UI
36
+ */
37
+ export var OutputFormat;
38
+ (function (OutputFormat) {
39
+ /**
40
+ * Plain text with no formatting.
41
+ *
42
+ * All escape sequences are stripped. Only the visible character content
43
+ * remains. Useful for text search, AI agent consumption, or logging.
44
+ *
45
+ * @example "ERROR: connection refused\nRetrying in 5s..."
46
+ */
47
+ OutputFormat[OutputFormat["PlainText"] = 0] = "PlainText";
48
+ /**
49
+ * ANSI/VT escape sequences preserved.
50
+ *
51
+ * The output contains the same escape sequences that produced the screen
52
+ * content. Useful for piping to another terminal, `less -R`, or tools
53
+ * that understand ANSI color codes.
54
+ *
55
+ * @example "\x1b[1;31mERROR\x1b[0m: connection refused"
56
+ */
57
+ OutputFormat[OutputFormat["AnsiEscapes"] = 1] = "AnsiEscapes";
58
+ /**
59
+ * HTML with inline CSS styles.
60
+ *
61
+ * Each styled span becomes a `<span style="...">` element. Colors are
62
+ * rendered as CSS `color` and `background-color`. Bold, italic, underline,
63
+ * and other attributes become corresponding CSS properties.
64
+ *
65
+ * @example '<span style="font-weight: bold; color: #ff0000">ERROR</span>: connection refused'
66
+ */
67
+ OutputFormat[OutputFormat["Html"] = 2] = "Html";
68
+ })(OutputFormat || (OutputFormat = {}));
69
+ // ─── Text Attribute Types ────────────────────────────────────────────────────
70
+ /**
71
+ * The style of underline decoration applied to text.
72
+ *
73
+ * Modern terminals support multiple underline styles via the SGR 4:x
74
+ * sub-parameter syntax (e.g., `ESC[4:3m` for curly underline).
75
+ */
76
+ export var UnderlineStyle;
77
+ (function (UnderlineStyle) {
78
+ /** No underline. */
79
+ UnderlineStyle[UnderlineStyle["None"] = 0] = "None";
80
+ /** Standard single underline (SGR 4). */
81
+ UnderlineStyle[UnderlineStyle["Single"] = 1] = "Single";
82
+ /** Double underline (SGR 21 or SGR 4:2). */
83
+ UnderlineStyle[UnderlineStyle["Double"] = 2] = "Double";
84
+ /** Curly/wavy underline (SGR 4:3) — commonly used for spelling errors. */
85
+ UnderlineStyle[UnderlineStyle["Curly"] = 3] = "Curly";
86
+ /** Dotted underline (SGR 4:4). */
87
+ UnderlineStyle[UnderlineStyle["Dotted"] = 4] = "Dotted";
88
+ /** Dashed underline (SGR 4:5). */
89
+ UnderlineStyle[UnderlineStyle["Dashed"] = 5] = "Dashed";
90
+ })(UnderlineStyle || (UnderlineStyle = {}));
91
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/terminal-screen-emulator/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,YAgCX;AAhCD,WAAY,YAAY;IACtB;;;;;;;OAOG;IACH,yDAAa,CAAA;IAEb;;;;;;;;OAQG;IACH,6DAAe,CAAA;IAEf;;;;;;;;OAQG;IACH,+CAAQ,CAAA;AACV,CAAC,EAhCW,YAAY,KAAZ,YAAY,QAgCvB;AAoQD,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,CAAN,IAAY,cAaX;AAbD,WAAY,cAAc;IACxB,oBAAoB;IACpB,mDAAQ,CAAA;IACR,yCAAyC;IACzC,uDAAU,CAAA;IACV,4CAA4C;IAC5C,uDAAU,CAAA;IACV,0EAA0E;IAC1E,qDAAS,CAAA;IACT,kCAAkC;IAClC,uDAAU,CAAA;IACV,kCAAkC;IAClC,uDAAU,CAAA;AACZ,CAAC,EAbW,cAAc,KAAd,cAAc,QAazB"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @module terminal-screen-emulator/wasm-loader
3
+ *
4
+ * Node-specific WASM loader for the Ghostty terminal emulator binary.
5
+ *
6
+ * This module handles:
7
+ * 1. Locating the `ghostty-vt.wasm` binary on disk (Node `fs.readFile`)
8
+ * 2. Delegating compilation, caching, and instantiation to the shared
9
+ * platform-agnostic helpers in `../wasm/`
10
+ *
11
+ * The platform-agnostic pieces (the `GhosttyWasmExports` interface,
12
+ * `WasmEmulatorInstance`, struct layout types, and the compile/instantiate
13
+ * boilerplate) live under `../wasm/` so they can be reused by a browser-side
14
+ * loader without duplication.
15
+ *
16
+ * The WASM binary is compiled once and cached — subsequent calls to
17
+ * {@link instantiateEmulator} reuse the compiled module, which is
18
+ * significantly faster than recompiling each time.
19
+ *
20
+ * @internal This module is not part of the public API.
21
+ */
22
+ import { type WasmEmulatorInstance } from "../wasm/compile.js";
23
+ export type { GhosttyWasmExports } from "../wasm/exports.js";
24
+ export type { StructFieldLayout, StructLayout, WasmTypeLayouts, } from "../wasm/type-layouts.js";
25
+ export type { WasmEmulatorInstance } from "../wasm/compile.js";
26
+ export { resetWasmCache } from "../wasm/compile.js";
27
+ /**
28
+ * Pre-load the ghostty-vt WASM bytes so subsequent `instantiateEmulator()`
29
+ * calls skip the disk search.
30
+ *
31
+ * Intended for compiled-binary embedders (e.g. Bun `--compile`) that already
32
+ * have the bytes in memory via their own asset-embedding mechanism. Calling
33
+ * this resets the per-process compilation cache so the next instantiate call
34
+ * compiles the freshly preloaded bytes.
35
+ *
36
+ * @param bytes - The raw WASM binary bytes. Must be a `Uint8Array` whose
37
+ * backing buffer is a real `ArrayBuffer` (not
38
+ * `SharedArrayBuffer`) — same constraint that `readFile`
39
+ * satisfies internally.
40
+ *
41
+ * @example Bun standalone executable
42
+ * ```ts
43
+ * import wasmPath from "@gkoreli/ghostty-vt-js/wasm" with { type: "file" };
44
+ * import { preloadEmulatorWasm } from "@gkoreli/ghostty-vt-js/terminal-screen-emulator";
45
+ *
46
+ * const bytes = new Uint8Array(await Bun.file(wasmPath).arrayBuffer());
47
+ * preloadEmulatorWasm(bytes);
48
+ * ```
49
+ */
50
+ export declare function preloadEmulatorWasm(bytes: Uint8Array<ArrayBuffer>): void;
51
+ /**
52
+ * Create a new WASM emulator instance.
53
+ *
54
+ * Each instance has its own WASM linear memory and can operate independently.
55
+ * Multiple instances can exist simultaneously without interference.
56
+ *
57
+ * The underlying WASM module is compiled once (singleton) and reused across
58
+ * all instances — only instantiation happens per call.
59
+ *
60
+ * @returns A ready-to-use WASM emulator instance with parsed type layouts.
61
+ * @throws {Error} If the WASM binary cannot be found or fails to compile.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const instance = await instantiateEmulator();
66
+ * // instance.exports — raw WASM functions
67
+ * // instance.typeLayouts — struct field offsets for safe memory access
68
+ * ```
69
+ */
70
+ export declare function instantiateEmulator(): Promise<WasmEmulatorInstance>;
71
+ //# sourceMappingURL=wasm-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-loader.d.ts","sourceRoot":"","sources":["../../src/terminal-screen-emulator/wasm-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,oBAAoB,CAAC;AAQ5B,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,eAAe,GAChB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AA4FpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAKxE;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAIzE"}