Documentation
¶
Overview ¶
Package interactive is komando's interactive mode: the screens that help a person build a command line (C162). It returns the line as argv; internal/cli runs it as if it was typed, so every check of a typed line still applies. It reads keys and draws, nothing more: no command runs here (TestInteractiveImports).
Index ¶
- Constants
- Variables
- func Build(t Terminal, leaves []capability.Leaf, o Options) ([]string, error)
- func Draw(l *List, s Style) []string
- func DrawForm(f *Form, s Style) []string
- func DrawReview(r *Review, s Style) []string
- type Answers
- type Field
- type Form
- type List
- type Menu
- type Options
- type Result
- type Review
- type Row
- type Style
- type Terminal
Constants ¶
const MaxRows = 30
MaxRows is how many rows a list shows at once, as the line prompts do (promptMaxRows); typing narrows it.
Variables ¶
var ( // ErrQuit: Esc at the top of the menu. Nothing runs, nothing is said. ErrQuit = errors.New("left the menu") // ErrStop: Ctrl-C. Nothing runs. ErrStop = errors.New("stopped at the menu") )
Functions ¶
func Build ¶ added in v0.18.2
Build shows the menu of the command tree and returns the words of the command a person took, as they would have typed them. It only builds a line: it runs nothing, and a value is never part of it (a command's arguments are asked for by the line prompts that follow, as for a typed line). ErrQuit is Esc at the top, ErrStop Ctrl-C; any other error is the terminal's (term.ErrIdle, term.ErrTooSmall, io.EOF), which has put the terminal back already. On every way out the rows drawn are cleared.
func Draw ¶
Draw is the list as lines, top to bottom, in an order that never changes: the question with what was typed, the help when asked for, the rows of the page, a line under them when there is something to say, and the key line. It only reads l.
func DrawForm ¶
DrawForm is the form as lines: the command's words, then the field being filled (a list as Draw shows it, or the question with what is typed), then its key line. It only reads f.
func DrawReview ¶
DrawReview is the review as lines: the question, the whole line with a $ first, then its keys. A line wider than the window wraps; no part of it is cut, so what runs is what was shown.
Types ¶
type Field ¶
type Field struct {
Key string // the answer's key: arg0, arg1 ... or flag:NAME
Ask string // the question
Help string
Required bool
Free bool // with Rows: other text may be typed (tag:prod)
Advanced bool // asked only after "more options"
Default func(Answers) string // what an empty Enter takes; nil: nothing
Rows func(Answers) []Row // the list it is picked from; nil: typed
Show func(Answers) bool // asked only while true; nil: always
// Check is why an answer is refused; "" takes it.
Check func(a Answers, v string) string
// Clean takes a password out of a pasted address (user:password@);
// found says one was there. The screen never draws it.
Clean func(v string) (clean string, found bool)
}
Field is one question of a form, as internal/cli describes it from the command and its form hint. A secret or a value komando makes is never a field: internal/cli leaves those out. The functions read the answers given so far and nothing else may change through them.
type Form ¶
type Form struct {
Title string
// contains filtered or unexported fields
}
Form asks a command's fields one after another: the required ones first, then the other main ones; the advanced ones only when the person asks for more options. Its answers go back to internal/cli, which builds the line.
type List ¶
type List struct {
Question string
Help string
Rows []Row
Free bool
// Banner is drawn above the question: the first screen's name and what
// the tool does.
Banner []string
// Numbered draws the number of each row, and a digit typed on an empty
// search jumps to that row (more digits make a longer number). Text a
// person types in a list of names is search, so only the menu is numbered.
Numbered bool
// EscQuits says Esc leaves the screen instead of going back: the top
// level of the menu.
EscQuits bool
// contains filtered or unexported fields
}
List is a list with type-to-search. Free: when no row matches, Enter takes the typed text as it is (a selector such as @web or tag:prod).
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
Menu is the first screen: the command tree of the capability table as nested lists, one level per word a person types. Enter on a word opens the words after it; Enter on a whole command takes it.
func NewMenu ¶
func NewMenu(leaves []capability.Leaf) *Menu
NewMenu is the tree of the built leaves, at its top level.
func (*Menu) Fit ¶ added in v0.18.2
Fit fits the level shown, and every level after it, to a window of height rows.
type Options ¶ added in v0.18.2
Options are how Build draws the first screen: Color shows the highlighted row in reverse video too (never by colour alone: it starts with > either way), and Banner is the name and what komando does, above the question.
type Review ¶
type Review struct {
// contains filtered or unexported fields
}
Review is the last screen: the line built from the answers, as internal/cli prints it (quoted, secrets masked), before it runs.
type Row ¶
type Row struct {
Value, Label, Detail string
}
Row is one entry of a list: the value it stands for, the name shown and a detail beside it.
type Style ¶
Style is how a screen is drawn: the window's width, and whether the highlighted row is also shown in reverse video (never by colour alone: it starts with > either way).
type Terminal ¶ added in v0.18.2
type Terminal interface {
ReadKey() (term.Key, error)
Write(p []byte) (int, error)
Size() (w, h int)
Suspend() error
}
Terminal is the screen session Build drives. *term.Screen is one; tests use a fake with no terminal behind it. Build never opens or restores the terminal: whoever opened it restores it, on every way out.