Documentation ¶
Index ¶
- 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
- 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 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 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 OptionTitle(x string) option
- func OptionWriter(x ConsoleWriter) option
- func SwitchKeyBindMode(m KeyBindMode) option
- 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) 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) 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 Prompt
- type Render
- type Suggest
- type VT100Parser
- type VT100Writer
- func (w *VT100Writer) AskForCPR()
- func (w *VT100Writer) ClearTitle()
- func (w *VT100Writer) CursorBackward(n int)
- func (w *VT100Writer) CursorDown(n int)
- func (w *VT100Writer) CursorForward(n int)
- func (w *VT100Writer) CursorGoTo(row, col int)
- func (w *VT100Writer) CursorUp(n int)
- func (w *VT100Writer) EraseDown()
- func (w *VT100Writer) EraseEndOfLine()
- func (w *VT100Writer) EraseLine()
- func (w *VT100Writer) EraseScreen()
- func (w *VT100Writer) EraseStartOfLine()
- func (w *VT100Writer) EraseUp()
- func (w *VT100Writer) Flush() error
- func (w *VT100Writer) HideCursor()
- func (w *VT100Writer) SaveCursor()
- func (w *VT100Writer) ScrollDown()
- func (w *VT100Writer) ScrollUp()
- func (w *VT100Writer) SetColor(fg, bg Color, bold bool)
- func (w *VT100Writer) SetTitle(title string)
- func (w *VT100Writer) ShowCursor()
- func (w *VT100Writer) UnSaveCursor()
- func (w *VT100Writer) Write(data []byte)
- func (w *VT100Writer) WriteRaw(data []byte)
- func (w *VT100Writer) WriteRawStr(data string)
- func (w *VT100Writer) WriteStr(data string)
- type WinSize
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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.
func OptionAddKeyBind ¶
func OptionAddKeyBind(b ...KeyBind) option
func OptionDescriptionBGColor ¶
func OptionDescriptionBGColor(x Color) option
func OptionDescriptionTextColor ¶
func OptionDescriptionTextColor(x Color) option
func OptionHistory ¶
func OptionHistory(x []string) option
func OptionInputBGColor ¶
func OptionInputBGColor(x Color) option
func OptionInputTextColor ¶
func OptionInputTextColor(x Color) option
func OptionMaxSuggestion ¶
func OptionMaxSuggestion(x uint16) option
func OptionParser ¶
func OptionParser(x ConsoleParser) option
func OptionPrefix ¶
func OptionPrefix(x string) option
func OptionPrefixBackgroundColor ¶
func OptionPrefixBackgroundColor(x Color) option
func OptionPrefixTextColor ¶
func OptionPrefixTextColor(x Color) option
func OptionPreviewSuggestionBGColor ¶
func OptionPreviewSuggestionBGColor(x Color) option
func OptionPreviewSuggestionTextColor ¶
func OptionPreviewSuggestionTextColor(x Color) option
func OptionSelectedDescriptionBGColor ¶
func OptionSelectedDescriptionBGColor(x Color) option
func OptionSelectedDescriptionTextColor ¶
func OptionSelectedDescriptionTextColor(x Color) option
func OptionSelectedSuggestionBGColor ¶
func OptionSelectedSuggestionBGColor(x Color) option
func OptionSelectedSuggestionTextColor ¶
func OptionSelectedSuggestionTextColor(x Color) option
func OptionSuggestionBGColor ¶
func OptionSuggestionBGColor(x Color) option
func OptionSuggestionTextColor ¶
func OptionSuggestionTextColor(x Color) option
func OptionTitle ¶
func OptionTitle(x string) option
func OptionWriter ¶
func OptionWriter(x ConsoleWriter) option
func SwitchKeyBindMode ¶
func SwitchKeyBindMode(m KeyBindMode) option
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
}
func NewCompletionManager ¶
func NewCompletionManager(completer Completer, max uint16) *CompletionManager
func (*CompletionManager) Completing ¶
func (c *CompletionManager) Completing() bool
func (*CompletionManager) GetSelectedSuggestion ¶
func (c *CompletionManager) GetSelectedSuggestion() (s Suggest, ok bool)
func (*CompletionManager) GetSuggestions ¶
func (c *CompletionManager) GetSuggestions() []Suggest
func (*CompletionManager) Next ¶
func (c *CompletionManager) Next()
func (*CompletionManager) Previous ¶
func (c *CompletionManager) Previous()
func (*CompletionManager) Reset ¶
func (c *CompletionManager) Reset()
func (*CompletionManager) Update ¶
func (c *CompletionManager) Update(in Document)
type ConsoleParser ¶
type ConsoleWriter ¶
type ConsoleWriter interface { WriteRaw(data []byte) Write(data []byte) WriteStr(data string) WriteRawStr(data string) Flush() error EraseScreen() EraseUp() EraseDown() EraseStartOfLine() EraseEndOfLine() EraseLine() ShowCursor() HideCursor() CursorGoTo(row, col int) CursorUp(n int) CursorDown(n int) CursorForward(n int) CursorBackward(n int) AskForCPR() SaveCursor() UnSaveCursor() ScrollDown() ScrollUp() SetTitle(title string) ClearTitle() SetColor(fg, bg Color, bold bool) }
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 return an index relative to the cursor position pointing to the start of the previous word. Return `None` if nothing was found.
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) 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 History ¶
type History struct {
// contains filtered or unexported fields
}
func NewHistory ¶
func NewHistory() *History
type Key ¶
type Key int
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 Render ¶
type Render struct {
// contains filtered or unexported fields
}
func (*Render) Render ¶
func (r *Render) Render(buffer *Buffer, completion *CompletionManager)
func (*Render) UpdateWinSize ¶
type VT100Parser ¶
type VT100Parser struct {
// contains filtered or unexported fields
}
func NewVT100StandardInputParser ¶
func NewVT100StandardInputParser() *VT100Parser
func (*VT100Parser) GetKey ¶
func (t *VT100Parser) GetKey(b []byte) Key
func (*VT100Parser) GetWinSize ¶
func (t *VT100Parser) GetWinSize() *WinSize
GetWinSize returns winsize struct which is the response of ioctl(2).
func (*VT100Parser) Setup ¶
func (t *VT100Parser) Setup() error
func (*VT100Parser) TearDown ¶
func (t *VT100Parser) TearDown() error
type VT100Writer ¶
type VT100Writer struct {
// contains filtered or unexported fields
}
func NewVT100StandardOutputWriter ¶
func NewVT100StandardOutputWriter() *VT100Writer
func (*VT100Writer) AskForCPR ¶
func (w *VT100Writer) AskForCPR()
func (*VT100Writer) ClearTitle ¶
func (w *VT100Writer) ClearTitle()
func (*VT100Writer) CursorBackward ¶
func (w *VT100Writer) CursorBackward(n int)
func (*VT100Writer) CursorDown ¶
func (w *VT100Writer) CursorDown(n int)
func (*VT100Writer) CursorForward ¶
func (w *VT100Writer) CursorForward(n int)
func (*VT100Writer) CursorGoTo ¶
func (w *VT100Writer) CursorGoTo(row, col int)
func (*VT100Writer) CursorUp ¶
func (w *VT100Writer) CursorUp(n int)
func (*VT100Writer) EraseDown ¶
func (w *VT100Writer) EraseDown()
func (*VT100Writer) EraseEndOfLine ¶
func (w *VT100Writer) EraseEndOfLine()
func (*VT100Writer) EraseLine ¶
func (w *VT100Writer) EraseLine()
func (*VT100Writer) EraseScreen ¶
func (w *VT100Writer) EraseScreen()
func (*VT100Writer) EraseStartOfLine ¶
func (w *VT100Writer) EraseStartOfLine()
func (*VT100Writer) EraseUp ¶
func (w *VT100Writer) EraseUp()
func (*VT100Writer) Flush ¶
func (w *VT100Writer) Flush() error
func (*VT100Writer) HideCursor ¶
func (w *VT100Writer) HideCursor()
func (*VT100Writer) SaveCursor ¶
func (w *VT100Writer) SaveCursor()
func (*VT100Writer) ScrollDown ¶
func (w *VT100Writer) ScrollDown()
func (*VT100Writer) ScrollUp ¶
func (w *VT100Writer) ScrollUp()
func (*VT100Writer) SetColor ¶
func (w *VT100Writer) SetColor(fg, bg Color, bold bool)
func (*VT100Writer) SetTitle ¶
func (w *VT100Writer) SetTitle(title string)
func (*VT100Writer) ShowCursor ¶
func (w *VT100Writer) ShowCursor()
func (*VT100Writer) UnSaveCursor ¶
func (w *VT100Writer) UnSaveCursor()
func (*VT100Writer) Write ¶
func (w *VT100Writer) Write(data []byte)
func (*VT100Writer) WriteRaw ¶
func (w *VT100Writer) WriteRaw(data []byte)
func (*VT100Writer) WriteRawStr ¶
func (w *VT100Writer) WriteRawStr(data string)
func (*VT100Writer) WriteStr ¶
func (w *VT100Writer) WriteStr(data string)