zz_

app/tui/LogBuffer.ts

zzmq.dev@gmail.com/zz / app / tui / LogBuffer.ts @ d7f9d802 Download
Ladder Summary
  • file The file defines a **`LogBuffer`** class that stores log lines in a fixed‑size ring buffer, automatically trimming older entries when the configured maximum (default 4000) is exceeded. Its public API consists of a **`push(line: string): void`** method for adding new lines (splitting multi‑line strings) and an **`all`** getter that returns a read‑only array of the buffered lines. No other functions or classes are exported.
 // A capped ring buffer the work loop pushes agent activity lines into,
 // and the TUI polls on its own render interval -- simpler than real
 // pub/sub for a terminal view that's already redrawing on a timer.
 export class LogBuffer {
  private lines: string[] = [];
  constructor(private max = 4000) {}
 
  push(line: string): void {
  for (const part of line.split("\n")) this.lines.push(part);
  if (this.lines.length > this.max) this.lines.splice(0, this.lines.length - this.max);
  }
 
  get all(): readonly string[] {
  return this.lines;
  }
 }