MCPcopy Create free account
hub / github.com/coder/ghostty-web / GhosttyTerminal

Class GhosttyTerminal

lib/ghostty.ts:254–789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252 * - No per-row WASM boundary crossings!
253 */
254export class GhosttyTerminal {
255 private exports: GhosttyWasmExports;
256 private memory: WebAssembly.Memory;
257 private handle: TerminalHandle;
258 private _cols: number;
259 private _rows: number;
260
261 /** Size of GhosttyCell in WASM (16 bytes) */
262 private static readonly CELL_SIZE = 16;
263
264 /** Reusable buffer for viewport operations */
265 private viewportBufferPtr: number = 0;
266 private viewportBufferSize: number = 0;
267
268 /** Cell pool for zero-allocation rendering */
269 private cellPool: GhosttyCell[] = [];
270
271 constructor(
272 exports: GhosttyWasmExports,
273 memory: WebAssembly.Memory,
274 cols: number = 80,
275 rows: number = 24,
276 config?: GhosttyTerminalConfig
277 ) {
278 this.exports = exports;
279 this.memory = memory;
280 this._cols = cols;
281 this._rows = rows;
282
283 if (config) {
284 // Allocate config struct in WASM memory
285 const configPtr = this.exports.ghostty_wasm_alloc_u8_array(GHOSTTY_CONFIG_SIZE);
286 if (configPtr === 0) {
287 throw new Error('Failed to allocate config (out of memory)');
288 }
289
290 try {
291 // Write config to WASM memory
292 const view = new DataView(this.memory.buffer);
293 let offset = configPtr;
294
295 // scrollback_limit (u32)
296 view.setUint32(offset, config.scrollbackLimit ?? 10000, true);
297 offset += 4;
298
299 // fg_color (u32)
300 view.setUint32(offset, config.fgColor ?? 0, true);
301 offset += 4;
302
303 // bg_color (u32)
304 view.setUint32(offset, config.bgColor ?? 0, true);
305 offset += 4;
306
307 // cursor_color (u32)
308 view.setUint32(offset, config.cursorColor ?? 0, true);
309 offset += 4;
310
311 // palette[16] (u32 * 16)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…