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

Class BufferLine

lib/buffer.ts:219–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217 * A single line in the buffer
218 */
219export class BufferLine implements IBufferLine {
220 private cells: GhosttyCell[];
221 private _isWrapped: boolean;
222 private _length: number;
223
224 constructor(cells: GhosttyCell[], isWrapped: boolean, length: number) {
225 this.cells = cells;
226 this._isWrapped = isWrapped;
227 this._length = length;
228 }
229
230 get length(): number {
231 return this._length;
232 }
233
234 get isWrapped(): boolean {
235 return this._isWrapped;
236 }
237
238 getCell(x: number): IBufferCell | undefined {
239 if (x < 0 || x >= this._length) {
240 return undefined;
241 }
242
243 if (x >= this.cells.length) {
244 // Cell beyond what was returned (empty/null cell)
245 return new BufferCell(
246 {
247 codepoint: 0,
248 fg_r: 204,
249 fg_g: 204,
250 fg_b: 204,
251 bg_r: 0,
252 bg_g: 0,
253 bg_b: 0,
254 flags: 0,
255 width: 1,
256 hyperlink_id: 0,
257 grapheme_len: 0,
258 },
259 x
260 );
261 }
262
263 return new BufferCell(this.cells[x], x);
264 }
265
266 translateToString(trimRight = false, startColumn = 0, endColumn = this._length): string {
267 // Clamp bounds
268 const start = Math.max(0, Math.min(startColumn, this._length));
269 const end = Math.max(start, Math.min(endColumn, this._length));
270
271 let result = '';
272 for (let x = start; x < end; x++) {
273 const cell = this.getCell(x);
274 if (cell) {
275 const chars = cell.getChars();
276 result += chars;

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…