Documentation ¶
Index ¶
- Constants
- Variables
- func Ansi(c int) []byte
- func Colored(c int, b []byte) []byte
- func Deansi(b []byte) []byte
- func MoveCursor(pos int, d int) []byte
- func Read(tty reader) chan Key
- func SetCursor(pos int) []byte
- type Code
- type Ed
- func (e *Ed) Append(b []byte)
- func (e *Ed) Back()
- func (e *Ed) BackWord()
- func (e *Ed) Complete(strs [][]byte, dir int)
- func (e *Ed) CompleteNext(strs [][]byte)
- func (e *Ed) CompletePrev(strs [][]byte)
- func (e *Ed) Del(i ...int)
- func (e *Ed) Delete()
- func (e *Ed) DeleteFromCursor()
- func (e *Ed) Discard()
- func (e *Ed) End()
- func (e *Ed) Handle(key int, handler func(*Ed, Key))
- func (e *Ed) History(strs [][]byte, dir int)
- func (e *Ed) HistoryNext(strs [][]byte)
- func (e *Ed) HistoryPrev(strs [][]byte)
- func (e *Ed) Insert(b []byte)
- func (e *Ed) Left()
- func (e *Ed) MoveCursor(i int, dir int)
- func (e *Ed) Newline()
- func (e *Ed) Pause()
- func (e *Ed) Refresh()
- func (e *Ed) Reject(chars []byte)
- func (e *Ed) Reset()
- func (e *Ed) Resume()
- func (e *Ed) Return()
- func (e *Ed) Right()
- func (e *Ed) Run()
- func (e *Ed) Set(b []byte)
- func (e *Ed) SetCursor(pos ...int)
- func (e *Ed) Stop()
- func (e *Ed) Str() string
- func (e *Ed) Suggest(str []byte)
- func (e *Ed) Transpose()
- func (e *Ed) Write(b []byte)
- type Iterm
- type Key
- type List
- type Term
- func (t *Term) Clear()
- func (t *Term) ClearLine()
- func (t *Term) Del(i ...int)
- func (t *Term) HideCursor()
- func (t *Term) MoveCursor(i int, dir int)
- func (t *Term) Newline()
- func (t *Term) Pause()
- func (t *Term) Read() chan Key
- func (t *Term) Resume()
- func (t *Term) Return()
- func (t *Term) SetCursor(pos int)
- func (t *Term) ShowCursor()
- func (t *Term) Stop()
- func (t *Term) Write(b []byte)
Constants ¶
const ( Clear int = iota ClearLine Cursor ShowCursor HideCursor Del Cr Newline Red Green Reset )
Known ansi codes
const ( Rgt int = iota Lft )
Directions
const ( Chars int = iota CtrlA CtrlB CtrlC CtrlD CtrlE CtrlF CtrlH Tab CtrlK CtrlL Enter CtrlN CtrlP CtrlT CtrlU CtrlW Esc Backspace Delete ShiftTab Up Down Right Left )
Known keys
const ( Forw int = iota Back Hist Comp Sugg )
Forw/Back - directions Hist/Comp/Sugg - modes for cycling through sets
Variables ¶
var Keys = map[int]Key{ CtrlA: {CtrlA, []byte{0x1}, "Ctrl-A"}, CtrlB: {CtrlB, []byte{0x2}, "Ctrl-B"}, CtrlC: {CtrlC, []byte{0x3}, "Ctrl-C"}, CtrlD: {CtrlD, []byte{0x4}, "Ctrl-D"}, CtrlE: {CtrlE, []byte{0x5}, "Ctrl-E"}, CtrlF: {CtrlF, []byte{0x6}, "Ctrl-F"}, CtrlH: {CtrlH, []byte{0x8}, "Ctrl-H"}, Tab: {Tab, []byte{0x9}, "Tab"}, CtrlK: {CtrlK, []byte{0x0b}, "Ctrl-K"}, CtrlL: {CtrlL, []byte{0x0c}, "Ctrl-L"}, Enter: {Enter, []byte{0x0d}, "Enter"}, CtrlN: {CtrlN, []byte{0x0e}, "Ctrl-N"}, CtrlP: {CtrlP, []byte{0x10}, "Ctrl-P"}, CtrlT: {CtrlT, []byte{0x14}, "Ctrl-T"}, CtrlU: {CtrlU, []byte{0x15}, "Ctrl-U"}, CtrlW: {CtrlW, []byte{0x17}, "Ctrl-W"}, Esc: {Esc, []byte{0x1b}, "Esc"}, Backspace: {Backspace, []byte{0x7f}, "Backspace"}, Delete: {Delete, []byte{0x1b, 0x5b, 0x33, 0x7E}, "Delete"}, ShiftTab: {ShiftTab, []byte{0x1b, 0x5b, 0x5a}, "Shift-Tab"}, Up: {Up, []byte{0x1b, 0x5b, 0x41}, "Up"}, Down: {Down, []byte{0x1b, 0x5b, 0x42}, "Down"}, Right: {Right, []byte{0x1b, 0x5b, 0x43}, "Right"}, Left: {Left, []byte{0x1b, 0x5b, 0x44}, "Left"}, }
Keys defines known keys
Functions ¶
func Deansi ¶
Deansi replaces ansi codes in the given byte array with hints. This is useful for testing.
func MoveCursor ¶
MoveCursor returns ansi codes for moving the cursor by the given number of chars in the given direction.
Types ¶
type Ed ¶
type Ed struct { Prompt []byte Pos int Chars []byte Suggested []byte // contains filtered or unexported fields }
Ed represents the line editor
func NewEd ¶
NewEd creates a line editor (Ed) without any handlers attached. See NewReadline for a line editor that resembles (most of) Linenoise's functionality.
func NewReadline ¶
NewReadline creates a line editor that resembles most of Linenoise's functionality
func (*Ed) BackWord ¶
func (e *Ed) BackWord()
BackWord removes one word before the current cursor position.
func (*Ed) Complete ¶
Complete displays the previous or next completion from the given slice depending on the given direction.
func (*Ed) CompleteNext ¶
CompleteNext displays the next completion from the given slice.
func (*Ed) CompletePrev ¶
CompletePrev displays the previous completion from the given slice.
func (*Ed) Delete ¶
func (e *Ed) Delete()
Delete removes one char after the current cursor position.
func (*Ed) DeleteFromCursor ¶
func (e *Ed) DeleteFromCursor()
DeleteFromCursor deletes all chars from the current cursor position to the end of the line.
func (*Ed) Discard ¶
func (e *Ed) Discard()
Discard discards the given input by moving to the next line and starting over with an empty prompt. This resembles the behaviour Ctrl-C in Bash or Zshele.
func (*Ed) History ¶
History displays the previous or next line from the given slice depending on the given direction.
func (*Ed) HistoryNext ¶
HistoryNext displays the next line from the given slice.
func (*Ed) HistoryPrev ¶
HistoryPrev displays the previous line from the given slice.
func (*Ed) MoveCursor ¶
MoveCursor moves the cursor by the given number of chars in the given direction.
func (*Ed) Pause ¶
func (e *Ed) Pause()
Pause pauses the editor, should be used before outputting text to the terminal, e.g. in an Enter handler.
func (*Ed) Reject ¶
Reject rejects the given chars by printing them at the current cursor position in red, and removing them after 100 milliseconds.
func (*Ed) Resume ¶
func (e *Ed) Resume()
Resume resumes the editor, and places the terminal in raw mode.
func (*Ed) SetCursor ¶
SetCursor sets the cursor to the given position, defaults to the current position.
func (*Ed) Suggest ¶
Suggest appends the first matching suggestion from the given slice in green after the current cursor position.
func (*Ed) Transpose ¶
func (e *Ed) Transpose()
Transpose transposes the char before the cursor position with the one on the cursor position, and moves the cursor one char to the right, if possible. If the cursor is at the beginning of the line it transposes the current char with the next one, and moves the cursor two chars to the right. This resembles Zshell's behaviour.
type Iterm ¶
type Iterm interface { Start() Read(b []byte) (int, error) Write(b []byte) (int, error) Restore() error RawMode() error Close() error }
Iterm represents a subset of the tty implemented in github.com/pkg/term.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List represents a list of strings that are used for completion, history, and suggestions.
type Term ¶
type Term struct {
// contains filtered or unexported fields
}
Term represents a terminal
func (*Term) Clear ¶
func (t *Term) Clear()
Clear clears from the current cursor position to the end of the line.
func (*Term) Del ¶
Del writes the given number of delete chars (`\x7F`) to the terminal (defaults to 1), deleting the char after the cursor position.
func (*Term) MoveCursor ¶
MoveCursor moves the cursor by the given number of chars in the given direction.
func (*Term) Pause ¶
func (t *Term) Pause()
Pause pauses the terminal, restoring the previous mode and settings.
func (*Term) Resume ¶
func (t *Term) Resume()
Resume resumes the terminal, setting the terminal in raw mode.