Documentation ¶
Index ¶
- Variables
- func DeleteBeforeChar(buf *Buffer)
- func DeleteChar(buf *Buffer)
- func DeleteWord(buf *Buffer)
- func GoLeftChar(buf *Buffer)
- func GoLeftWord(buf *Buffer)
- func GoLineBeginning(buf *Buffer)
- func GoLineEnd(buf *Buffer)
- func GoRightChar(buf *Buffer)
- func GoRightWord(buf *Buffer)
- type ASCIICode
- type ASCIICodeBind
- 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) DisplayCursorPosition() int
- 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 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) DisplayCursorPosition() int
- func (d *Document) FindEndOfCurrentWord() int
- func (d *Document) FindEndOfCurrentWordUntilSeparator(sep string) int
- func (d *Document) FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor(sep string) int
- func (d *Document) FindEndOfCurrentWordWithSpace() int
- func (d *Document) FindStartOfPreviousWord() int
- func (d *Document) FindStartOfPreviousWordUntilSeparator(sep string) int
- func (d *Document) FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor(sep string) 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) GetWordAfterCursor() string
- func (d *Document) GetWordAfterCursorUntilSeparator(sep string) string
- func (d *Document) GetWordAfterCursorUntilSeparatorIgnoreNextToCursor(sep string) string
- func (d *Document) GetWordAfterCursorWithSpace() string
- func (d *Document) GetWordBeforeCursor() string
- func (d *Document) GetWordBeforeCursorUntilSeparator(sep string) string
- func (d *Document) GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor(sep string) string
- func (d *Document) GetWordBeforeCursorWithSpace() string
- func (d *Document) LastKeyStroke() Key
- 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 ExitChecker
- type Filter
- type History
- type Key
- type KeyBind
- type KeyBindFunc
- type KeyBindMode
- type Option
- func OptionAddASCIICodeBind(b ...ASCIICodeBind) Option
- func OptionAddKeyBind(b ...KeyBind) Option
- func OptionBreakLineCallback(fn func(*Document)) Option
- func OptionCompletionOnDown() Option
- func OptionCompletionWordSeparator(x string) Option
- func OptionDescriptionColor(x *fcolor.Color) Option
- func OptionHistory(x []string) Option
- func OptionInitialBufferText(x string) Option
- func OptionInputColor(x *fcolor.Color) Option
- func OptionKeywordColor(kwCol *fcolor.Color) Option
- func OptionKeywords(kw []string) 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 OptionPrefixColor(x *fcolor.Color) Option
- func OptionPreviewSuggestionColor(x *fcolor.Color) Option
- func OptionScrollbarBGColor(x *fcolor.Color) Option
- func OptionScrollbarThumbColor(x *fcolor.Color) Option
- func OptionSelectedDescriptionColor(x *fcolor.Color) Option
- func OptionSelectedSuggestionColor(x *fcolor.Color) Option
- func OptionSetExitCheckerOnInput(fn ExitChecker) Option
- func OptionShowCompletionAtStart() Option
- func OptionStatusBarCallback(cb func(*Buffer, *CompletionManager) (string, bool)) Option
- func OptionStatusBarColor(color *fcolor.Color) Option
- func OptionSuggestionColor(x *fcolor.Color) Option
- func OptionSwitchKeyBindMode(m KeyBindMode) Option
- func OptionTitle(x string) Option
- func OptionWriter(x ConsoleWriter) Option
- type PosixParser
- type PosixWriter
- type Prompt
- type Render
- type Suggest
- func FilterContains(completions []Suggest, sub string, ignoreCase bool) []Suggest
- func FilterFuzzy(completions []Suggest, sub string, ignoreCase bool) []Suggest
- func FilterHasPrefix(completions []Suggest, sub string, ignoreCase bool) []Suggest
- func FilterHasSuffix(completions []Suggest, sub string, ignoreCase bool) []Suggest
- 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) HideCursor()
- func (w *VT100Writer) SaveCursor()
- func (w *VT100Writer) ScrollDown()
- func (w *VT100Writer) ScrollUp()
- func (w *VT100Writer) SetTitle(title string)
- func (w *VT100Writer) ShowCursor()
- func (w *VT100Writer) UnSaveCursor()
- func (w *VT100Writer) WriteStr(data string, color *fcolor.Color)
- type WinSize
Examples ¶
- Document.CurrentLine
- Document.CurrentLineAfterCursor
- Document.CurrentLineBeforeCursor
- Document.CursorPositionCol
- Document.CursorPositionRow
- Document.DisplayCursorPosition
- Document.DisplayCursorPosition (WithJapanese)
- Document.GetWordAfterCursor
- Document.GetWordAfterCursorUntilSeparator
- Document.GetWordAfterCursorUntilSeparatorIgnoreNextToCursor
- Document.GetWordAfterCursorWithSpace
- Document.GetWordBeforeCursor
- Document.GetWordBeforeCursorUntilSeparator
- Document.GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor
- Document.GetWordBeforeCursorWithSpace
- Document.TextAfterCursor
- Document.TextBeforeCursor
Constants ¶
This section is empty.
Variables ¶
var ASCIISequences = []*ASCIICode{}/* 112 elements not displayed */
ASCIISequences holds mappings of the key and byte array.
var ( // NewStandardOutputWriter returns ConsoleWriter object to write to stdout. // This generates VT100 escape sequences because almost terminal emulators // in POSIX OS built on top of a VT100 specification. // Deprecated: Please use NewStdoutWriter NewStandardOutputWriter = NewStdoutWriter )
var SwitchKeyBindMode = OptionSwitchKeyBindMode
SwitchKeyBindMode to set a key bind mode. Deprecated: Please use OptionSwitchKeyBindMode.
Functions ¶
func DeleteBeforeChar ¶ added in v0.2.2
func DeleteBeforeChar(buf *Buffer)
DeleteBeforeChar Go to Backspace
func DeleteChar ¶ added in v0.2.2
func DeleteChar(buf *Buffer)
DeleteChar Delete character under the cursor
func DeleteWord ¶ added in v0.2.2
func DeleteWord(buf *Buffer)
DeleteWord Delete word before the cursor
func GoLineBeginning ¶ added in v0.2.2
func GoLineBeginning(buf *Buffer)
GoLineBeginning Go to the beginning of the line
Types ¶
type ASCIICodeBind ¶ added in v0.2.2
type ASCIICodeBind struct { ASCIICode []byte Fn KeyBindFunc }
ASCIICodeBind represents which []byte should do what operation
type Buffer ¶
type Buffer struct {
// 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) DisplayCursorPosition ¶ added in v0.2.2
DisplayCursorPosition returns the cursor position on rendered text on terminal emulators. So if Document is "日本(cursor)語", DisplayedCursorPosition returns 4 because '日' and '本' are double width characters.
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 // 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 { // WriteStr to write safety string by removing control sequences. WriteStr(data string, color *fcolor.Color) // 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() }
ConsoleWriter is an interface to abstract output layer.
func NewStderrWriter ¶ added in v0.2.3
func NewStderrWriter() ConsoleWriter
NewStderrWriter returns ConsoleWriter object to write to stderr. This generates VT100 escape sequences because almost terminal emulators in POSIX OS built on top of a VT100 specification.
func NewStdoutWriter ¶ added in v0.2.3
func NewStdoutWriter() ConsoleWriter
NewStdoutWriter returns ConsoleWriter object to write to stdout. This generates VT100 escape sequences because almost terminal emulators in POSIX OS built on top of a VT100 specification.
type Document ¶
type Document struct { Text string // contains filtered or unexported fields }
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`.
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. This component has texts displayed in terminal and cursor position. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println(d.CurrentLine())
Output: This is a example of Document component.
func (*Document) CurrentLineAfterCursor ¶
CurrentLineAfterCursor returns the text from the cursor until the end of the line.
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. This component has texts displayed in terminal and cursor position. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println(d.CurrentLineAfterCursor())
Output: ple of Document component.
func (*Document) CurrentLineBeforeCursor ¶
CurrentLineBeforeCursor returns the text from the start of the line until the cursor.
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. This component has texts displayed in terminal and cursor position. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println(d.CurrentLineBeforeCursor())
Output: This is a exam
func (*Document) CursorPositionCol ¶
CursorPositionCol returns the current column. (0-based.)
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. This component has texts displayed in terminal and cursor position. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println("CursorPositionCol", d.CursorPositionCol())
Output: CursorPositionCol 14
func (*Document) CursorPositionRow ¶
CursorPositionRow returns the current row. (0-based.)
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. This component has texts displayed in terminal and cursor position. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println("CursorPositionRow", d.CursorPositionRow())
Output: CursorPositionRow 1
func (*Document) DisplayCursorPosition ¶ added in v0.2.2
DisplayCursorPosition returns the cursor position on rendered text on terminal emulators. So if Document is "日本(cursor)語", DisplayedCursorPosition returns 4 because '日' and '本' are double width characters.
Example ¶
d := &Document{ Text: `Hello! my name is c-bata.`, cursorPosition: len(`Hello`), } fmt.Println("DisplayCursorPosition", d.DisplayCursorPosition())
Output: DisplayCursorPosition 5
Example (WithJapanese) ¶
d := &Document{ Text: `こんにちは、芝田 将です。`, cursorPosition: 3, } fmt.Println("DisplayCursorPosition", d.DisplayCursorPosition())
Output: DisplayCursorPosition 6
func (*Document) FindEndOfCurrentWord ¶ added in v0.2.2
FindEndOfCurrentWord returns an index relative to the cursor position. pointing to the end of the current word. Return 0 if nothing was found.
func (*Document) FindEndOfCurrentWordUntilSeparator ¶ added in v0.2.2
FindEndOfCurrentWordUntilSeparator is almost the same as FindEndOfCurrentWord. But this can specify Separator. Return 0 if nothing was found.
func (*Document) FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor ¶ added in v0.2.2
FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor is almost the same as FindEndOfCurrentWordWithSpace. But this can specify Separator. Return 0 if nothing was found.
func (*Document) FindEndOfCurrentWordWithSpace ¶ added in v0.2.2
FindEndOfCurrentWordWithSpace is almost the same as FindEndOfCurrentWord. The only difference is to ignore contiguous spaces.
func (*Document) FindStartOfPreviousWord ¶
FindStartOfPreviousWord returns an index relative to the cursor position pointing to the start of the previous word. Return 0 if nothing was found.
func (*Document) FindStartOfPreviousWordUntilSeparator ¶ added in v0.2.2
FindStartOfPreviousWordUntilSeparator is almost the same as FindStartOfPreviousWord. But this can specify Separator. Return 0 if nothing was found.
func (*Document) FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor ¶ added in v0.2.2
FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor is almost the same as FindStartOfPreviousWordWithSpace. But this can specify Separator. Return 0 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) GetWordAfterCursor ¶ added in v0.2.2
GetWordAfterCursor returns the word after the cursor. If we have whitespace after the cursor this returns an empty string.
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println(d.GetWordAfterCursor())
Output: ple
func (*Document) GetWordAfterCursorUntilSeparator ¶ added in v0.2.2
GetWordAfterCursorUntilSeparator returns the text after the cursor until next separator.
Example ¶
d := &Document{ Text: `hello,i am c-bata,thank you for using go-prompt`, cursorPosition: len(`hello,i a`), } fmt.Println(d.GetWordAfterCursorUntilSeparator(","))
Output: m c-bata
func (*Document) GetWordAfterCursorUntilSeparatorIgnoreNextToCursor ¶ added in v0.2.2
GetWordAfterCursorUntilSeparatorIgnoreNextToCursor returns the word after the cursor. Unlike GetWordAfterCursor, it returns string containing space
Example ¶
d := &Document{ Text: `hello,i am c-bata,thank you for using go-prompt`, cursorPosition: len(`hello`), } fmt.Println(d.GetWordAfterCursorUntilSeparatorIgnoreNextToCursor(","))
Output: ,i am c-bata
func (*Document) GetWordAfterCursorWithSpace ¶ added in v0.2.2
GetWordAfterCursorWithSpace returns the word after the cursor. Unlike GetWordAfterCursor, it returns string containing space
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. `, cursorPosition: len(`Hello! my name is c-bata. This is a`), } fmt.Println(d.GetWordAfterCursorWithSpace())
Output: example
func (*Document) GetWordBeforeCursor ¶
GetWordBeforeCursor returns the word before the cursor. If we have whitespace before the cursor this returns an empty string.
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println(d.GetWordBeforeCursor())
Output: exam
func (*Document) GetWordBeforeCursorUntilSeparator ¶ added in v0.2.2
GetWordBeforeCursorUntilSeparator returns the text before the cursor until next separator.
Example ¶
d := &Document{ Text: `hello,i am c-bata`, cursorPosition: len(`hello,i am c`), } fmt.Println(d.GetWordBeforeCursorUntilSeparator(","))
Output: i am c
func (*Document) GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor ¶ added in v0.2.2
GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor returns the word before the cursor. Unlike GetWordBeforeCursor, it returns string containing space
Example ¶
d := &Document{ Text: `hello,i am c-bata,thank you for using go-prompt`, cursorPosition: len(`hello,i am c-bata,`), } fmt.Println(d.GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor(","))
Output: i am c-bata,
func (*Document) GetWordBeforeCursorWithSpace ¶ added in v0.1.1
GetWordBeforeCursorWithSpace returns the word before the cursor. Unlike GetWordBeforeCursor, it returns string containing space
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. `, cursorPosition: len(`Hello! my name is c-bata. This is a example `), } fmt.Println(d.GetWordBeforeCursorWithSpace())
Output: example
func (*Document) LastKeyStroke ¶ added in v1.0.0
LastKeyStroke return the last key pressed in this document.
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.
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. This component has texts displayed in terminal and cursor position. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println(d.TextAfterCursor())
Output: ple of Document component. This component has texts displayed in terminal and cursor position.
func (*Document) TextBeforeCursor ¶
TextBeforeCursor returns the text before the cursor.
Example ¶
d := &Document{ Text: `Hello! my name is c-bata. This is a example of Document component. This component has texts displayed in terminal and cursor position. `, cursorPosition: len(`Hello! my name is c-bata. This is a exam`), } fmt.Println(d.TextBeforeCursor())
Output: Hello! my name is c-bata. This is a exam
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 ExitChecker ¶ added in v1.0.0
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)
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 }
KeyBind represents which key should do what operation.
type KeyBindMode ¶
type KeyBindMode string
KeyBindMode to switch a key binding flexibly.
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 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 OptionAddASCIICodeBind ¶ added in v0.2.2
func OptionAddASCIICodeBind(b ...ASCIICodeBind) Option
OptionAddASCIICodeBind to set a custom key bind.
func OptionAddKeyBind ¶
OptionAddKeyBind to set a custom key bind.
func OptionBreakLineCallback ¶ added in v1.0.0
OptionBreakLineCallback to run a callback at every break line
func OptionCompletionOnDown ¶ added in v1.0.0
func OptionCompletionOnDown() Option
OptionCompletionOnDown allows for Down arrow key to trigger completion.
func OptionCompletionWordSeparator ¶ added in v0.2.2
OptionCompletionWordSeparator to set word separators. Enable only ' ' if empty.
func OptionDescriptionColor ¶ added in v1.0.0
OptionDescriptionColor to change a background color of description text in drop down suggestions.
func OptionHistory ¶
OptionHistory to set history expressed by string array.
func OptionInitialBufferText ¶ added in v1.0.0
OptionInitialBufferText to set the initial buffer text
func OptionInputColor ¶ added in v1.0.0
OptionInputColor to change a color of text which is input by user
func OptionKeywordColor ¶ added in v1.0.0
OptionKeywordColor sets colors for keywords in displaying
func OptionKeywords ¶ added in v1.0.0
OptionKeywords sets the list of words to consider as keywords
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 OptionPrefixColor ¶ added in v1.0.0
OptionPrefixColor change a text color of prefix string
func OptionPreviewSuggestionColor ¶ added in v1.0.0
OptionPreviewSuggestionColor to change a text color which is completed
func OptionScrollbarBGColor ¶ added in v0.2.0
OptionScrollbarBGColor to change a background color of scrollbar.
func OptionScrollbarThumbColor ¶ added in v0.2.0
OptionScrollbarThumbColor to change a thumb color on scrollbar.
func OptionSelectedDescriptionColor ¶ added in v1.0.0
OptionSelectedDescriptionColor to change a text color of description which is selected inside suggestions drop down box.
func OptionSelectedSuggestionColor ¶ added in v1.0.0
OptionSelectedSuggestionColor to change a text color for completed text which is selected inside suggestions drop down box.
func OptionSetExitCheckerOnInput ¶ added in v1.0.0
func OptionSetExitCheckerOnInput(fn ExitChecker) Option
OptionSetExitCheckerOnInput set an exit function which checks if go-prompt exits its Run loop
func OptionShowCompletionAtStart ¶ added in v0.2.3
func OptionShowCompletionAtStart() Option
OptionShowCompletionAtStart to set completion window is open at start.
func OptionStatusBarCallback ¶ added in v1.0.0
func OptionStatusBarCallback(cb func(*Buffer, *CompletionManager) (string, bool)) Option
OptionStatusBarCallback sets a callback function that returns the status bar message and color to display it in
func OptionStatusBarColor ¶ added in v1.0.0
OptionStatusBarColor sets the color of the status bar
func OptionSuggestionColor ¶ added in v1.0.0
OptionSuggestionColor to change a text color in drop down suggestions.
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 interface.
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) 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 { VT100Writer // contains filtered or unexported fields }
PosixWriter is a ConsoleWriter implementation for POSIX environment. To control terminal emulator, this outputs VT100 escape sequences.
func (*PosixWriter) Flush ¶ added in v0.2.0
func (w *PosixWriter) Flush() error
Flush to flush buffer
type Prompt ¶
type Prompt struct { ASCIICodeBindings []ASCIICodeBind // 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 FilterFuzzy ¶ added in v0.2.3
FilterFuzzy checks whether the completion.Text fuzzy matches sub. Fuzzy searching for "dog" is equivalent to "*d*o*g*". This search term would match, for example, "Good food is gone"
^ ^ ^
func FilterHasPrefix ¶
FilterHasPrefix checks whether the string completions.Text begins with sub.
type VT100Writer ¶
type VT100Writer struct {
// contains filtered or unexported fields
}
VT100Writer generates VT100 escape sequences. Thread unsafe
func (*VT100Writer) AskForCPR ¶
func (w *VT100Writer) AskForCPR()
AskForCPR asks for a cursor position report (CPR).
func (*VT100Writer) ClearTitle ¶
func (w *VT100Writer) ClearTitle()
ClearTitle clears a title of terminal window.
func (*VT100Writer) CursorBackward ¶
func (w *VT100Writer) CursorBackward(n int)
CursorBackward moves the cursor backward by 'n' columns; the default count is 1.
func (*VT100Writer) CursorDown ¶
func (w *VT100Writer) CursorDown(n int)
CursorDown moves the cursor down by 'n' rows; the default count is 1.
func (*VT100Writer) CursorForward ¶
func (w *VT100Writer) CursorForward(n int)
CursorForward moves the cursor forward by 'n' columns; the default count is 1.
func (*VT100Writer) CursorGoTo ¶
func (w *VT100Writer) CursorGoTo(row, col int)
CursorGoTo sets the cursor position where subsequent text will begin.
func (*VT100Writer) CursorUp ¶
func (w *VT100Writer) CursorUp(n int)
CursorUp moves the cursor up by 'n' rows; the default count is 1.
func (*VT100Writer) EraseDown ¶
func (w *VT100Writer) EraseDown()
EraseDown erases the screen from the current line down to the bottom of the screen.
func (*VT100Writer) EraseEndOfLine ¶
func (w *VT100Writer) EraseEndOfLine()
EraseEndOfLine erases from the current cursor position to the end of the current line.
func (*VT100Writer) EraseLine ¶
func (w *VT100Writer) EraseLine()
EraseLine erases the entire current line.
func (*VT100Writer) EraseScreen ¶
func (w *VT100Writer) EraseScreen()
EraseScreen erases the screen with the background colour and moves the cursor to home.
func (*VT100Writer) EraseStartOfLine ¶
func (w *VT100Writer) EraseStartOfLine()
EraseStartOfLine erases from the current cursor position to the start of the current line.
func (*VT100Writer) EraseUp ¶
func (w *VT100Writer) EraseUp()
EraseUp erases the screen from the current line up to the top of the screen.
func (*VT100Writer) SaveCursor ¶
func (w *VT100Writer) SaveCursor()
SaveCursor saves current cursor position.
func (*VT100Writer) ScrollDown ¶
func (w *VT100Writer) ScrollDown()
ScrollDown scrolls display down one line.
func (*VT100Writer) ScrollUp ¶
func (w *VT100Writer) ScrollUp()
ScrollUp scroll display up one line.
func (*VT100Writer) SetTitle ¶
func (w *VT100Writer) SetTitle(title string)
SetTitle sets a title of terminal window.
func (*VT100Writer) ShowCursor ¶
func (w *VT100Writer) ShowCursor()
ShowCursor stops blinking cursor and show.
func (*VT100Writer) UnSaveCursor ¶
func (w *VT100Writer) UnSaveCursor()
UnSaveCursor restores cursor position after a Save Cursor.