Documentation
¶
Index ¶
- 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) Reset()
- func (b *Buffer) SwapCharactersBeforeCursor()
- func (b *Buffer) Text() string
- 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) 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)
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 ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
FindEndOfCurrentWordUntilSeparator is almost the same as FindEndOfCurrentWord. But this can specify Separator. Return 0 if nothing was found.
func (*Document) FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor ¶
FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor is almost the same as FindEndOfCurrentWordWithSpace. But this can specify Separator. Return 0 if nothing was found.
func (*Document) FindEndOfCurrentWordWithSpace ¶
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 ¶
FindStartOfPreviousWordUntilSeparator is almost the same as FindStartOfPreviousWord. But this can specify Separator. Return 0 if nothing was found.
func (*Document) FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor ¶
FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor is almost the same as FindStartOfPreviousWordWithSpace. But this can specify Separator. Return 0 if nothing was found.
func (*Document) FindStartOfPreviousWordWithSpace ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) 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.)