Documentation
¶
Overview ¶
Package console drives an interactive terminal for the AI: it types one line as the user would, waits until the device or shell is back at its prompt, pages through "--More--", and stops where the terminal asks for a password or an answer. A terminal has no exit codes, so neither does a Result.
Index ¶
Constants ¶
const MaxLine = 4096
MaxLine is the longest line Line types.
Variables ¶
var ( // ErrLine is a line that is empty, too long, or has a control // character in it. ErrLine = errors.New("console: a line is one line of printable text") // ErrKey is a key Key does not press. ErrKey = errors.New("console: unknown key") )
var Keys = map[string][]byte{
"enter": {'\r'},
"space": {' '},
"q": {'q'},
"ctrl_c": {0x03},
}
Keys are what Key presses.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Timeout is the longest wait; 60 seconds.
Timeout time.Duration
// Settle is how long the output stays quiet before the cursor's line
// is read as a prompt; 300 ms.
Settle time.Duration
// Idle is how long quiet output without a prompt ends the wait; 10 s.
Idle time.Duration
// MaxPages is how many "--More--" pages are turned; 200.
MaxPages int
// MaxBytes is how much output is kept; 1 MB less 4 KB.
MaxBytes int
// Decode turns the bytes printed into text; nil takes them as UTF-8.
Decode func([]byte) string
}
Options bound a wait. Zero fields take the defaults.
type Result ¶
Result is what a line or a key printed, as text without the echo of the line typed, and how the wait for it ended.
type Status ¶
type Status string
Status is how a wait ended.
const ( // AtPrompt is back at a prompt: the command has finished. AtPrompt Status = "prompt" // Password asks for a password, which only the user types. Password Status = "password" // Question asks for an answer, as [y/n] or [confirm]. Question Status = "question" // FullScreen is a full-screen program, as an editor or less. FullScreen Status = "fullscreen" // Quiet printed nothing for a while without a prompt: it may still run. Quiet Status = "quiet" // Timeout ran out of time; the command may still run. Timeout Status = "timeout" // Limit printed more than is kept, or more pages than are turned. Limit Status = "limit" )
type Terminal ¶
type Terminal interface {
// Input is where typed bytes go, bound to the connection of the call.
Input() (io.Writer, error)
// Watch gives fn the bytes printed from now on, until stop.
Watch(fn func(p []byte)) (stop func())
// CursorLine is the text of the line the cursor is on.
CursorLine() string
// FullScreen reports a full-screen program on the alternate screen.
FullScreen() bool
}
Terminal is the terminal the console types into and reads from.