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

Class Buffer

lib/buffer.ts:96–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94 * A terminal buffer (normal or alternate screen)
95 */
96export class Buffer implements IBuffer {
97 private terminal: Terminal;
98 private bufferType: 'normal' | 'alternate';
99 private nullCell: BufferCell;
100
101 constructor(terminal: Terminal, type: 'normal' | 'alternate') {
102 this.terminal = terminal;
103 this.bufferType = type;
104
105 // Create a null cell (codepoint=0, default colors, no flags)
106 const nullCellData: GhosttyCell = {
107 codepoint: 0,
108 fg_r: 204,
109 fg_g: 204,
110 fg_b: 204,
111 bg_r: 0,
112 bg_g: 0,
113 bg_b: 0,
114 flags: 0,
115 width: 1,
116 hyperlink_id: 0,
117 grapheme_len: 0,
118 };
119 this.nullCell = new BufferCell(nullCellData, 0);
120 }
121
122 get type(): 'normal' | 'alternate' {
123 return this.bufferType;
124 }
125
126 get cursorX(): number {
127 const wasmTerm = this.getWasmTerm();
128 if (!wasmTerm) return 0;
129 return wasmTerm.getCursor().x;
130 }
131
132 get cursorY(): number {
133 const wasmTerm = this.getWasmTerm();
134 if (!wasmTerm) return 0;
135 return wasmTerm.getCursor().y;
136 }
137
138 get viewportY(): number {
139 // Get viewport offset from Terminal
140 // For now, return 0 (no scrollback navigation implemented yet)
141 return 0;
142 }
143
144 get baseY(): number {
145 // For normal buffer: 0
146 // For alternate buffer: 0 (alternate has no scrollback)
147 return 0;
148 }
149
150 get length(): number {
151 const wasmTerm = this.getWasmTerm();
152 if (!wasmTerm) return 0;
153

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…