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 ¶
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.
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.
const TickEvery = time.Second
TickEvery is how often a view is told of the time.
Variables ¶
This section is empty.
Functions ¶
func KeyLine ¶
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 ¶
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 ShownView ¶
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 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 ¶
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. |