screen

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 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 is the full-screen surface home draws on (design/terminal-ui.md, "The full-screen views"): the terminal's alternate screen, entered and left so the terminal ends as it was, a view drawn whole into it and drawn again on every key, resize and second, and the person's Ctrl-Z. It holds the key line too.

Index

Constants

View Source
const (
	Enter = enterScreen + hideCursor
	Leave = leaveScreen + showCursor
)

Enter and Leave are what the surface writes as it takes the alternate screen, and as it gives it back with the cursor shown.

View Source
const LeastCols = flow.LeastWidth

LeastCols is the fewest columns a full-screen view is laid out at: a narrower terminal is drawn as at these, and shows what fits. A view is laid out at the terminal's own height, however short.

View Source
const TickEvery = time.Second

TickEvery is how often a view is told of the time.

Variables

This section is empty.

Functions

func KeyLine

func KeyLine(width int, keys []Key, drop ...string) ink.Row

KeyLine is keys laid out as a view's last row, width wide, from column 1: each key bold in the accent, what it does faint, three spaces between. Short of room, the keys drop names go first, in its order, then the rest from the right; the last, quit, always stays.

func Write

func Write(rows []ink.Row, size Size, pal ink.Palette) string

Write is rows as the surface writes them to a terminal of size, in one write: from its top left, each row drawn and the rest of it erased, cut to the terminal's width, as many as it has rows, and where they're fewer, the screen erased below them, from the row after. A row that fills its line has nothing after it to erase: a terminal waiting to wrap there would erase its last cell.

Types

type Key

type Key struct {
	Key, Does string
}

Key is a key and what it does, in a key line.

type ShownView

type ShownView interface {
	View
	Shown(at time.Time)
}

ShownView is a view told when the frame it last drew is on the screen: once the frame's write returns, or once it's found the same as the frame on the screen and written again not at all. A key read before then was typed at the frame before.

type Size

type Size struct {
	Cols, Rows int
}

Size is a terminal's size, in columns and rows.

func (Size) Laid

func (s Size) Laid() Size

Laid is the size a view is laid out at on a terminal of s.

type Surface

type Surface struct {
	Out io.Writer
	Pal ink.Palette
	// Size is the terminal's size now, read again at every draw.
	Size func() Size
	Now  func() time.Time
	// Keyboard is the keys typed, and Ctrl-Z.
	Keyboard flow.Keyboard
	// Resizes tells of each change to the terminal's size; nil tells of
	// none, and the view is drawn at its new size at the next key or tick.
	Resizes <-chan os.Signal
	// Foreground reports whether the process is in the terminal's
	// foreground, and Resume sets the keys to be read again once it is: a
	// process continued in the background, as bg continues it, takes the
	// screen back only once it's brought to the foreground. nil Foreground,
	// it always is; nil Resume, the keys need nothing.
	Foreground func() bool
	Resume     func() error
	// contains filtered or unexported fields
}

Surface draws a view on the terminal's alternate screen until the view is done, its context ends, or the terminal hangs up, and leaves the terminal as it was however it ends, a panic included.

func (*Surface) Run

func (s *Surface) Run(ctx context.Context, v View) (err error)

Run draws v until it's done or ctx ends. Every key read before the frame that took the screen was on it, as Run starts, as the process is back in the foreground after Ctrl-Z, and as the terminal is resized, is thrown away, as a question's are (decision 38); so is one read while the screen is the shell's. A terminal that hung up, as a signal ending ctx says or as it did while the process was stopped, is no failure: it's left as it can be. A screen already given back to the shell isn't given back again.

type View

type View interface {
	Draw(size Size, now time.Time) []ink.Row
	// Key takes k, and reports whether the view is done.
	Key(ctx context.Context, k terminal.Key) (bool, error)
	Tick(ctx context.Context, now time.Time) error
}

View is what the surface draws: laid out whole at a size, as it stands at a moment; taking the keys typed at it; and told of each second, to read again what it shows.

Directories

Path Synopsis
Package screentest is the capture tool for the full-screen views (design/terminal-ui.md, "Testing"): it drives a real view, every seam it reads faked by its caller, as the surface does, through the keys a fixture names, and gives the frame it draws.
Package screentest is the capture tool for the full-screen views (design/terminal-ui.md, "Testing"): it drives a real view, every seam it reads faked by its caller, as the surface does, through the keys a fixture names, and gives the frame it draws.

Jump to

Keyboard shortcuts

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