Documentation ¶
Index ¶
- Variables
- func EnableSurrogatePair(value bool)
- func IsSurrogatePairEnabled() bool
- func ResetCharWidth()
- func SetCharWidth(c rune, width int)
- type AnonymousCommand
- type Buffer
- func (B *Buffer) CurrentWord() (string, int)
- func (B *Buffer) CurrentWordTop() (wordTop int)
- func (B *Buffer) Delete(pos int, n int) WidthT
- func (B *Buffer) DrawFromHead()
- func (B *Buffer) GetKey() (string, error)
- func (B *Buffer) GetWidthBetween(from int, to int) WidthT
- func (B *Buffer) GotoHead()
- func (B *Buffer) InsertAndRepaint(str string)
- func (B *Buffer) InsertString(pos int, s string) int
- func (B *Buffer) RepaintAfterPrompt()
- func (B *Buffer) RepaintAll()
- func (B *Buffer) ReplaceAndRepaint(pos int, str string)
- func (B *Buffer) ResetViewStart()
- func (B Buffer) String() string
- func (B *Buffer) SubString(start, end int) string
- func (B *Buffer) ViewWidth() WidthT
- type Cell
- type ColorSequence
- type Coloring
- type Command
- type Editor
- type GoCommand
- type IHistory
- type ITty
- type KeyGoFuncTdeprecated
- type KeyMap
- func (km *KeyMap) BindKey(key keys.Code, f Command)
- func (km *KeyMap) BindKeyClosure(name string, f func(context.Context, *Buffer) Result) errordeprecated
- func (km *KeyMap) BindKeyFunc(key string, f Command) errordeprecated
- func (km *KeyMap) BindKeySymbol(key, funcName string) errordeprecated
- func (km *KeyMap) GetBindKey(key string) Commanddeprecated
- type Moji
- type Result
- type SelfInserter
- type WidthT
- func GetStringWidth(s string) WidthTdeprecated
Constants ¶
This section is empty.
Variables ¶
var CmdAcceptLine = NewGoCommand("ACCEPT_LINE", cmdAcceptLine)
CmdAcceptLine is the command that ends the editing successfully (for Ctrl-M) Then the method `(*Editor) ReadLine()` returns nil as error.
var CmdBackwardChar = NewGoCommand("BACKWARD_CHAR", cmdBackwardChar)
CmdBackwardChar is the command that moves cursor to the previous character (for Ctrl-B)
var CmdBackwardDeleteChar = NewGoCommand("BACKWARD_DELETE_CHAR", cmdBackwardDeleteChar)
CmdBackwardDeleteChar is the command that deletes a character on the leftside of cursor (for Backspace)
var CmdBackwardWord = NewGoCommand("BACKWARD_WORD", cmdBackwardWord)
CmdBackwardWord is the command that moves cursor to the top of the previous word (for M-B)
var CmdBeginningOfLine = NewGoCommand("BEGINNING_OF_LINE", cmdBeginningOfLine)
CmdBeginningOfLine is the command that moves cursor to the top of line (for Ctrl-A)
var CmdClearScreen = NewGoCommand("CLEAR_SCREEN", cmdClearScreen)
CmdClearScreen is the command that clears the screen and repaints the line (for Ctrl-L)
var CmdDeleteChar = NewGoCommand("DELETE_CHAR", cmdDeleteChar)
CmdDeleteChar is the command that delete a character on the cursor (for Del)
var CmdDeleteOrAbort = NewGoCommand("DELETE_OR_ABORT", cmdDeleteOrAbort)
CmdDeleteOrAbort is the command that deletes a character on the cursor when the line has any characters. Otherwise quit the editing (for Ctrl-D)
var CmdEndOfLine = NewGoCommand("END_OF_LINE", cmdEndOfLine)
CmdEndOfLine is the command that moves cursor to the end of the line (for Ctrl-E)
var CmdForwardChar = NewGoCommand("FORWARD_CHAR", cmdForwardChar)
CmdForwardChar is the command that moves cursor to the next character (for Ctrl-F)
var CmdForwardWord = NewGoCommand("FORWARD_WORD", cmdForwardWord)
CmdForwardWord is the command that move cursor to the top of the next word (for M-F)
var CmdISearchBackward = NewGoCommand("ISEARCH_BACKWARD", cmdISearchBackward)
CmdISearchBackward is the command that enters incremental-search-mode. (Ctrl-I)
var CmdInterrupt = NewGoCommand("INTR", cmdInterrupt)
CmdInterrupt is the command that aborts the editing (for Ctrl-C) Then the method `(*Editor) ReadLine()` returns `readline.CtrlC` as error.
var CmdKillLine = NewGoCommand("KILL_LINE", cmdKillLine)
CmdKillLine is the command that removes text from cursor to the end of the line (for Ctrl-K)
var CmdKillWholeLine = NewGoCommand("KILL_WHOLE_LINE", cmdKillWholeLine)
CmdKillWholeLine is the command that removes the whole characters of the line.
var CmdNextHistory = NewGoCommand("NEXT_HISTORY", cmdNextHistory)
CmdNextHistory is the command that replaces the line to the next entry of the history. (Ctrl-N)
var CmdPreviousHistory = NewGoCommand("PREVIOUS_HISTORY", cmdPreviousHistory)
CmdPreviousHistory is the command that replaces the line to the previous entry in the history (Ctrl-P)
var CmdQuotedInsert = NewGoCommand("QUOTED_INSERT", cmdQuotedInsert)
CmdQuotedInsert is the command that inserts the next typed character itself even if it is a control-character (for Ctrl-V or Ctrl-Q)
var CmdRepaintOnNewline = NewGoCommand("REPAINT_ON_NEWLINE", cmdRepaintOnNewline)
var CmdSwapChar = NewGoCommand("SWAPCHAR", cmdSwapChar)
CmdSwapChar is the command that swaps the character on the cursor and on on the leftside of the cursor (for Ctrl-T)
var CmdUndo = NewGoCommand("UNDO", cmdUndo)
CmdUndo is the command that executes undo (for Ctrl-U)
var CmdUnixLineDiscard = NewGoCommand("UNIX_LINE_DISCARD", cmdUnixLineDiscard)
CmdUnixLineDiscard is the command that removes from the top of the line until cursor. (for Ctrl-U)
var CmdUnixWordRubout = NewGoCommand("UNIX_WORD_RUBOUT", cmdUnixWordRubout)
CmdUnixWordRubout is the command that removes the current word (for Ctrl-W)
var CmdYank = NewGoCommand("YANK", cmdYank)
CmdYank is the command that inserts the string in the clipboard (for Ctrl-Y)
var CmdYankWithQuote = NewGoCommand("YANK_WITH_QUOTE", cmdYankWithQuote)
CmdYankWithQuote is the command that inserts the string in the clipboard and enclose it with double quoatations.
var CtrlC = errors.New("^C")
CtrlC is the error when Ctrl-C is pressed.
var Delimiters = "\"'"
Delimiters means the quationmarks. The whitespace enclosed by them are not treat as parameters separator.
var GlobalKeyMap = &KeyMap{ KeyMap: map[keys.Code]Command{ keys.AltB: CmdBackwardWord, keys.AltF: CmdForwardWord, keys.AltV: CmdYank, keys.AltY: CmdYankWithQuote, keys.Backspace: CmdBackwardDeleteChar, keys.CtrlA: CmdBeginningOfLine, keys.CtrlB: CmdBackwardChar, keys.CtrlC: CmdInterrupt, keys.CtrlD: CmdDeleteOrAbort, keys.CtrlE: CmdEndOfLine, keys.CtrlF: CmdForwardChar, keys.CtrlH: CmdBackwardDeleteChar, keys.CtrlK: CmdKillLine, keys.CtrlL: CmdClearScreen, keys.CtrlLeft: CmdBackwardWord, keys.CtrlM: CmdAcceptLine, keys.CtrlN: CmdNextHistory, keys.CtrlP: CmdPreviousHistory, keys.CtrlQ: CmdQuotedInsert, keys.CtrlR: CmdISearchBackward, keys.CtrlRight: CmdForwardWord, keys.CtrlT: CmdSwapChar, keys.CtrlU: CmdUnixLineDiscard, keys.CtrlUnderbar: CmdUndo, keys.CtrlV: CmdQuotedInsert, keys.CtrlW: CmdUnixWordRubout, keys.CtrlY: CmdYank, keys.CtrlZ: CmdUndo, keys.Delete: CmdDeleteChar, keys.Down: CmdNextHistory, keys.End: CmdEndOfLine, keys.Escape: CmdKillWholeLine, keys.Home: CmdBeginningOfLine, keys.Left: CmdBackwardChar, keys.Right: CmdForwardChar, keys.Up: CmdPreviousHistory, }, }
GlobalKeyMap is the global keymap for users' customizing
Functions ¶
func EnableSurrogatePair ¶ added in v0.11.0
func EnableSurrogatePair(value bool)
func IsSurrogatePairEnabled ¶ added in v0.11.0
func IsSurrogatePairEnabled() bool
func ResetCharWidth ¶
func ResetCharWidth()
func SetCharWidth ¶
Types ¶
type AnonymousCommand ¶ added in v0.11.2
func (AnonymousCommand) Call ¶ added in v0.11.2
func (f AnonymousCommand) Call(ctx context.Context, B *Buffer) Result
func (AnonymousCommand) String ¶ added in v0.11.2
func (f AnonymousCommand) String() string
type Buffer ¶
type Buffer struct { *Editor Buffer []Cell ViewStart int // contains filtered or unexported fields }
Buffer is ReadLine's internal data structure
func (*Buffer) CurrentWord ¶
CurrentWord returns the current word the cursor exists and word's position
func (*Buffer) CurrentWordTop ¶
CurrentWordTop returns the position of the current word the cursor exists
func (*Buffer) Delete ¶
Delete remove Buffer[pos:pos+n]. It returns the width to clear the end of line. It does not update screen.
func (*Buffer) DrawFromHead ¶
func (B *Buffer) DrawFromHead()
DrawFromHead draw all text in viewarea and move screen-cursor to the position where it should be.
func (*Buffer) GetWidthBetween ¶
GetWidthBetween returns the width between start and end
func (*Buffer) GotoHead ¶
func (B *Buffer) GotoHead()
GotoHead move screen-cursor to the top of the viewarea. It should be called before text is changed.
func (*Buffer) InsertAndRepaint ¶
InsertAndRepaint inserts str and repaint the editline.
func (*Buffer) InsertString ¶
InsertString inserts string s at pos (Do not update screen) It returns the count of runes
func (*Buffer) RepaintAfterPrompt ¶
func (B *Buffer) RepaintAfterPrompt()
RepaintAfterPrompt repaints the all characters in the editline except for prompt.
func (*Buffer) RepaintAll ¶
func (B *Buffer) RepaintAll()
RepaintAll repaints the all characters in the editline including prompt.
func (*Buffer) ReplaceAndRepaint ¶
ReplaceAndRepaint replaces the string between `pos` and cursor's position to `str`
func (*Buffer) ResetViewStart ¶
func (B *Buffer) ResetViewStart()
ResetViewStart set ViewStart the new value which should be. It does not update screen.
type Cell ¶ added in v0.9.0
type Cell struct { Moji Moji // contains filtered or unexported fields }
type ColorSequence ¶ added in v0.10.0
type ColorSequence int64
const ( Black ColorSequence = 3 | ((30 + iota) << colorCodeBitSize) | (49 << (colorCodeBitSize * 2)) | (1 << (colorCodeBitSize * 3)) Red Green Yellow Blue Magenta Cyan White DefaultForeGroundColor )
const ( DarkGray ColorSequence = 3 | ((30 + iota) << colorCodeBitSize) | (22 << (colorCodeBitSize * 2)) | (49 << (colorCodeBitSize * 3)) DarkRed DarkGree DarkYellow DarkBlue DarkMagenta DarkCyan DarkWhite )
func SGR1 ¶ added in v0.6.3
func SGR1(n1 int) ColorSequence
func SGR2 ¶ added in v0.6.3
func SGR2(n1, n2 int) ColorSequence
func SGR3 ¶ added in v0.6.3
func SGR3(n1, n2, n3 int) ColorSequence
func SGR4 ¶ added in v0.6.3
func SGR4(n1, n2, n3, n4 int) ColorSequence
type Coloring ¶ added in v0.6.0
type Coloring interface { // Reset has to initialize receiver's fields and return default color. Init() ColorSequence // Next has to return color for the given rune. Next(rune) ColorSequence }
type Editor ¶
type Editor struct { KeyMap History IHistory Writer io.Writer Out *bufio.Writer Prompt func() (int, error) PromptWriter func(io.Writer) (int, error) Default string Cursor int LineFeed func(Result) Tty ITty Coloring Coloring HistoryCycling bool }
Editor is the main class to hold the parameter for ReadLine
func (*Editor) GetBindKey
deprecated
added in
v0.8.4
type GoCommand ¶ added in v0.11.1
GoCommand is the implement of Command which has a name and a function
func NewGoCommand ¶ added in v0.11.1
NewGoCommand creates an instance of GoCommand with a name and an function.
type IHistory ¶
IHistory is the interface ReadLine can use as container for history. It can be set to Editor.History field
type KeyGoFuncT
deprecated
type KeyGoFuncT = GoCommand
Deprecated: use GoCommand instead
type KeyMap ¶
KeyMap is the class for key-bindings
func (*KeyMap) BindKeyFunc
deprecated
func (*KeyMap) BindKeySymbol
deprecated
func (*KeyMap) GetBindKey
deprecated
type Moji ¶
func StringToMoji ¶ added in v0.9.0
type Result ¶
type Result int
Result is the type for readline's result.
const ( // CONTINUE is returned by key-functions to continue the line editor CONTINUE Result = iota // ENTER is returned by key-functions when Enter key is pressed ENTER Result = iota // ABORT is returned by key-functions when Ctrl-D is pressed with no command-line ABORT Result = iota // INTR is returned by key-functions when Ctrl-C is pressed INTR Result = iota )
type SelfInserter ¶ added in v0.11.2
type SelfInserter string
func (SelfInserter) Call ¶ added in v0.11.2
func (s SelfInserter) Call(ctx context.Context, this *Buffer) Result
func (SelfInserter) String ¶ added in v0.11.2
func (s SelfInserter) String() string