Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultExecuteOnEnterCallback(p *Prompt, indentSize int) (int, bool)
- func DefaultPrefixCallback() string
- func DeleteBeforeChar(p *Prompt) bool
- func DeleteChar(p *Prompt) bool
- func DeleteWordBeforeCursor(p *Prompt) bool
- func GoLeftChar(p *Prompt) bool
- func GoLineBeginning(p *Prompt) bool
- func GoLineEnd(p *Prompt) bool
- func GoRightChar(p *Prompt) bool
- func Input(opts ...Option) string
- func NoopExecutor(in string)
- type ASCIICode
- type ASCIICodeBind
- type Buffer
- func (b *Buffer) CursorDown(count int, columns istrings.Width, rows int) bool
- func (b *Buffer) CursorLeft(count istrings.GraphemeNumber, columns istrings.Width, rows int) bool
- func (b *Buffer) CursorLeftRunes(count istrings.RuneNumber, columns istrings.Width, rows int) bool
- func (b *Buffer) CursorRight(count istrings.GraphemeNumber, columns istrings.Width, rows int) bool
- func (b *Buffer) CursorRightRunes(count istrings.RuneNumber, columns istrings.Width, rows int) bool
- func (b *Buffer) CursorUp(count int, columns istrings.Width, rows int) bool
- func (b *Buffer) Delete(count istrings.GraphemeNumber, col istrings.Width, row int) string
- func (b *Buffer) DeleteBeforeCursor(count istrings.GraphemeNumber, columns istrings.Width, rows int) string
- func (b *Buffer) DeleteBeforeCursorRunes(count istrings.RuneNumber, columns istrings.Width, rows int) (deleted string)
- func (b *Buffer) DeleteRunes(count istrings.RuneNumber, col istrings.Width, row int) string
- func (b *Buffer) DisplayCursorPosition(columns istrings.Width) Position
- func (b *Buffer) Document() (d *Document)
- func (b *Buffer) InsertText(text string, overwrite bool)
- func (b *Buffer) InsertTextMoveCursor(text string, columns istrings.Width, rows int, overwrite bool)
- func (b *Buffer) JoinNextLine(separator string, col istrings.Width, row int)
- func (b *Buffer) NewLine(columns istrings.Width, rows int, copyMargin bool)
- func (b *Buffer) SwapCharactersBeforeCursor(col istrings.Width, row int)
- 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() int
- func (c *CompletionManager) Previous()
- func (c *CompletionManager) Reset()
- func (c *CompletionManager) Update(in Document)
- type CompletionManagerOption
- type DisplayAttribute
- type Document
- func (d *Document) CurrentLine() string
- func (d *Document) CurrentLineAfterCursor() string
- func (d *Document) CurrentLineBeforeCursor() string
- func (d *Document) CurrentLineIndentLevel(indentSize int) int
- func (d *Document) CurrentLineIndentSpaces() int
- func (d *Document) CurrentRuneIndex() istrings.RuneNumber
- func (d *Document) CursorPositionCol() (col istrings.Width)
- func (d *Document) CursorPositionRow() (row istrings.RuneNumber)
- func (d *Document) DisplayCursorPosition(columns istrings.Width) Position
- func (d *Document) FindEndOfCurrentWord() istrings.ByteNumber
- func (d *Document) FindEndOfCurrentWordUntilSeparator(sep string) istrings.ByteNumber
- func (d *Document) FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor(sep string) istrings.ByteNumber
- func (d *Document) FindEndOfCurrentWordWithSpace() istrings.ByteNumber
- func (d *Document) FindRuneNumberUntilEndOfCurrentWord() istrings.RuneNumber
- func (d *Document) FindRuneNumberUntilStartOfPreviousWord() istrings.RuneNumber
- func (d *Document) FindStartOfFirstWordOfLine() istrings.RuneNumber
- func (d *Document) FindStartOfPreviousWord() istrings.ByteNumber
- func (d *Document) FindStartOfPreviousWordUntilSeparator(sep string) istrings.ByteNumber
- func (d *Document) FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor(sep string) istrings.ByteNumber
- func (d *Document) FindStartOfPreviousWordWithSpace() istrings.ByteNumber
- func (d *Document) GetCharRelativeToCursor(offset istrings.RuneNumber) (r rune)
- func (d *Document) GetCursorDownPosition(count int, preferredColumn istrings.Width) istrings.RuneNumber
- func (d *Document) GetCursorLeftPosition(count istrings.GraphemeNumber) istrings.RuneNumber
- func (d *Document) GetCursorLeftPositionRunes(count istrings.RuneNumber) istrings.RuneNumber
- func (d *Document) GetCursorPosition(columns istrings.Width) Position
- func (d *Document) GetCursorRightPosition(count istrings.GraphemeNumber) istrings.RuneNumber
- func (d *Document) GetCursorRightPositionRunes(count istrings.RuneNumber) istrings.RuneNumber
- func (d *Document) GetCursorUpPosition(count int, preferredColumn istrings.Width) istrings.RuneNumber
- func (d *Document) GetEndOfLinePosition() istrings.RuneNumber
- func (d *Document) GetEndOfTextPosition(columns istrings.Width) Position
- func (d *Document) GetStartOfLinePosition() istrings.RuneNumber
- 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) IndentLevel(input string, indentSize int) int
- func (d *Document) IndentSpaces(input string) int
- func (d *Document) LastKeyStroke() Key
- func (d *Document) LastLineIndentLevel(indentSize int) int
- func (d *Document) LastLineIndentSpaces() int
- func (d *Document) LineCount() int
- func (d *Document) Lines() []string
- func (d *Document) OnLastLine() bool
- func (d *Document) PreviousLine() (s string, ok bool)
- func (d *Document) PreviousLineIndentLevel(indentSize int) int
- func (d *Document) PreviousLineIndentSpaces() int
- func (d *Document) TextAfterCursor() string
- func (d *Document) TextBeforeCursor() string
- func (d *Document) TextEndPositionRow() (row istrings.RuneNumber)
- func (d *Document) TranslateIndexToPosition(index istrings.RuneNumber) (int, int)
- func (d *Document) TranslateRowColToIndex(row int, column istrings.Width) (index istrings.RuneNumber)
- type EagerLexer
- type ExecuteOnEnterCallback
- type Executor
- type ExitChecker
- type Filter
- type History
- type Key
- type KeyBind
- type KeyBindFunc
- type KeyBindMode
- type Lexer
- type LexerFunc
- type Option
- func WithASCIICodeBind(b ...ASCIICodeBind) Option
- func WithBreakLineCallback(fn func(*Document)) Option
- func WithCompleter(c Completer) Option
- func WithCompletionOnDown() Option
- func WithCompletionWordSeparator(sep string) Option
- func WithDescriptionBGColor(x Color) Option
- func WithDescriptionTextColor(x Color) Option
- func WithExecuteOnEnterCallback(fn ExecuteOnEnterCallback) Option
- func WithExitChecker(fn ExitChecker) Option
- func WithHistory(x []string) Option
- func WithIndentSize(i int) Option
- func WithInitialText(text string) Option
- func WithInputBGColor(x Color) Option
- func WithInputTextColor(x Color) Option
- func WithKeyBind(b ...KeyBind) Option
- func WithKeyBindMode(m KeyBindMode) Option
- func WithLexer(lex Lexer) Option
- func WithMaxSuggestion(x uint16) Option
- func WithPrefix(prefix string) Option
- func WithPrefixBackgroundColor(x Color) Option
- func WithPrefixCallback(f PrefixCallback) Option
- func WithPrefixTextColor(x Color) Option
- func WithReader(r Reader) Option
- func WithScrollbarBGColor(x Color) Option
- func WithScrollbarThumbColor(x Color) Option
- func WithSelectedDescriptionBGColor(x Color) Option
- func WithSelectedDescriptionTextColor(x Color) Option
- func WithSelectedSuggestionBGColor(x Color) Option
- func WithSelectedSuggestionTextColor(x Color) Option
- func WithShowCompletionAtStart() Option
- func WithSuggestionBGColor(x Color) Option
- func WithSuggestionTextColor(x Color) Option
- func WithTitle(t string) Option
- func WithWriter(w Writer) Option
- type Position
- type PosixReader
- type PosixWriter
- type PrefixCallback
- type Prompt
- func (p *Prompt) Buffer() *Buffer
- func (p *Prompt) Close()
- func (p *Prompt) CursorDown(count int) bool
- func (p *Prompt) CursorLeft(count istrings.GraphemeNumber) bool
- func (p *Prompt) CursorLeftRunes(count istrings.RuneNumber) bool
- func (p *Prompt) CursorRight(count istrings.GraphemeNumber) bool
- func (p *Prompt) CursorRightRunes(count istrings.RuneNumber) bool
- func (p *Prompt) CursorUp(count int) bool
- func (p *Prompt) Delete(count istrings.GraphemeNumber) string
- func (p *Prompt) DeleteBeforeCursor(count istrings.GraphemeNumber) string
- func (p *Prompt) DeleteBeforeCursorRunes(count istrings.RuneNumber) string
- func (p *Prompt) DeleteRunes(count istrings.RuneNumber) string
- func (p *Prompt) IndentSize() int
- func (p *Prompt) Input() string
- func (p *Prompt) InsertText(text string, overwrite bool)
- func (p *Prompt) InsertTextMoveCursor(text string, overwrite bool)
- func (p *Prompt) Run()
- func (p *Prompt) TerminalColumns() istrings.Width
- func (p *Prompt) TerminalRows() int
- func (p *Prompt) UserInputColumns() istrings.Width
- type Reader
- type Renderer
- type SimpleToken
- type SimpleTokenOption
- 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
- func NoopCompleter(_ Document) ([]Suggest, istrings.RuneNumber, istrings.RuneNumber)
- type Token
- type UserInput
- 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) SetColor(fg, bg Color, bold bool)
- func (w *VT100Writer) SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribute)
- func (w *VT100Writer) SetTitle(title string)
- func (w *VT100Writer) ShowCursor()
- func (w *VT100Writer) UnSaveCursor()
- func (w *VT100Writer) Write(data []byte) (int, error)
- func (w *VT100Writer) WriteRaw(data []byte)
- func (w *VT100Writer) WriteRawString(data string)
- func (w *VT100Writer) WriteString(data string) (int, error)
- type WinSize
- type Writer
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 ¶
const ( DefColCount = 80 // Default column count of the terminal DefRowCount = 25 // Default row count of the terminal )
const DefaultIndentSize = 2
const IndentUnit = ' '
const IndentUnitString = string(IndentUnit)
Variables ¶
var ASCIISequences = []*ASCIICode{}/* 117 elements not displayed */
ASCIISequences holds mappings of the key and byte array.
var ( // NewStandardOutputWriter returns Writer 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 )
Functions ¶
func DefaultExecuteOnEnterCallback ¶ added in v1.0.0
func DefaultPrefixCallback ¶ added in v1.0.0
func DefaultPrefixCallback() string
func DeleteBeforeChar ¶ added in v0.2.2
DeleteBeforeChar Go to Backspace
func DeleteChar ¶ added in v0.2.2
DeleteChar Delete character under the cursor
func DeleteWordBeforeCursor ¶ added in v1.0.0
func GoLineBeginning ¶ added in v0.2.2
GoLineBeginning Go to the beginning of the line
func GoRightChar ¶ added in v0.2.2
GoRightChar Forward one character
func NoopExecutor ¶ added in v1.0.0
func NoopExecutor(in string)
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). Returns true when the view should be rerendered.
func (*Buffer) CursorLeft ¶
Move to the left on the current line by the given amount of graphemes. Returns true when the view should be rerendered.
func (*Buffer) CursorLeftRunes ¶ added in v1.1.0
Move to the left on the current line by the given amount of runes. Returns true when the view should be rerendered.
func (*Buffer) CursorRight ¶
Move to the right on the current line by the given amount of graphemes. Returns true when the view should be rerendered.
func (*Buffer) CursorRightRunes ¶ added in v1.1.0
Move to the right on the current line by the given amount of runes. Returns true when the view should be rerendered.
func (*Buffer) CursorUp ¶
CursorUp move cursor to the previous line. (for multi-line edit). Returns true when the view should be rerendered.
func (*Buffer) DeleteBeforeCursor ¶
func (b *Buffer) DeleteBeforeCursor(count istrings.GraphemeNumber, columns istrings.Width, rows int) string
Deletes the specified number of graphemes before the cursor and returns the deleted text.
func (*Buffer) DeleteBeforeCursorRunes ¶ added in v1.1.0
func (b *Buffer) DeleteBeforeCursorRunes(count istrings.RuneNumber, columns istrings.Width, rows int) (deleted string)
Deletes the specified number of runes before the cursor and returns the deleted text.
func (*Buffer) DeleteRunes ¶ added in v1.1.0
Deletes the specified number of runes and returns 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 ¶
Insert string into the buffer without moving the cursor.
func (*Buffer) InsertTextMoveCursor ¶ added in v1.0.0
func (b *Buffer) InsertTextMoveCursor(text string, columns istrings.Width, rows int, overwrite bool)
Insert string into the buffer and move the cursor.
func (*Buffer) JoinNextLine ¶
JoinNextLine joins the next line to the current one by deleting the line ending after the current line.
func (*Buffer) SwapCharactersBeforeCursor ¶
SwapCharactersBeforeCursor swaps the last two characters before the cursor.
type Color ¶
type Color int
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 Completer ¶
type Completer func(Document) (suggestions []Suggest, startChar, endChar istrings.RuneNumber)
Completer is a function that returns a slice of suggestions for the given Document.
startChar and endChar represent the indices of the first and last rune of the text that the suggestions were generated for and that should be replaced by the selected suggestion.
type CompletionManager ¶
type CompletionManager struct {
// contains filtered or unexported fields
}
CompletionManager manages which suggestion is now selected.
func NewCompletionManager ¶
func NewCompletionManager(max uint16, opts ...CompletionManagerOption) *CompletionManager
NewCompletionManager returns an initialized CompletionManager object.
func (*CompletionManager) Completing ¶
func (c *CompletionManager) Completing() bool
Completing returns true when the CompletionManager selects something.
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() int
Next to select the next suggestion item.
func (*CompletionManager) Previous ¶
func (c *CompletionManager) Previous()
Select the previous suggestion item.
func (*CompletionManager) Reset ¶
func (c *CompletionManager) Reset()
Unselect the currently selected suggestion.
func (*CompletionManager) Update ¶
func (c *CompletionManager) Update(in Document)
Update the suggestions.
type CompletionManagerOption ¶ added in v1.0.0
type CompletionManagerOption func(*CompletionManager)
Constructor option for CompletionManager.
func CompletionManagerWithCompleter ¶ added in v1.0.0
func CompletionManagerWithCompleter(completer Completer) CompletionManagerOption
Set a custom completer.
type DisplayAttribute ¶ added in v0.2.2
type DisplayAttribute int
DisplayAttribute represents display attributes like Blinking, Bold, Italic and so on.
const ( // DisplayReset reset all display attributes. DisplayReset DisplayAttribute = iota // DisplayBold set bold or increases intensity. DisplayBold // DisplayLowIntensity decreases intensity. Not widely supported. DisplayLowIntensity // DisplayItalic set italic. Not widely supported. DisplayItalic // DisplayUnderline set underline DisplayUnderline // DisplayBlink set blink (less than 150 per minute). DisplayBlink // DisplayRapidBlink set blink (more than 150 per minute). Not widely supported. DisplayRapidBlink // DisplayReverse swap foreground and background colors. DisplayReverse // DisplayInvisible set invisible. Not widely supported. DisplayInvisible // DisplayCrossedOut set characters legible, but marked for deletion. Not widely supported. DisplayCrossedOut // DisplayDefaultFont set primary(default) font DisplayDefaultFont )
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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`Hello! my name is c-bata. This is a exam`), } fmt.Println(d.CurrentLineBeforeCursor())
Output: This is a exam
func (*Document) CurrentLineIndentLevel ¶ added in v1.1.3
Returns the indentation level of the current line the cursor is on.
func (*Document) CurrentLineIndentSpaces ¶ added in v1.1.3
Returns the amount of spaces that the current line the cursor is on is indented with.
func (*Document) CurrentRuneIndex ¶ added in v1.0.0
func (d *Document) CurrentRuneIndex() istrings.RuneNumber
Returns the index of the rune that's under the cursor.
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: istrings.RuneCountInString(`Hello! my name is c-bata. This is a exam`), } fmt.Println("CursorPositionCol", d.CursorPositionCol())
Output: CursorPositionCol 14
func (*Document) CursorPositionRow ¶
func (d *Document) CursorPositionRow() (row istrings.RuneNumber)
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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`Hello`), } fmt.Println("DisplayCursorPosition", d.DisplayCursorPosition(50))
Output: DisplayCursorPosition {5 0}
Example (WithJapanese) ¶
d := &Document{ Text: `こんにちは、芝田 将です。`, cursorPosition: 3, } fmt.Println("DisplayCursorPosition", d.DisplayCursorPosition(30))
Output: DisplayCursorPosition {6 0}
func (*Document) FindEndOfCurrentWord ¶ added in v0.2.2
func (d *Document) FindEndOfCurrentWord() istrings.ByteNumber
FindEndOfCurrentWord returns a byte 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
func (d *Document) FindEndOfCurrentWordUntilSeparator(sep string) istrings.ByteNumber
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
func (d *Document) FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor(sep string) istrings.ByteNumber
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
func (d *Document) FindEndOfCurrentWordWithSpace() istrings.ByteNumber
FindEndOfCurrentWordWithSpace is almost the same as FindEndOfCurrentWord. The only difference is to ignore contiguous spaces.
func (*Document) FindRuneNumberUntilEndOfCurrentWord ¶ added in v1.0.0
func (d *Document) FindRuneNumberUntilEndOfCurrentWord() istrings.RuneNumber
Returns the number of runes of the text after the cursor until the end of the current word.
func (*Document) FindRuneNumberUntilStartOfPreviousWord ¶ added in v1.0.0
func (d *Document) FindRuneNumberUntilStartOfPreviousWord() istrings.RuneNumber
Returns the rune count of the text before the cursor until the start of the previous word.
func (*Document) FindStartOfFirstWordOfLine ¶ added in v1.0.0
func (d *Document) FindStartOfFirstWordOfLine() istrings.RuneNumber
GetStartOfLinePosition returns relative position for the start of this line.
func (*Document) FindStartOfPreviousWord ¶
func (d *Document) FindStartOfPreviousWord() istrings.ByteNumber
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
func (d *Document) FindStartOfPreviousWordUntilSeparator(sep string) istrings.ByteNumber
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
func (d *Document) FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor(sep string) istrings.ByteNumber
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
func (d *Document) FindStartOfPreviousWordWithSpace() istrings.ByteNumber
FindStartOfPreviousWordWithSpace is almost the same as FindStartOfPreviousWord. The only difference is to ignore contiguous spaces.
func (*Document) GetCharRelativeToCursor ¶
func (d *Document) GetCharRelativeToCursor(offset istrings.RuneNumber) (r rune)
GetCharRelativeToCursor return character relative to cursor position, or empty string
func (*Document) GetCursorDownPosition ¶
func (d *Document) GetCursorDownPosition(count int, preferredColumn istrings.Width) istrings.RuneNumber
GetCursorDownPosition return the relative cursor position (character index) where we would be if the user pressed the arrow-down button.
func (*Document) GetCursorLeftPosition ¶
func (d *Document) GetCursorLeftPosition(count istrings.GraphemeNumber) istrings.RuneNumber
Returns the amount of runes that the cursors should be moved by. The `count` argument tells this function by how many graphemes (visible characters) the cursor should be moved (to the left).
func (*Document) GetCursorLeftPositionRunes ¶ added in v1.1.0
func (d *Document) GetCursorLeftPositionRunes(count istrings.RuneNumber) istrings.RuneNumber
Returns the amount of runes that the cursors should be moved by. The `count` argument tells this function by how many runes the cursor should be moved (to the left).
func (*Document) GetCursorPosition ¶ added in v1.0.0
Get the current cursor position.
func (*Document) GetCursorRightPosition ¶
func (d *Document) GetCursorRightPosition(count istrings.GraphemeNumber) istrings.RuneNumber
Returns the amount of runes that the cursors should be moved by. The `count` argument tells this function by how many graphemes (visible characters) the cursor should be moved (to the right).
func (*Document) GetCursorRightPositionRunes ¶ added in v1.1.0
func (d *Document) GetCursorRightPositionRunes(count istrings.RuneNumber) istrings.RuneNumber
Returns the amount of runes that the cursors should be moved by. The `count` argument tells this function by how many runes the cursor should be moved (to the right).
func (*Document) GetCursorUpPosition ¶
func (d *Document) GetCursorUpPosition(count int, preferredColumn istrings.Width) istrings.RuneNumber
GetCursorUpPosition return the relative cursor position (character index) where we would be if the user pressed the arrow-up button.
func (*Document) GetEndOfLinePosition ¶
func (d *Document) GetEndOfLinePosition() istrings.RuneNumber
GetEndOfLinePosition returns relative position for the end of this line.
func (*Document) GetEndOfTextPosition ¶ added in v1.0.0
Get the position of the end of the current text.
func (*Document) GetStartOfLinePosition ¶ added in v1.0.0
func (d *Document) GetStartOfLinePosition() istrings.RuneNumber
GetStartOfLinePosition returns relative position for the start 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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`Hello! my name is c-bata. This is a example `), } fmt.Println(d.GetWordBeforeCursorWithSpace())
Output: example
func (*Document) IndentLevel ¶ added in v1.1.3
Returns the indentation level of the last line of the given text.
func (*Document) IndentSpaces ¶ added in v1.1.3
Returns the amount of spaces that the last line of input of the given text is indented with.
func (*Document) LastKeyStroke ¶ added in v1.0.0
LastKeyStroke return the last key pressed in this document.
func (*Document) LastLineIndentLevel ¶ added in v1.1.0
Returns the indentation level of the last line of input.
func (*Document) LastLineIndentSpaces ¶ added in v1.1.0
Returns the amount of spaces that the last line of input is indented with.
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) PreviousLine ¶ added in v1.1.4
Return the text of the previous line (relative to the cursor). If the cursor is on the first line then false is returned in the second value to signify that there is no previous line.
func (*Document) PreviousLineIndentLevel ¶ added in v1.1.4
Returns the indentation level of the previous line (relative to the cursor).
func (*Document) PreviousLineIndentSpaces ¶ added in v1.1.4
Returns the amount of spaces that the previous line (relative to the cursor) is indented with.
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: istrings.RuneCountInString(`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: istrings.RuneCountInString(`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) TextEndPositionRow ¶ added in v1.0.0
func (d *Document) TextEndPositionRow() (row istrings.RuneNumber)
TextEndPositionRow returns the row of the end of the current text. (0-based.)
func (*Document) TranslateIndexToPosition ¶
func (d *Document) TranslateIndexToPosition(index istrings.RuneNumber) (int, int)
TranslateIndexToPosition given an index for the text, return the corresponding (row, col) tuple. (0-based. Returns (0, 0) for index=0.)
func (*Document) TranslateRowColToIndex ¶
func (d *Document) TranslateRowColToIndex(row int, column istrings.Width) (index istrings.RuneNumber)
TranslateRowColToIndex given a (row, col), return the corresponding index. (Row and col params are 0-based.)
type EagerLexer ¶ added in v1.0.0
type EagerLexer struct {
// contains filtered or unexported fields
}
EagerLexer is a wrapper around LexerFunc that transforms an eager lexer which produces an array with all tokens at once into a streaming lexer compatible with go-prompt.
func NewEagerLexer ¶ added in v1.0.0
func NewEagerLexer(fn LexerFunc) *EagerLexer
Create a new EagerLexer.
func (*EagerLexer) Init ¶ added in v1.0.0
func (l *EagerLexer) Init(input string)
Initialise the lexer with the given input.
func (*EagerLexer) Next ¶ added in v1.0.0
func (l *EagerLexer) Next() (Token, bool)
Return the next token and true if the operation was successful.
type ExecuteOnEnterCallback ¶ added in v1.0.0
ExecuteOnEnterCallback is a function that receives user input after Enter has been pressed and determines whether the input should be executed. If this function returns true, the Executor callback will be called otherwise a newline will be added to the buffer containing user input and optionally indentation made up of `indentSize * indent` spaces.
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 AltRight Left AltLeft ShiftLeft ShiftUp ShiftDown ShiftRight Home End Delete ShiftDelete ControlDelete PageUp PageDown BackTab Insert Backspace AltBackspace // 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 KeyBindFunc ¶
KeyBindFunc receives buffer and processed it.
type KeyBindMode ¶
type KeyBindMode uint8
KeyBindMode to switch a key binding flexibly.
const ( // CommonKeyBind is a mode without any keyboard shortcut CommonKeyBind KeyBindMode = iota // EmacsKeyBind is a mode to use emacs-like keyboard shortcut EmacsKeyBind )
type Lexer ¶ added in v1.0.0
type Lexer interface { Init(string) // Reset the lexer's state and initialise it with the given input. // Next returns the next Token and a bool flag // which is false when the end of input has been reached. Next() (Token, bool) }
Lexer is a streaming lexer that takes in a piece of text and streams tokens with the Next() method
type LexerFunc ¶ added in v1.0.0
LexerFunc is a function implementing a simple lexer that receives a string and returns a complete slice of Tokens.
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 WithASCIICodeBind ¶ added in v1.0.0
func WithASCIICodeBind(b ...ASCIICodeBind) Option
WithASCIICodeBind to set a custom key bind.
func WithBreakLineCallback ¶ added in v1.0.0
WithBreakLineCallback to run a callback at every break line
func WithCompleter ¶ added in v1.0.0
WithCompleter is an option that sets a custom Completer object.
func WithCompletionOnDown ¶ added in v1.0.0
func WithCompletionOnDown() Option
WithCompletionOnDown allows for Down arrow key to trigger completion.
func WithCompletionWordSeparator ¶ added in v1.0.0
WithCompletionWordSeparator can be used to set word separators. Enable only ' ' if empty.
func WithDescriptionBGColor ¶ added in v1.0.0
WithDescriptionBGColor to change a background color of description text in drop down suggestions.
func WithDescriptionTextColor ¶ added in v1.0.0
WithDescriptionTextColor to change a background color of description text in drop down suggestions.
func WithExecuteOnEnterCallback ¶ added in v1.0.0
func WithExecuteOnEnterCallback(fn ExecuteOnEnterCallback) Option
WithExecuteOnEnterCallback can be used to set a custom callback function that determines whether an Enter key should trigger the Executor or add a newline to the user input buffer.
func WithExitChecker ¶ added in v1.0.0
func WithExitChecker(fn ExitChecker) Option
WithExitChecker set an exit function which checks if go-prompt exits its Run loop
func WithHistory ¶ added in v1.0.0
WithHistory to set history expressed by string array.
func WithIndentSize ¶ added in v1.0.0
WithIndentSize is an option that sets the amount of spaces that constitute a single indentation level.
func WithInitialText ¶ added in v1.0.0
WithInitialText can be used to set the initial buffer text.
func WithInputBGColor ¶ added in v1.0.0
WithInputBGColor to change a color of background which is input by user
func WithInputTextColor ¶ added in v1.0.0
WithInputTextColor to change a color of text which is input by user
func WithKeyBind ¶ added in v1.0.0
WithKeyBind to set a custom key bind.
func WithKeyBindMode ¶ added in v1.0.0
func WithKeyBindMode(m KeyBindMode) Option
WithKeyBindMode set a key bind mode.
func WithMaxSuggestion ¶ added in v1.0.0
WithMaxSuggestion specify the max number of displayed suggestions.
func WithPrefix ¶ added in v1.0.0
WithPrefix can be used to set a prefix string for the prompt.
func WithPrefixBackgroundColor ¶ added in v1.0.0
WithPrefixBackgroundColor to change a background color of prefix string
func WithPrefixCallback ¶ added in v1.0.0
func WithPrefixCallback(f PrefixCallback) Option
WithPrefixCallback can be used to change the prefix dynamically by a callback function.
func WithPrefixTextColor ¶ added in v1.0.0
WithPrefixTextColor change a text color of prefix string
func WithReader ¶ added in v1.0.0
WithReader can be used to set a custom Reader object.
func WithScrollbarBGColor ¶ added in v1.0.0
WithScrollbarBGColor to change a background color of scrollbar.
func WithScrollbarThumbColor ¶ added in v1.0.0
WithScrollbarThumbColor to change a thumb color on scrollbar.
func WithSelectedDescriptionBGColor ¶ added in v1.0.0
WithSelectedDescriptionBGColor to change a background color of description which is selected inside suggestions drop down box.
func WithSelectedDescriptionTextColor ¶ added in v1.0.0
WithSelectedDescriptionTextColor to change a text color of description which is selected inside suggestions drop down box.
func WithSelectedSuggestionBGColor ¶ added in v1.0.0
WithSelectedSuggestionBGColor to change a background color for completed text which is selected inside suggestions drop down box.
func WithSelectedSuggestionTextColor ¶ added in v1.0.0
WithSelectedSuggestionTextColor to change a text color for completed text which is selected inside suggestions drop down box.
func WithShowCompletionAtStart ¶ added in v1.0.0
func WithShowCompletionAtStart() Option
WithShowCompletionAtStart to set completion window is open at start.
func WithSuggestionBGColor ¶ added in v1.0.0
WithSuggestionBGColor change a background color in drop down suggestions.
func WithSuggestionTextColor ¶ added in v1.0.0
WithSuggestionTextColor to change a text color in drop down suggestions.
func WithTitle ¶ added in v1.0.0
WithTitle can be used to set the title displayed at the header bar of the terminal.
func WithWriter ¶ added in v1.0.0
WithWriter can be used to set a custom Writer object.
type Position ¶ added in v1.0.0
Position stores the coordinates of a p.
(0, 0) represents the top-left corner of the prompt, while (n, n) the bottom-right corner.
type PosixReader ¶ added in v1.0.0
type PosixReader struct {
// contains filtered or unexported fields
}
PosixReader is a Reader implementation for the POSIX environment.
func NewStdinReader ¶ added in v1.0.0
func NewStdinReader() *PosixReader
NewStdinReader returns Reader object to read from stdin.
func (*PosixReader) Close ¶ added in v1.0.0
func (t *PosixReader) Close() error
Close should be called after stopping input
func (*PosixReader) GetWinSize ¶ added in v1.0.0
func (t *PosixReader) GetWinSize() *WinSize
GetWinSize returns WinSize object to represent width and height of terminal.
func (*PosixReader) Open ¶ added in v1.0.0
func (t *PosixReader) Open() error
Open should be called before starting input
type PosixWriter ¶ added in v0.2.0
type PosixWriter struct { VT100Writer // contains filtered or unexported fields }
PosixWriter is a Writer 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 PrefixCallback ¶ added in v1.0.0
type PrefixCallback func() (prefix string)
Callback function that returns a prompt prefix.
type Prompt ¶
type Prompt struct { ASCIICodeBindings []ASCIICodeBind // contains filtered or unexported fields }
Prompt is a core struct of go-prompt.
func (*Prompt) CursorDown ¶ added in v1.0.0
Move the cursor down. Returns true when the view should be rerendered.
func (*Prompt) CursorLeft ¶ added in v1.0.0
func (p *Prompt) CursorLeft(count istrings.GraphemeNumber) bool
Move to the left on the current line by the given amount of graphemes (visible characters). Returns true when the view should be rerendered.
func (*Prompt) CursorLeftRunes ¶ added in v1.1.0
func (p *Prompt) CursorLeftRunes(count istrings.RuneNumber) bool
Move to the left on the current line by the given amount of runes. Returns true when the view should be rerendered.
func (*Prompt) CursorRight ¶ added in v1.0.0
func (p *Prompt) CursorRight(count istrings.GraphemeNumber) bool
Move the cursor to the right on the current line by the given amount of graphemes (visible characters). Returns true when the view should be rerendered.
func (*Prompt) CursorRightRunes ¶ added in v1.1.0
func (p *Prompt) CursorRightRunes(count istrings.RuneNumber) bool
Move the cursor to the right on the current line by the given amount of runes. Returns true when the view should be rerendered.
func (*Prompt) CursorUp ¶ added in v1.0.0
Move the cursor up. Returns true when the view should be rerendered.
func (*Prompt) Delete ¶ added in v1.1.2
func (p *Prompt) Delete(count istrings.GraphemeNumber) string
Deletes the specified number of graphemes and returns the deleted text.
func (*Prompt) DeleteBeforeCursor ¶ added in v1.1.2
func (p *Prompt) DeleteBeforeCursor(count istrings.GraphemeNumber) string
Deletes the specified number of graphemes before the cursor and returns the deleted text.
func (*Prompt) DeleteBeforeCursorRunes ¶ added in v1.1.2
func (p *Prompt) DeleteBeforeCursorRunes(count istrings.RuneNumber) string
Deletes the specified number of runes before the cursor and returns the deleted text.
func (*Prompt) DeleteRunes ¶ added in v1.1.2
func (p *Prompt) DeleteRunes(count istrings.RuneNumber) string
Deletes the specified number of runes and returns the deleted text.
func (*Prompt) IndentSize ¶ added in v1.1.0
Returns the configured indent size.
func (*Prompt) Input ¶
Input starts the prompt, lets the user input a single line and returns this line as a string.
func (*Prompt) InsertText ¶ added in v1.1.2
Insert string into the buffer without moving the cursor.
func (*Prompt) InsertTextMoveCursor ¶ added in v1.1.2
Insert string into the buffer and move the cursor.
func (*Prompt) TerminalColumns ¶ added in v1.1.1
Returns the current amount of columns that the terminal can display.
func (*Prompt) TerminalRows ¶ added in v1.1.1
Returns the current amount of rows that the terminal can display.
func (*Prompt) UserInputColumns ¶ added in v1.1.2
Get the number of columns that are available for user input.
type Reader ¶ added in v1.0.0
type Reader interface { // Open should be called before starting reading Open() error // GetWinSize returns WinSize object to represent width and height of terminal. GetWinSize() *WinSize io.ReadCloser }
Reader is an interface to abstract input layer.
type Renderer ¶ added in v1.0.0
type Renderer struct {
// contains filtered or unexported fields
}
Takes care of the rendering process
func (*Renderer) Render ¶ added in v1.0.0
func (r *Renderer) Render(buffer *Buffer, completion *CompletionManager, lexer Lexer)
Render renders to the console.
func (*Renderer) Setup ¶ added in v1.0.0
func (r *Renderer) Setup()
Setup to initialize console output.
func (*Renderer) UpdateWinSize ¶ added in v1.0.0
UpdateWinSize called when window size is changed.
func (*Renderer) UserInputColumns ¶ added in v1.0.0
Get the number of columns that are available for user input.
type SimpleToken ¶ added in v1.0.0
type SimpleToken struct {
// contains filtered or unexported fields
}
SimpleToken as the default implementation of Token.
func NewSimpleToken ¶ added in v1.0.0
func NewSimpleToken(firstIndex, lastIndex istrings.ByteNumber, opts ...SimpleTokenOption) *SimpleToken
Create a new SimpleToken.
func (*SimpleToken) BackgroundColor ¶ added in v1.0.2
func (t *SimpleToken) BackgroundColor() Color
Retrieve the background color of this token.
func (*SimpleToken) Color ¶ added in v1.0.0
func (t *SimpleToken) Color() Color
Retrieve the text color of this token.
func (*SimpleToken) DisplayAttributes ¶ added in v1.0.2
func (t *SimpleToken) DisplayAttributes() []DisplayAttribute
Retrieve the display attributes of this token eg. bold, underline.
func (*SimpleToken) FirstByteIndex ¶ added in v1.0.1
func (t *SimpleToken) FirstByteIndex() istrings.ByteNumber
The index of the first byte of the lexeme.
func (*SimpleToken) LastByteIndex ¶ added in v1.0.0
func (t *SimpleToken) LastByteIndex() istrings.ByteNumber
The index of the last byte of the lexeme.
type SimpleTokenOption ¶ added in v1.0.2
type SimpleTokenOption func(*SimpleToken)
func SimpleTokenWithBackgroundColor ¶ added in v1.0.2
func SimpleTokenWithBackgroundColor(c Color) SimpleTokenOption
func SimpleTokenWithColor ¶ added in v1.0.2
func SimpleTokenWithColor(c Color) SimpleTokenOption
func SimpleTokenWithDisplayAttributes ¶ added in v1.0.2
func SimpleTokenWithDisplayAttributes(attrs ...DisplayAttribute) SimpleTokenOption
type Suggest ¶
Suggest represents a single suggestion in the auto-complete box.
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.
func FilterHasSuffix ¶
FilterHasSuffix checks whether the completion.Text ends with sub.
func NoopCompleter ¶ added in v1.0.0
func NoopCompleter(_ Document) ([]Suggest, istrings.RuneNumber, istrings.RuneNumber)
NoopCompleter implements a Completer function that always returns no suggestions.
type Token ¶ added in v1.0.0
type Token interface { Color() Color // Color of the token's text BackgroundColor() Color DisplayAttributes() []DisplayAttribute FirstByteIndex() istrings.ByteNumber // Index of the last byte of this token LastByteIndex() istrings.ByteNumber // Index of the last byte of this token }
Token is a single unit of text returned by a Lexer.
type UserInput ¶ added in v1.0.0
type UserInput struct {
// contains filtered or unexported fields
}
UserInput is the struct that contains the user input context.
type VT100Writer ¶
type VT100Writer struct {
// contains filtered or unexported fields
}
VT100Writer generates VT100 escape sequences.
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) SetColor ¶
func (w *VT100Writer) SetColor(fg, bg Color, bold bool)
SetColor sets text and background colors. and specify whether text is bold.
func (*VT100Writer) SetDisplayAttributes ¶ added in v0.2.2
func (w *VT100Writer) SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribute)
SetDisplayAttributes to set VT100 display attributes.
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.
func (*VT100Writer) Write ¶
func (w *VT100Writer) Write(data []byte) (int, error)
Write to write safety byte array by removing control sequences.
func (*VT100Writer) WriteRaw ¶
func (w *VT100Writer) WriteRaw(data []byte)
WriteRaw to write raw byte array
func (*VT100Writer) WriteRawString ¶ added in v1.0.0
func (w *VT100Writer) WriteRawString(data string)
WriteRawString to write raw string
func (*VT100Writer) WriteString ¶ added in v1.0.0
func (w *VT100Writer) WriteString(data string) (int, error)
WriteString to write safety string by removing control sequences.
type Writer ¶ added in v1.0.0
type Writer interface { io.Writer io.StringWriter // WriteRaw to write raw byte array. WriteRaw(data []byte) // WriteString to write raw string. WriteRawString(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) // Sets the colors and display attributes. SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribute) }
Writer is an interface to abstract the output layer.
func NewStderrWriter ¶ added in v0.2.3
func NewStderrWriter() Writer
NewStderrWriter returns Writer 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() Writer
NewStdoutWriter returns Writer object to write to stdout. This generates VT100 escape sequences because almost terminal emulators in POSIX OS built on top of a VT100 specification.