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 ¶
- func IsTerminal(f *os.File) bool
- func ResetTermModes(stdout *os.File)
- func Tail(p string, n int) string
- func Wrap(s string, width int) string
- type UI
- func (u *UI) Ask(prompt, def string) string
- func (u *UI) AskChoice(prompt string, def int, options ...string) int
- func (u *UI) AskInt(prompt string, def, max int) int
- func (u *UI) AskYN(prompt string, def bool) bool
- func (u *UI) Box(title, body string)
- func (u *UI) CanAsk() bool
- func (u *UI) HaveTTY() bool
- func (u *UI) NewWindow(out io.Writer, log io.Writer) *Window
- type Window
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResetTermModes ¶
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.
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 (*UI) AskInt ¶
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) Box ¶
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 ¶
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.
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.