Documentation ¶
Overview ¶
Package cmd allows developers to easily build command line interpreters, inspired by the python cmd module.
Index ¶
- Variables
- type ASCIICodeBind
- type Cmd
- type Color
- type ColorOption
- type Command
- type CommandMap
- type ConsoleParser
- type ConsoleWriter
- type Document
- type ExitChecker
- type Key
- type KeyBind
- type KeyBindFunc
- type KeyBindMode
- type LivePrefixOption
- type OptArg
- type Option
- type ParserOption
- type Suggestion
- type WriterOption
Constants ¶
This section is empty.
Variables ¶
var OptionAddASCIICodeBind = prompt.OptionAddASCIICodeBind
OptionAddASCIICodeBind to set a custom key bind. OptionAddASCIICodeBind(b ...ASCIICodeBind)
var OptionAddKeyBind = prompt.OptionAddKeyBind
OptionAddKeyBind to set a custom key bind. OptionAddKeyBind(b ...KeyBind)
var OptionBreakLineCallback = prompt.OptionBreakLineCallback
OptionBreakLineCallback to run a callback at every break line OptionBreakLineCallback(fn func(*Document))
var OptionCompletionOnDown = prompt.OptionCompletionOnDown
OptionCompletionOnDown allows for Down arrow key to trigger completion. Example: OptionCompletionOnDown()
var OptionCompletionWordSeparator = prompt.OptionCompletionWordSeparator
OptionCompletionWordSeparator to set word separators. Enable only ' ' if empty.
var OptionDescriptionBGColor = prompt.OptionDescriptionBGColor
OptionDescriptionBGColor to change a background color of description text in drop down suggestions.
var OptionDescriptionTextColor = prompt.OptionDescriptionTextColor
OptionDescriptionTextColor to change a background color of description text in drop down suggestions.
var OptionHistory = prompt.OptionHistory
OptionHistory to set history expressed by string array. Example: OptionHistory([]string{"SELECT * FROM users;"})
var OptionInitialBufferText = prompt.OptionInitialBufferText
OptionInitialBufferText to set the initial buffer text
var OptionInputBGColor = prompt.OptionInputBGColor
OptionInputBGColor to change a color of background which is input by user
var OptionInputTextColor = prompt.OptionInputTextColor
OptionInputTextColor to change a color of text which is input by user
var OptionLivePrefix = prompt.OptionLivePrefix
OptionLivePrefix to change the prefix dynamically by callback function
var OptionMaxSuggestion = prompt.OptionMaxSuggestion
OptionMaxSuggestion specify the max number of displayed suggestions. Example: OptionMaxSuggestion(5)
var OptionParser = prompt.OptionParser
OptionParser to set a custom ConsoleParser object. An argument should implement ConsoleParser interface.
var OptionPrefix = prompt.OptionPrefix
OptionPrefix to set prefix string.
var OptionPrefixBackgroundColor = prompt.OptionPrefixBackgroundColor
OptionPrefixBackgroundColor to change a background color of prefix string
var OptionPrefixTextColor = prompt.OptionPrefixTextColor
OptionPrefixTextColor change a text color of prefix string
var OptionPreviewSuggestionBGColor = prompt.OptionPreviewSuggestionBGColor
OptionPreviewSuggestionBGColor to change a background color which is completed
var OptionPreviewSuggestionTextColor = prompt.OptionPreviewSuggestionTextColor
OptionPreviewSuggestionTextColor to change a text color which is completed
var OptionScrollbarBGColor = prompt.OptionScrollbarBGColor
OptionScrollbarBGColor to change a background color of scrollbar.
var OptionScrollbarThumbColor = prompt.OptionScrollbarThumbColor
OptionScrollbarThumbColor to change a thumb color on scrollbar.
var OptionSelectedDescriptionBGColor = prompt.OptionSelectedDescriptionBGColor
OptionSelectedDescriptionBGColor to change a background color of description which is selected inside suggestions drop down box.
var OptionSelectedDescriptionTextColor = prompt.OptionSelectedDescriptionTextColor
OptionSelectedDescriptionTextColor to change a text color of description which is selected inside suggestions drop down box.
var OptionSelectedSuggestionBGColor = prompt.OptionSelectedSuggestionBGColor
OptionSelectedSuggestionBGColor to change a background color for completed text which is selected inside suggestions drop down box.
var OptionSelectedSuggestionTextColor = prompt.OptionSelectedSuggestionTextColor
OptionSelectedSuggestionTextColor to change a text color for completed text which is selected inside suggestions drop down box.
var OptionShowCompletionAtStart = prompt.OptionShowCompletionAtStart
OptionShowCompletionAtStart to set completion window is open at start.
var OptionSuggestionBGColor = prompt.OptionSuggestionBGColor
OptionSuggestionBGColor change a background color in drop down suggestions.
var OptionSuggestionTextColor = prompt.OptionSuggestionTextColor
OptionSuggestionTextColor to change a text color in drop down suggestions.
var OptionSwitchKeyBindMode = prompt.OptionSwitchKeyBindMode
OptionSwitchKeyBindMode set a key bind mode. select key bindings either "emacs" or "common" Example: OptionSwitchKeyBindMode("common")
var OptionTitle = prompt.OptionTitle
OptionTitle to set title displayed at the header bar of terminal.
var OptionWriter = prompt.OptionWriter
OptionWriter to set a custom ConsoleWriter object. An argument should implement ConsoleWriter interface.
var StringOption func(x string) Option
StringOption is the function type targeting ConsoleParser parameters
Functions ¶
This section is empty.
Types ¶
type ASCIICodeBind ¶
type ASCIICodeBind = prompt.ASCIICodeBind
ASCIICodeBind represents which []byte should do what operation struct{ASCIICode []byte
Fn KeyBindFunc}
type Cmd ¶
type Cmd struct { Precmd func(line string) Postcmd func(stop bool, line string) Preloop func() Postloop func() // contains filtered or unexported fields }
Cmd The core structure of go-cmd
func NewCmd ¶
func NewCmd(cmdMap CommandMap, opts ...Option) (cmd Cmd)
NewCmd Creates and returns a new Cmd struct. Must be called before anything else.
func (*Cmd) AddCommand ¶
AddCommand Allows you to dynamically add new Commands to the shell at run time.
type Color ¶
Color represents color on terminal.
const ( // DefaultColor represents a default color. DefaultColor Color = iota // Black represents a black. Black // DarkRed represents a dark red. DarkRed // DarkGreen represents a dark green. DarkGreen // Brown represents a brown. Brown // DarkBlue represents a dark blue. DarkBlue // Purple represents a purple. Purple // Cyan represents a cyan. Cyan // LightGray represents a light gray. LightGray // DarkGray represents a dark gray. DarkGray // Red represents a red. Red // Green represents a green. Green // Yellow represents a yellow. Yellow // Blue represents a blue. Blue // Fuchsia represents a fuchsia. Fuchsia // Turquoise represents a turquoise. Turquoise // White represents a white. White )
type ColorOption ¶
ColorOption is the function type to specifically target colors parameters
type Command ¶
type Command struct { Function func(args []string) (quit bool) Description string Options map[string]OptArg }
Command Represents a terminal command. The Function is required.
type CommandMap ¶
CommandMap A mapping of the string names to Command structures
type Document ¶
Document has text displayed in terminal and cursor position.
struct { Text string // This represents a index in a rune array of Document.Text. // So if Document is "日本(cursor)語", cursorPosition is 2. // But DisplayedCursorPosition returns 4 because '日' and '本' are double width characters. cursorPosition int lastKey Key }
type ExitChecker ¶
type ExitChecker = prompt.ExitChecker
ExitChecker is called after user input to check if prompt must stop and exit go-prompt Run loop. User input means: selecting/typing an entry, then, if said entry content matches the ExitChecker function criteria: - immediate exit (if breakline is false) without executor called - exit after typing <return> (meaning breakline is true), and the executor is called first, before exit. Exit means exit go-prompt (not the overall Go program) func(in string, breakline bool) bool
type Key ¶
Key is the type express the key inserted from user.
const ( // Escape Key ... Escape Key = iota ControlA ControlB ControlC ControlD ControlE ControlF ControlG ControlH ControlI ControlJ ControlK ControlL ControlM ControlN ControlO ControlP ControlQ ControlR ControlS ControlT ControlU ControlV ControlW ControlX ControlY ControlZ ControlSpace ControlBackslash ControlSquareClose ControlCircumflex ControlUnderscore ControlLeft ControlRight ControlUp ControlDown Up Down Right Left ShiftLeft ShiftUp ShiftDown ShiftRight Home End Delete ShiftDelete ControlDelete PageUp PageDown BackTab Insert Backspace // Aliases. Tab Enter F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 // Any Matches any key. Any // Special CPRResponse Vt100MouseEvent WindowsMouseEvent BracketedPaste // Key which is ignored. (The key binding for this key should not do anything.) Ignore // Key is not defined NotDefined )
type KeyBind ¶
KeyBind represents which key should do what operation. struct { Key key
Fn KeyBindFunc }
type KeyBindFunc ¶
type KeyBindFunc = prompt.KeyBindFunc
KeyBindFunc receives buffer and processed it. func(*buffer)
type KeyBindMode ¶
type KeyBindMode = prompt.KeyBindMode
KeyBindMode to switch a key binding flexibly. string
const ( // CommonKeyBind is a mode without any keyboard shortcut CommonKeyBind KeyBindMode = "common" // EmacsKeyBind is a mode to use emacs-like keyboard shortcut EmacsKeyBind KeyBindMode = "emacs" )
type LivePrefixOption ¶
LivePrefixOption is a function type for for modifying the shell prefix
type OptArg ¶
type OptArg struct { Description string Arguments []Suggestion }
OptArg Represents options available for commands.
type Option ¶
Option is the type to replace default parameters. shell.NewShell accepts any number of options (this is functional option pattern).
type ParserOption ¶
type ParserOption func(x ConsoleParser) Option
ParserOption is the function type targeting ConsoleParser parameters
type Suggestion ¶
Suggestion is equivalent to go-prompt.Suggest {Text, Description}
type WriterOption ¶
type WriterOption func(x ConsoleWriter) Option
WriterOption is the function type targeting ConsoleWriter parameters