Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callback ¶
Callback to notify when input changes
Receives the input value and whether a tab was just pressed. Called in-line with each key press so heavy processing should be done outside of the callback path.
Callback is initialized with zero-values before keypresses are read. This is gives you a chance to show full output up front, and let user input reduce it.
Tab and Enter keypresses will set the respective booleans. The input text will be passed as well.
It's possible to split Callback into onKeypress, onTab, and onEnter. If this is something you want please submit an issue on the repo. :)
type ClosestMatch ¶
type ClosestMatch struct { Data map[string]string OnSelect func(string) MaxShown int // default: "Use <TAB> and <ENTER> to select from below. Otherwise press <ENTER> when ready" Instructions string ShowInstructions bool // default: FgBlue SelectedColor *color.Color // default: FgHiBlack InstructionColor *color.Color }
ClosestMatch configures a callback to let users select from a set of options
Data's keys are used as titles, and shown on-screen. The values can be used to give additional ranking. For example, you might want to show ticket names but use their summaries for more accurate matching.
onSelect will be called when user presses Enter. If they made a selection, the string arg will be equal to one of the keys in Data. Otherwise it's the raw value of the prompt.
func (*ClosestMatch) CB ¶
func (c *ClosestMatch) CB() Callback
CB returns a configured callback to use with Prompt
type Prompt ¶
type Prompt struct { // What the user sees in front of their input Prefix string Callback Callback // Lines between the prompt and output from callback (default: 2) Padding int // Keep the value of text and pos variables on screen Debug bool // contains filtered or unexported fields }
Prompt lets a user type input that is sent to a callback in realtime
Callback is invoked when the input changes or Tab or Enter are pressed. The return value is shown below the prompt and rewritten when changed.
This allows for a reactive CLI that isn't full-on curses/TUI. It should feel like a normal tool.
func (*Prompt) Wait ¶
func (p *Prompt) Wait()
Wait begins the prompt and feeds updates into the callback until Enter is pressed.
The terminal is put into raw mode until this returns. Avoid writing to stdout/stderr until then else it will throw off the formatting. Badly.
Most of the logic making it feel like a normal prompt is from careful repositioning of the ANSI cursor.