screen

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package screen draws the terminal UI's area below the conversation, and writes the conversation above it, as Codex's TUI does (ADR 0033).

The conversation is the terminal's own scrollback: lines written once, above the area, never drawn again. The area (what is being written, the calls under way, the input, the status line) is drawn again at each frame. The area's place on the terminal is kept here:

  • The conversation's lines are written in a scroll region from the top of the terminal to just above the area: only that region scrolls, and the area stays where it is.
  • Where the area is not at the bottom of the terminal (a terminal just started, the area got shorter), it is first pushed down by reverse scrolls, by the lines to write (to the bottom at most).
  • The area getting taller than the room below it scrolls the terminal up, its bottom at the terminal's bottom. Getting shorter at the bottom, it stays there: what is above it moves down as much, blank rows left at the terminal's top (Codex leaves its bottom up until lines written push it down; ADR 0033, 追記). Getting shorter not at the bottom, its top stays: the next lines written push it down.

So, once the terminal is full, the area's bottom (the input, the status line) stays at the terminal's bottom.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Size

func Size(out *os.File) (w, h int, err error)

Size is the terminal's size in cells.

Types

type Cursor

type Cursor struct {
	X, Y  int
	Color string
	Style int
}

Cursor is where the cursor is shown, in the area (nil: hidden), its colour ("#rrggbb", "" the terminal's) and its style (DECSCUSR: 1 a blinking block, 2 a steady one, ..., 0 the terminal's).

type Screen

type Screen struct {

	// Term is the terminal taken (raw mode, modes), given back to a command
	// the UI runs in it and taken again (Retake).
	Term *Terminal

	// NoRegions: the terminal's scroll regions are not to be relied on
	// (Zellij): lines are written where the area is, and it is drawn again
	// under them, as Codex writes there.
	NoRegions bool
	// Trace, if set, is given each write and the area's place after it
	// (KAIROCODE_TUI_TRACE: what the terminal was sent, to find out what it
	// did otherwise than the tests' terminal).
	Trace io.Writer
	// contains filtered or unexported fields
}

Screen draws on a terminal of Width × Height cells.

func New

func New(out io.Writer, w, h int) *Screen

New is a screen writing to out, a terminal of w × h cells.

func (*Screen) Clear

func (s *Screen) Clear()

Clear takes the area away (the UI leaving): the cursor is left where it began.

func (*Screen) Draw

func (s *Screen) Draw(lines []string, cur *Cursor)

Draw draws the area: lines (each at most as wide as the terminal), the cursor at cur.

func (*Screen) DrawAlt

func (s *Screen) DrawAlt(lines []string, cur *Cursor)

DrawAlt draws a screen of its own (the terminal's alternate screen), lines from its top; Draw goes back to the area.

func (*Screen) Insert

func (s *Screen) Insert(lines []string)

Insert writes lines in the conversation, above the area.

func (*Screen) Place

func (s *Screen) Place(row int)

Place says where the cursor is (its row, 0-based), as the terminal told it: where the area begins when the UI starts. After a resize, it is where the cell the cursor was left on went: the area's old self begins as many rows above as its lines before that cell now take, and is cleared from there (a terminal that wrapped them again has them take more rows).

func (*Screen) Placed

func (s *Screen) Placed() bool

Placed says whether the area's place is known (Draw draws nothing before).

func (*Screen) Plain

func (s *Screen) Plain()

Plain has the screen write as it is, its colours not made to fit the terminal (tests).

func (*Screen) Resize

func (s *Screen) Resize(w, h int)

Resize says the terminal's new size. The terminal may have moved what it shows (most wrap its lines again): the area's place is not known until the terminal tells where the cursor went (Place), and it is drawn again whole there.

func (*Screen) Retake

func (s *Screen) Retake()

Retake takes the terminal again after a command ran in it: the area's place is not known any more (what the command wrote moved it).

func (*Screen) Size

func (s *Screen) Size() (w, h int)

Size is the terminal's size as last told.

func (*Screen) Stop

func (s *Screen) Stop()

Stop stops the UI's process as the shell's Ctrl+Z does: the area taken away and the terminal given back, until it is continued (fg); then the terminal is taken again, and the area's place asked again.

type Terminal

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

Terminal is the terminal the UI takes: its input in raw mode.

func Take

func Take(in, out *os.File) (*Terminal, error)

Take puts in in raw mode and asks the terminal for the modes; Restore undoes it.

func (*Terminal) Restore

func (t *Terminal) Restore() error

Restore puts the terminal back as it was.

func (*Terminal) Retake

func (t *Terminal) Retake()

Retake takes the terminal again, as Take did, after Restore.

func (*Terminal) Stop

func (t *Terminal) Stop()

Stop stops the process (its group), as the shell's Ctrl+Z does, until it is continued (fg): the terminal is given back first, taken again after.

Directories

Path Synopsis
Package vtest is a small terminal for tests of what internal/tui/screen writes (ADR 0033).
Package vtest is a small terminal for tests of what internal/tui/screen writes (ADR 0033).

Jump to

Keyboard shortcuts

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