package server import "git.a-wan.net/alan/pipelines/internal/protocol" // A machine terminal's output also feeds a headless emulator // (internal/termstate), under the same lock as the retained tail, so its // state always belongs to the tail's end. A client that reads from before // the tail (a new page, a reload, a reconnect after the tail moved on, a // gap) would otherwise redraw from an arbitrary cut: a full-screen program // that wrote more than the tail since it started would land on the main // screen, and its modes (mouse, bracketed paste, cursor keys, ...) would be // lost. Such a read gets the emulator's snapshot instead: an escape // sequence stream that resets the client's emulator and redraws the // scrollback, the main screen, the alternate screen when in use, the // cursor, the modes and the pen, as of OutputEnd; the frames that follow // start there. A read inside the tail (an ordinary resume, or a stream not // longer than the tail) gets the raw bytes as before. // retainedFromLocked is where the retained tail starts: the newest // TerminalRetained bytes (the buffer may hold more until it compacts). func (p *terminalProcess) retainedFromLocked() int64 { return max(p.out.start, p.out.total-protocol.TerminalRetained) } // screenLocked sets record's output to the screen's snapshot. p.mu is held. func (p *terminalProcess) screenLocked(record *protocol.TerminalRecord) { snap, partial := p.screen.Snapshot() end := p.out.total if !p.outDone { // An unfinished character is left out of the snapshot and sent // whole in the next frame. end -= int64(partial) } record.Output = validChatShellText(snap) record.OutputStart, record.OutputEnd = end, end record.OutputSnapshot = true }