ui

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 8 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 ui asks questions on the terminal and prints agent-vm's boxed notices, as 0.2's lib/ui.sh did.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal reports whether f is a terminal.

func ResetTermModes

func ResetTermModes(stdout *os.File)

ResetTermModes turns off the input modes a full-screen program in the VM may have left on when it was killed or its connection dropped: mouse tracking, focus reports, bracketed paste, the kitty keyboard protocol and xterm's modifyOtherKeys, each of which types escape sequences into the host shell otherwise. Also shows the cursor. Only on a terminal.

func Tail

func Tail(p string, n int) string

Tail is the last n lines of the file at p, for when a step failed and its window is gone. Cleaned as the window cleans them: the log holds what the guest printed, and printing it raw would let it drive the terminal.

func Wrap

func Wrap(s string, width int) string

Wrap word-wraps s to width columns. Lines indented by two spaces are commands, kept whole so they can be copied.

Types

type UI

type UI struct {
	Stderr io.Writer
	// OpenTTY opens the terminal answers are read from (the process's
	// own when nil; tests set their own).
	OpenTTY func() (io.ReadCloser, error)
	// StderrIsTerminal: where the questions go is seen by someone.
	StderrIsTerminal bool
	// Width of the terminal, for boxes; 0 asks the terminal.
	Width int
}

UI asks on the controlling terminal and writes questions to Stderr.

func New

func New() *UI

New is the UI of this process.

func (*UI) Ask

func (u *UI) Ask(prompt, def string) string

Ask asks for a value, def when the answer is empty.

func (*UI) AskChoice

func (u *UI) AskChoice(prompt string, def int, options ...string) int

AskChoice lists options, numbered from 1, and returns the number picked.

func (*UI) AskInt

func (u *UI) AskInt(prompt string, def, max int) int

AskInt asks for a positive integer, at most max when max > 0, until it gets one: a typo such as "10G" is caught here.

func (*UI) AskYN

func (u *UI) AskYN(prompt string, def bool) bool

AskYN asks a yes/no question; an empty answer is def.

func (*UI) Box

func (u *UI) Box(title, body string)

Box prints body on Stderr as a boxed notice, for the warnings and offers of setup and of a start: one paragraph per line, wrapped to the terminal (72 columns at most). No right border: it would need every line padded to its display width, unknown for non-ASCII text.

func (*UI) CanAsk

func (u *UI) CanAsk() bool

CanAsk reports whether a question can be asked and seen: a terminal to read the answer from, and stderr on a terminal too, or a caller capturing stderr would wait on a question nobody sees.

func (*UI) HaveTTY

func (u *UI) HaveTTY() bool

HaveTTY reports whether a terminal can be opened: a device node that exists does not say it (CI, cron), only opening it does.

func (*UI) NewWindow

func (u *UI) NewWindow(out io.Writer, log io.Writer) *Window

NewWindow writes to out, a terminal or not, and to log.

type Window

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

Window copies what is written to log and, on a terminal, shows only the last lines, redrawn in place and cleared at Close; elsewhere it passes every line through. Lines are cut to the terminal's width, since a wrapped one would break the redraw, and colour codes are dropped, since a cut one would leave the terminal coloured.

func (*Window) Close

func (w *Window) Close()

Close shows a last line without a newline, then clears the window.

func (*Window) Write

func (w *Window) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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