interactive

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: AGPL-3.0 Imports: 6 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 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

View Source
const MaxRows = 30

MaxRows is how many rows a list shows at once, as the line prompts do (promptMaxRows); typing narrows it.

Variables

This section is empty.

Functions

func Draw

func Draw(l *List, s Style) []string

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

func DrawForm(f *Form, s Style) []string

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

func DrawReview(r *Review, s Style) []string

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 Answers

type Answers = map[string]string

Answers are a form's answers by field key.

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.

func NewForm

func NewForm(title string, fields []Field) *Form

NewForm is a form on its first field.

func (*Form) AtMore

func (f *Form) AtMore() bool

AtMore says whether the form asks whether to see more options.

func (*Form) Field

func (f *Form) Field() Field

Field is the field being filled; the zero Field on the more-options step.

func (*Form) Key

func (f *Form) Key(k term.Key) (Result, Answers)

Key applies one key. Take comes with the answers: only shown fields that have a value.

func (*Form) Text

func (f *Form) Text() string

Text is what is typed into the field being filled.

type List

type List struct {
	Question string
	Help     string
	Rows     []Row
	Free     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).

func NewList

func NewList(question, help string, rows []Row, free bool) *List

NewList is a list of rows with nothing typed, the first row highlighted.

func (*List) Current

func (l *List) Current() Row

Current is the highlighted row; the zero Row when nothing is shown.

func (*List) Fit

func (l *List) Fit(height int)

Fit sets the page to a window of height rows: at most MaxRows, at least one.

func (*List) Key

func (l *List) Key(k term.Key) (Result, string)

Key applies one key. Take comes with the value taken.

func (*List) Shown

func (l *List) Shown() []Row

Shown is the rows that match the search: on name and detail, ignoring case, the same match as the line prompts.

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 (m *Menu) Key(k term.Key) (Result, capability.Leaf)

Key applies one key. Take comes with the leaf taken.

func (m *Menu) List() *List

List is the level shown, for Draw.

type Result

type Result int

Result is what a key did to a screen.

const (
	Stay Result = iota // nothing ends: draw again
	Take               // a value was taken
	Back               // Esc on an empty search: one level back
	Quit               // Ctrl-C: nothing runs
)

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.

func NewReview

func NewReview(line string) *Review

NewReview shows line, the words after komando.

func (*Review) Key

func (r *Review) Key(k term.Key) Result

Key applies one key: Enter runs the line, Esc goes back to the form, Ctrl-C quits.

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

type Style struct {
	Width int
	Color bool
}

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).

Jump to

Keyboard shortcuts

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