Documentation ¶
Index ¶
- Variables
- func BisectLeft(a []int, v int) int
- func BisectRight(a []int, v int) int
- func Choose(prefix string, choices []string, opts ...Option) string
- func Input(prefix string, completer Completer, opts ...Option) string
- type ASCIICode
- type Buffer
- func (b *Buffer) CursorDown(count int)
- func (b *Buffer) CursorLeft(count int)
- func (b *Buffer) CursorRight(count int)
- func (b *Buffer) CursorUp(count int)
- func (b *Buffer) Delete(count int) (deleted string)
- func (b *Buffer) DeleteBeforeCursor(count int) (deleted string)
- func (b *Buffer) Document() (d *Document)
- func (b *Buffer) InsertText(v string, overwrite bool, moveCursor bool)
- func (b *Buffer) JoinNextLine(separator string)
- func (b *Buffer) NewLine(copyMargin bool)
- func (b *Buffer) SwapCharactersBeforeCursor()
- func (b *Buffer) Text() string
- type Color
- type Completer
- type CompletionManager
- func (c *CompletionManager) Completing() bool
- func (c *CompletionManager) GetSelectedSuggestion() (s Suggest, ok bool)
- func (c *CompletionManager) GetSuggestions() []Suggest
- func (c *CompletionManager) Next()
- func (c *CompletionManager) Previous()
- func (c *CompletionManager) Reset()
- func (c *CompletionManager) Update(in Document)
- type ConsoleParser
- type ConsoleWriter
- type Document
- func (d *Document) CurrentLine() string
- func (d *Document) CurrentLineAfterCursor() string
- func (d *Document) CurrentLineBeforeCursor() string
- func (d *Document) CursorPositionCol() (col int)
- func (d *Document) CursorPositionRow() (row int)
- func (d *Document) FindStartOfPreviousWord() int
- func (d *Document) FindStartOfPreviousWordWithSpace() int
- func (d *Document) GetCharRelativeToCursor(offset int) (r rune)
- func (d *Document) GetCursorDownPosition(count int, preferredColumn int) int
- func (d *Document) GetCursorLeftPosition(count int) int
- func (d *Document) GetCursorRightPosition(count int) int
- func (d *Document) GetCursorUpPosition(count int, preferredColumn int) int
- func (d *Document) GetEndOfLinePosition() int
- func (d *Document) GetWordBeforeCursor() string
- func (d *Document) GetWordBeforeCursorWithSpace() string
- func (d *Document) LineCount() int
- func (d *Document) Lines() []string
- func (d *Document) OnLastLine() bool
- func (d *Document) TextAfterCursor() string
- func (d *Document) TextBeforeCursor() string
- func (d *Document) TranslateIndexToPosition(index int) (row int, col int)
- func (d *Document) TranslateRowColToIndex(row int, column int) (index int)
- type Exec
- type Executor
- type Filter
- type History
- type Key
- type KeyBind
- type KeyBindFunc
- type KeyBindMode
- type Option
- func OptionAddKeyBind(b ...KeyBind) Option
- func OptionDescriptionBGColor(x Color) Option
- func OptionDescriptionTextColor(x Color) Option
- func OptionHistory(x []string) Option
- func OptionInputBGColor(x Color) Option
- func OptionInputTextColor(x Color) Option
- func OptionLivePrefix(f func() (prefix string, useLivePrefix bool)) Option
- func OptionMaxSuggestion(x uint16) Option
- func OptionParser(x ConsoleParser) Option
- func OptionPrefix(x string) Option
- func OptionPrefixBackgroundColor(x Color) Option
- func OptionPrefixTextColor(x Color) Option
- func OptionPreviewSuggestionBGColor(x Color) Option
- func OptionPreviewSuggestionTextColor(x Color) Option
- func OptionScrollbarBGColor(x Color) Option
- func OptionScrollbarThumbColor(x Color) Option
- func OptionSelectedDescriptionBGColor(x Color) Option
- func OptionSelectedDescriptionTextColor(x Color) Option
- func OptionSelectedSuggestionBGColor(x Color) Option
- func OptionSelectedSuggestionTextColor(x Color) Option
- func OptionSuggestionBGColor(x Color) Option
- func OptionSuggestionTextColor(x Color) Option
- func OptionSwitchKeyBindMode(m KeyBindMode) Option
- func OptionTitle(x string) Option
- func OptionWriter(x ConsoleWriter) Option
- type PosixParser
- type PosixWriter
- func (w *PosixWriter) AskForCPR()
- func (w *PosixWriter) ClearTitle()
- func (w *PosixWriter) CursorBackward(n int)
- func (w *PosixWriter) CursorDown(n int)
- func (w *PosixWriter) CursorForward(n int)
- func (w *PosixWriter) CursorGoTo(row, col int)
- func (w *PosixWriter) CursorUp(n int)
- func (w *PosixWriter) EraseDown()
- func (w *PosixWriter) EraseEndOfLine()
- func (w *PosixWriter) EraseLine()
- func (w *PosixWriter) EraseScreen()
- func (w *PosixWriter) EraseStartOfLine()
- func (w *PosixWriter) EraseUp()
- func (w *PosixWriter) Flush() error
- func (w *PosixWriter) HideCursor()
- func (w *PosixWriter) SaveCursor()
- func (w *PosixWriter) ScrollDown()
- func (w *PosixWriter) ScrollUp()
- func (w *PosixWriter) SetColor(fg, bg Color, bold bool)
- func (w *PosixWriter) SetTitle(title string)
- func (w *PosixWriter) ShowCursor()
- func (w *PosixWriter) UnSaveCursor()
- func (w *PosixWriter) Write(data []byte)
- func (w *PosixWriter) WriteRaw(data []byte)
- func (w *PosixWriter) WriteRawStr(data string)
- func (w *PosixWriter) WriteStr(data string)
- type Prompt
- type Render
- type Suggest
- type WinSize
Constants ¶
This section is empty.
Variables ¶
var SwitchKeyBindMode = OptionSwitchKeyBindMode
SwitchKeyBindMode to set a key bind mode. Deprecated: Please use OptionSwitchKeyBindMode.
Functions ¶
func BisectLeft ¶
BisectLeft to Locate the insertion point for v in a to maintain sorted order.
func BisectRight ¶
BisectRight to Locate the insertion point for v in a to maintain sorted order.
Types ¶
type Buffer ¶
type Buffer struct { CursorPosition int // contains filtered or unexported fields }
Buffer emulates the console buffer.
func (*Buffer) CursorDown ¶
CursorDown move cursor to the next line. (for multi-line edit).
func (*Buffer) CursorLeft ¶
CursorLeft move to left on the current line.
func (*Buffer) CursorRight ¶
CursorRight move to right on the current line.
func (*Buffer) DeleteBeforeCursor ¶
DeleteBeforeCursor delete specified number of characters before cursor and return the deleted text.
func (*Buffer) Document ¶
Document method to return document instance from the current text and cursor position.
func (*Buffer) InsertText ¶
InsertText insert string from current line.
func (*Buffer) JoinNextLine ¶
JoinNextLine joins the next line to the current one by deleting the line ending after the current line.
func (*Buffer) SwapCharactersBeforeCursor ¶
func (b *Buffer) SwapCharactersBeforeCursor()
SwapCharactersBeforeCursor swaps the last two characters before the cursor.
type CompletionManager ¶
type CompletionManager struct {
// contains filtered or unexported fields
}
CompletionManager manages which suggestion is now selected.
func NewCompletionManager ¶
func NewCompletionManager(completer Completer, max uint16) *CompletionManager
NewCompletionManager returns initialized CompletionManager object.
func (*CompletionManager) Completing ¶
func (c *CompletionManager) Completing() bool
Completing returns whether the CompletionManager selects something one.
func (*CompletionManager) GetSelectedSuggestion ¶
func (c *CompletionManager) GetSelectedSuggestion() (s Suggest, ok bool)
GetSelectedSuggestion returns the selected item.
func (*CompletionManager) GetSuggestions ¶
func (c *CompletionManager) GetSuggestions() []Suggest
GetSuggestions returns the list of suggestion.
func (*CompletionManager) Next ¶
func (c *CompletionManager) Next()
Next to select the next suggestion item.
func (*CompletionManager) Previous ¶
func (c *CompletionManager) Previous()
Previous to select the previous suggestion item.
func (*CompletionManager) Update ¶
func (c *CompletionManager) Update(in Document)
Update to update the suggestions.
type ConsoleParser ¶
type ConsoleParser interface { // Setup should be called before starting input Setup() error // TearDown should be called after stopping input TearDown() error // GetKey returns Key correspond to input byte codes. GetKey(b []byte) Key // GetWinSize returns WinSize object to represent width and height of terminal. GetWinSize() *WinSize // Read returns byte array. Read() ([]byte, error) }
ConsoleParser is an interface to abstract input layer.
type ConsoleWriter ¶
type ConsoleWriter interface { // WriteRaw to write raw byte array. WriteRaw(data []byte) // Write to write byte array without control sequences. Write(data []byte) // WriteStr to write raw string. WriteRawStr(data string) // WriteStr to write string without control sequences. WriteStr(data string) // Flush to flush buffer. Flush() error // EraseScreen erases the screen with the background colour and moves the cursor to home. EraseScreen() // EraseUp erases the screen from the current line up to the top of the screen. EraseUp() // EraseDown erases the screen from the current line down to the bottom of the screen. EraseDown() // EraseStartOfLine erases from the current cursor position to the start of the current line. EraseStartOfLine() // EraseEndOfLine erases from the current cursor position to the end of the current line. EraseEndOfLine() // EraseLine erases the entire current line. EraseLine() // ShowCursor stops blinking cursor and show. ShowCursor() // HideCursor hides cursor. HideCursor() // CursorGoTo sets the cursor position where subsequent text will begin. CursorGoTo(row, col int) // CursorUp moves the cursor up by 'n' rows; the default count is 1. CursorUp(n int) // CursorDown moves the cursor down by 'n' rows; the default count is 1. CursorDown(n int) // CursorForward moves the cursor forward by 'n' columns; the default count is 1. CursorForward(n int) // CursorBackward moves the cursor backward by 'n' columns; the default count is 1. CursorBackward(n int) // AskForCPR asks for a cursor position report (CPR). AskForCPR() // SaveCursor saves current cursor position. SaveCursor() // UnSaveCursor restores cursor position after a Save Cursor. UnSaveCursor() // ScrollDown scrolls display down one line. ScrollDown() // ScrollUp scroll display up one line. ScrollUp() // SetTitle sets a title of terminal window. SetTitle(title string) // ClearTitle clears a title of terminal window. ClearTitle() // SetColor sets text and background colors. and specify whether text is bold. SetColor(fg, bg Color, bold bool) }
ConsoleWriter is an interface to abstract output layer.
type Document ¶
Document has text displayed in terminal and cursor position.
func (*Document) CurrentLine ¶
CurrentLine return the text on the line where the cursor is. (when the input consists of just one line, it equals `text`.
func (*Document) CurrentLineAfterCursor ¶
CurrentLineAfterCursor returns the text from the cursor until the end of the line.
func (*Document) CurrentLineBeforeCursor ¶
CurrentLineBeforeCursor returns the text from the start of the line until the cursor.
func (*Document) CursorPositionCol ¶
CursorPositionCol returns the current column. (0-based.)
func (*Document) CursorPositionRow ¶
CursorPositionRow returns the current row. (0-based.)
func (*Document) FindStartOfPreviousWord ¶
FindStartOfPreviousWord returns an index relative to the cursor position pointing to the start of the previous word. Return `None` if nothing was found.
func (*Document) FindStartOfPreviousWordWithSpace ¶ added in v0.1.1
FindStartOfPreviousWordWithSpace is almost the same as FindStartOfPreviousWord. The only difference is to ignore contiguous spaces.
func (*Document) GetCharRelativeToCursor ¶
GetCharRelativeToCursor return character relative to cursor position, or empty string
func (*Document) GetCursorDownPosition ¶
GetCursorDownPosition return the relative cursor position (character index) where we would be if the user pressed the arrow-down button.
func (*Document) GetCursorLeftPosition ¶
GetCursorLeftPosition returns the relative position for cursor left.
func (*Document) GetCursorRightPosition ¶
GetCursorRightPosition returns relative position for cursor right.
func (*Document) GetCursorUpPosition ¶
GetCursorUpPosition return the relative cursor position (character index) where we would be if the user pressed the arrow-up button.
func (*Document) GetEndOfLinePosition ¶
GetEndOfLinePosition returns relative position for the end of this line.
func (*Document) GetWordBeforeCursor ¶
GetWordBeforeCursor returns the word before the cursor. If we have whitespace before the cursor this returns an empty string.
func (*Document) GetWordBeforeCursorWithSpace ¶ added in v0.1.1
GetWordBeforeCursorWithSpace returns the word before the cursor. Unlike GetWordBeforeCursor, it returns string containing space
func (*Document) LineCount ¶
LineCount return the number of lines in this document. If the document ends with a trailing \n, that counts as the beginning of a new line.
func (*Document) OnLastLine ¶
OnLastLine returns true when we are at the last line.
func (*Document) TextAfterCursor ¶
TextAfterCursor returns the text after the cursor.
func (*Document) TextBeforeCursor ¶
TextBeforeCursor returns the text before the cursor.
func (*Document) TranslateIndexToPosition ¶
TranslateIndexToPosition given an index for the text, return the corresponding (row, col) tuple. (0-based. Returns (0, 0) for index=0.)
type Exec ¶
type Exec struct {
// contains filtered or unexported fields
}
Exec is the struct contains user input context.
type History ¶
type History struct {
// contains filtered or unexported fields
}
History stores the texts that are entered.
type Key ¶
type Key int
Key is the type express the key inserted from user.
const ( 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 // 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 ¶
type KeyBind struct { Key Key Fn KeyBindFunc }
type KeyBindFunc ¶
type KeyBindFunc func(*Buffer)
type KeyBindMode ¶
type KeyBindMode string
const ( CommonKeyBind KeyBindMode = "common" EmacsKeyBind KeyBindMode = "emacs" )
type Option ¶ added in v0.1.1
Option is the type to replace default parameters. prompt.New accepts any number of options (this is functional option pattern).
func OptionAddKeyBind ¶
OptionAddKeyBind to set a custom key bind.
func OptionHistory ¶
OptionHistory to set history expressed by string array.
func OptionInputBGColor ¶
func OptionInputTextColor ¶
func OptionLivePrefix ¶ added in v0.2.0
OptionLivePrefix to change the prefix dynamically by callback function
func OptionMaxSuggestion ¶
OptionMaxSuggestion specify the max number of displayed suggestions.
func OptionParser ¶
func OptionParser(x ConsoleParser) Option
OptionParser to set a custom ConsoleParser object. An argument should implement ConsoleParser interface.
func OptionPrefixTextColor ¶
func OptionScrollbarBGColor ¶ added in v0.2.0
func OptionScrollbarThumbColor ¶ added in v0.2.0
func OptionSuggestionBGColor ¶
func OptionSwitchKeyBindMode ¶ added in v0.1.1
func OptionSwitchKeyBindMode(m KeyBindMode) Option
OptionSwitchKeyBindMode set a key bind mode.
func OptionTitle ¶
OptionTitle to set title displayed at the header bar of terminal.
func OptionWriter ¶
func OptionWriter(x ConsoleWriter) Option
OptionWriter to set a custom ConsoleWriter object. An argument should implement ConsoleWriter interace.
type PosixParser ¶ added in v0.2.0
type PosixParser struct {
// contains filtered or unexported fields
}
PosixParser is a ConsoleParser implementation for POSIX environment.
func NewStandardInputParser ¶ added in v0.2.0
func NewStandardInputParser() *PosixParser
NewStandardInputParser returns ConsoleParser object to read from stdin.
func (*PosixParser) GetKey ¶ added in v0.2.0
func (t *PosixParser) GetKey(b []byte) Key
GetKey returns Key correspond to input byte codes.
func (*PosixParser) GetWinSize ¶ added in v0.2.0
func (t *PosixParser) GetWinSize() *WinSize
GetWinSize returns WinSize object to represent width and height of terminal.
func (*PosixParser) Read ¶ added in v0.2.0
func (t *PosixParser) Read() ([]byte, error)
Read returns byte array.
func (*PosixParser) Setup ¶ added in v0.2.0
func (t *PosixParser) Setup() error
Setup should be called before starting input
func (*PosixParser) TearDown ¶ added in v0.2.0
func (t *PosixParser) TearDown() error
TearDown should be called after stopping input
type PosixWriter ¶ added in v0.2.0
type PosixWriter struct {
// contains filtered or unexported fields
}
PosixWriter is a ConsoleWriter implementation for POSIX environment. To control terminal emulator, this outputs VT100 escape sequences.
func NewStandardOutputWriter ¶ added in v0.2.0
func NewStandardOutputWriter() *PosixWriter
NewStandardOutputWriter returns ConsoleWriter object to write to stdout.
func (*PosixWriter) AskForCPR ¶ added in v0.2.0
func (w *PosixWriter) AskForCPR()
AskForCPR asks for a cursor position report (CPR).
func (*PosixWriter) ClearTitle ¶ added in v0.2.0
func (w *PosixWriter) ClearTitle()
ClearTitle clears a title of terminal window.
func (*PosixWriter) CursorBackward ¶ added in v0.2.0
func (w *PosixWriter) CursorBackward(n int)
CursorBackward moves the cursor backward by 'n' columns; the default count is 1.
func (*PosixWriter) CursorDown ¶ added in v0.2.0
func (w *PosixWriter) CursorDown(n int)
CursorDown moves the cursor down by 'n' rows; the default count is 1.
func (*PosixWriter) CursorForward ¶ added in v0.2.0
func (w *PosixWriter) CursorForward(n int)
CursorForward moves the cursor forward by 'n' columns; the default count is 1.
func (*PosixWriter) CursorGoTo ¶ added in v0.2.0
func (w *PosixWriter) CursorGoTo(row, col int)
CursorGoTo sets the cursor position where subsequent text will begin.
func (*PosixWriter) CursorUp ¶ added in v0.2.0
func (w *PosixWriter) CursorUp(n int)
CursorUp moves the cursor up by 'n' rows; the default count is 1.
func (*PosixWriter) EraseDown ¶ added in v0.2.0
func (w *PosixWriter) EraseDown()
EraseDown erases the screen from the current line down to the bottom of the screen.
func (*PosixWriter) EraseEndOfLine ¶ added in v0.2.0
func (w *PosixWriter) EraseEndOfLine()
EraseEndOfLine erases from the current cursor position to the end of the current line.
func (*PosixWriter) EraseLine ¶ added in v0.2.0
func (w *PosixWriter) EraseLine()
EraseLine erases the entire current line.
func (*PosixWriter) EraseScreen ¶ added in v0.2.0
func (w *PosixWriter) EraseScreen()
EraseScreen erases the screen with the background colour and moves the cursor to home.
func (*PosixWriter) EraseStartOfLine ¶ added in v0.2.0
func (w *PosixWriter) EraseStartOfLine()
EraseStartOfLine erases from the current cursor position to the start of the current line.
func (*PosixWriter) EraseUp ¶ added in v0.2.0
func (w *PosixWriter) EraseUp()
EraseUp erases the screen from the current line up to the top of the screen.
func (*PosixWriter) Flush ¶ added in v0.2.0
func (w *PosixWriter) Flush() error
Flush to flush buffer
func (*PosixWriter) HideCursor ¶ added in v0.2.0
func (w *PosixWriter) HideCursor()
HideCursor hides cursor.
func (*PosixWriter) SaveCursor ¶ added in v0.2.0
func (w *PosixWriter) SaveCursor()
SaveCursor saves current cursor position.
func (*PosixWriter) ScrollDown ¶ added in v0.2.0
func (w *PosixWriter) ScrollDown()
ScrollDown scrolls display down one line.
func (*PosixWriter) ScrollUp ¶ added in v0.2.0
func (w *PosixWriter) ScrollUp()
ScrollUp scroll display up one line.
func (*PosixWriter) SetColor ¶ added in v0.2.0
func (w *PosixWriter) SetColor(fg, bg Color, bold bool)
SetColor sets text and background colors. and specify whether text is bold.
func (*PosixWriter) SetTitle ¶ added in v0.2.0
func (w *PosixWriter) SetTitle(title string)
SetTitle sets a title of terminal window.
func (*PosixWriter) ShowCursor ¶ added in v0.2.0
func (w *PosixWriter) ShowCursor()
ShowCursor stops blinking cursor and show.
func (*PosixWriter) UnSaveCursor ¶ added in v0.2.0
func (w *PosixWriter) UnSaveCursor()
UnSaveCursor restores cursor position after a Save Cursor.
func (*PosixWriter) Write ¶ added in v0.2.0
func (w *PosixWriter) Write(data []byte)
Write to write byte array without control sequences
func (*PosixWriter) WriteRaw ¶ added in v0.2.0
func (w *PosixWriter) WriteRaw(data []byte)
WriteRaw to write raw byte array
func (*PosixWriter) WriteRawStr ¶ added in v0.2.0
func (w *PosixWriter) WriteRawStr(data string)
WriteRawStr to write raw string
func (*PosixWriter) WriteStr ¶ added in v0.2.0
func (w *PosixWriter) WriteStr(data string)
WriteStr to write string without control sequences
type Prompt ¶
type Prompt struct {
// contains filtered or unexported fields
}
Prompt is core struct of go-prompt.
type Render ¶
type Render struct {
// contains filtered or unexported fields
}
Render to render prompt information from state of Buffer.
func (*Render) Render ¶
func (r *Render) Render(buffer *Buffer, completion *CompletionManager)
Render renders to the console.
func (*Render) UpdateWinSize ¶
UpdateWinSize called when window size is changed.
type Suggest ¶
Suggest is printed when completing.
func FilterContains ¶
FilterContains checks whether the completion.Text contains sub.
func FilterHasPrefix ¶
FilterHasPrefix checks whether the string completions.Text begins with sub.