screen

package
v0.1.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package screen renders a terminal byte stream into the grid of cells a person would actually see.

Relayer's detection has always normalized a byte stream: escape sequences are stripped and the surviving bytes kept in write order. That is exact for an agent that only appends, and wrong for one that repaints. The cursor movements that say WHERE each fragment lands are discarded, and the erases that say what is no longer on screen are discarded with them — so a question the agent has already withdrawn is still matchable, and a question painted into a frame is concatenated in write order instead of landing inside it.

The parser is deliberately TOTAL: every CSI, OSC, DCS, SOS, PM and APC sequence is recognised and consumed, even the ones the screen does nothing with. Acting on a small set is safe; failing to RECOGNISE a sequence is not, because its bytes would then be printed as text — and an unrecognised erase leaves stale cells live, which is the exact failure this package exists to remove. The recognition comes from github.com/charmbracelet/x/ansi, already in the module graph by way of bubbletea, so the riskiest part is not hand-written here.

Index

Constants

View Source
const (
	MinWidth      = 2
	MinHeight     = 1
	MaxWidth      = 1000
	MaxHeight     = 500
	MaxScrollback = 512
)

Bounds on what one screen may hold, so a hostile or broken agent cannot make Relayer allocate without limit.

Variables

This section is empty.

Functions

This section is empty.

Types

type Screen

type Screen struct {
	// contains filtered or unexported fields
}

Screen is one terminal's visible grid plus a bounded scrollback. It is not safe for concurrent use; the caller owns the lock, as Processor already does.

func New

func New(width, height int) *Screen

New creates a screen. A width or height outside the supported range is clamped rather than rejected: a caller that has not measured its terminal yet still needs somewhere to put output.

func (*Screen) CursorLine

func (s *Screen) CursorLine() string

CursorLine reports the logical line the cursor sits on, which is where an agent that has stopped to ask leaves its question.

func (*Screen) Resize

func (s *Screen) Resize(width, height int)

Resize adapts the grid to a new terminal size, keeping what fits.

func (*Screen) Size

func (s *Screen) Size() (width, height int)

Size reports the current grid dimensions.

func (*Screen) Text

func (s *Screen) Text() string

Text renders the screen as the operator sees it: scrollback first, then the live grid, with rows joined where they wrapped so a sentence broken by the right margin is one line again. Trailing blank rows are dropped, because a mostly empty screen is not the same as a screen full of blank lines.

func (*Screen) Write

func (s *Screen) Write(data []byte) (int, error)

Write feeds raw terminal bytes, escape sequences included.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL