Documentation
¶
Overview ¶
Package readline is a pure-Go re-imagining of the UNIX readline API
Index ¶
- Constants
- Variables
- func GetSize(fd int) (width, height int, err error)
- func GetTermWidth() (termWidth int)
- func HkFnCancelAction(rl *Instance)
- func HkFnClearAfterCursor(rl *Instance)
- func HkFnClearLine(rl *Instance)
- func HkFnClearScreen(rl *Instance)
- func HkFnCursorJumpBackwards(rl *Instance)
- func HkFnCursorJumpForwards(rl *Instance)
- func HkFnCursorMoveToEndOfLine(rl *Instance)
- func HkFnCursorMoveToStartOfLine(rl *Instance)
- func HkFnModeAutocomplete(rl *Instance)
- func HkFnModeFuzzyFind(rl *Instance)
- func HkFnModePreviewLine(rl *Instance)
- func HkFnModePreviewToggle(rl *Instance)
- func HkFnModeSearchHistory(rl *Instance)
- func HkFnRecallWord1(rl *Instance)
- func HkFnRecallWord10(rl *Instance)
- func HkFnRecallWord11(rl *Instance)
- func HkFnRecallWord12(rl *Instance)
- func HkFnRecallWord2(rl *Instance)
- func HkFnRecallWord3(rl *Instance)
- func HkFnRecallWord4(rl *Instance)
- func HkFnRecallWord5(rl *Instance)
- func HkFnRecallWord6(rl *Instance)
- func HkFnRecallWord7(rl *Instance)
- func HkFnRecallWord8(rl *Instance)
- func HkFnRecallWord9(rl *Instance)
- func HkFnRecallWordLast(rl *Instance)
- func HkFnUndo(rl *Instance)
- func IsTerminal(fd int) bool
- func Restore(fd int, state *State) error
- type DelayedTabContext
- type EventReturn
- type EventState
- type ExampleHistory
- type HintCacheFuncT
- type History
- type Instance
- func (rl *Instance) AddEvent(keyPress string, callback keyPressEventCallbackT)
- func (rl *Instance) DelEvent(keyPress string)
- func (rl *Instance) ForceHintTextUpdate(s string)
- func (rl *Instance) Readline() (string, error)
- func (rl *Instance) ReadlineWithDefault(defaultValue string) (string, error)
- func (rl *Instance) SetPrompt(s string)
- type NullHistory
- type PreviewFuncCallbackT
- type PreviewFuncT
- type PreviewSizeT
- type State
- type TabCompleterReturnT
- type TabDisplayType
- type UnicodeT
- func (u *UnicodeT) CellLen() int
- func (u *UnicodeT) CellPos() int
- func (u *UnicodeT) Duplicate() *UnicodeT
- func (u *UnicodeT) RuneLen() int
- func (u *UnicodeT) RunePos() int
- func (u *UnicodeT) Runes() []rune
- func (u *UnicodeT) Set(rl *Instance, r []rune)
- func (u *UnicodeT) SetCellPos(cPos int)
- func (u *UnicodeT) SetRunePos(i int)
- func (u *UnicodeT) String() string
Constants ¶
const ( EventModeInputDefault = "Normal" EventModeInputVimKeys = "VimKeys" EventModeInputVimReplaceOnce = "VimReplaceOnce" EventModeInputVimReplaceMany = "VimReplaceMany" EventModeInputVimDelete = "VimDelete" EventModeInputVimCommand = "VimCommand" EventModeInputAutocomplete = "Autocomplete" EventModeInputFuzzyFind = "FuzzyFind" )
const ( EventModePreviewOff = "Disabled" EventModePreviewItem = "Autocomplete" EventModePreviewLine = "CmdLine" EventModePreviewUnknown = "Unknown" )
const ( // TabDisplayGrid is the default. It's where the screen below the prompt is // divided into a grid with each suggestion occupying an individual cell. TabDisplayGrid = iota // TabDisplayList is where suggestions are displayed as a list with a // description. The suggestion gets highlighted but both are searchable (ctrl+f) TabDisplayList // TabDisplayMap is where suggestions are displayed as a list with a // description however the description is what gets highlighted and only // that is searchable (ctrl+f). The benefit of TabDisplayMap is when your // autocomplete suggestions are IDs rather than human terms. TabDisplayMap )
Variables ¶
var ( // CtrlC is returned when ctrl+c is pressed ErrCtrlC = errors.New(_CtrlC) // EOF is returned when ctrl+d is pressed. // (this is actually the same value as io.EOF) ErrEOF = errors.New(_EOF) )
var ForceCrLf = true
Functions ¶
func GetTermWidth ¶
func GetTermWidth() (termWidth int)
GetTermWidth returns the width of Stdout or 80 if the width cannot be established
func HkFnCancelAction ¶
func HkFnCancelAction(rl *Instance)
func HkFnClearAfterCursor ¶
func HkFnClearAfterCursor(rl *Instance)
func HkFnClearLine ¶
func HkFnClearLine(rl *Instance)
func HkFnClearScreen ¶
func HkFnClearScreen(rl *Instance)
func HkFnCursorJumpBackwards ¶
func HkFnCursorJumpBackwards(rl *Instance)
func HkFnCursorJumpForwards ¶
func HkFnCursorJumpForwards(rl *Instance)
func HkFnCursorMoveToEndOfLine ¶
func HkFnCursorMoveToEndOfLine(rl *Instance)
func HkFnCursorMoveToStartOfLine ¶
func HkFnCursorMoveToStartOfLine(rl *Instance)
func HkFnModeAutocomplete ¶
func HkFnModeAutocomplete(rl *Instance)
func HkFnModeFuzzyFind ¶
func HkFnModeFuzzyFind(rl *Instance)
func HkFnModePreviewLine ¶
func HkFnModePreviewLine(rl *Instance)
func HkFnModePreviewToggle ¶
func HkFnModePreviewToggle(rl *Instance)
func HkFnModeSearchHistory ¶
func HkFnModeSearchHistory(rl *Instance)
func HkFnRecallWord1 ¶
func HkFnRecallWord1(rl *Instance)
func HkFnRecallWord10 ¶
func HkFnRecallWord10(rl *Instance)
func HkFnRecallWord11 ¶
func HkFnRecallWord11(rl *Instance)
func HkFnRecallWord12 ¶
func HkFnRecallWord12(rl *Instance)
func HkFnRecallWord2 ¶
func HkFnRecallWord2(rl *Instance)
func HkFnRecallWord3 ¶
func HkFnRecallWord3(rl *Instance)
func HkFnRecallWord4 ¶
func HkFnRecallWord4(rl *Instance)
func HkFnRecallWord5 ¶
func HkFnRecallWord5(rl *Instance)
func HkFnRecallWord6 ¶
func HkFnRecallWord6(rl *Instance)
func HkFnRecallWord7 ¶
func HkFnRecallWord7(rl *Instance)
func HkFnRecallWord8 ¶
func HkFnRecallWord8(rl *Instance)
func HkFnRecallWord9 ¶
func HkFnRecallWord9(rl *Instance)
func HkFnRecallWordLast ¶
func HkFnRecallWordLast(rl *Instance)
func IsTerminal ¶
IsTerminal returns true if the given file descriptor is a terminal.
Types ¶
type DelayedTabContext ¶
DelayedTabContext is a custom context interface for async updates to the tab completions
func (*DelayedTabContext) AppendDescriptions ¶
func (dtc *DelayedTabContext) AppendDescriptions(suggestions map[string]string)
AppendDescriptions updates the tab completions with additional suggestions + descriptions asynchronously
func (*DelayedTabContext) AppendSuggestions ¶
func (dtc *DelayedTabContext) AppendSuggestions(suggestions []string)
AppendSuggestions updates the tab completions with additional suggestions asynchronously
type EventReturn ¶
type EventReturn struct { Actions []func(rl *Instance) HintText []rune SetLine []rune SetPos int Continue bool MoreEvents bool }
EventReturn is a structure returned by the callback event function. This is used by readline to determine what state the API should return to after the readline event.
type EventState ¶
type EventState struct { Line string CursorPos int KeyPress string IsMasked bool InputMode string PreviewMode string }
EventState presents a simplified view of the current readline state
type ExampleHistory ¶
type ExampleHistory struct {
// contains filtered or unexported fields
}
ExampleHistory is an example of a LineHistory interface:
func (*ExampleHistory) Dump ¶
func (h *ExampleHistory) Dump() interface{}
Dump returns the entire history
func (*ExampleHistory) GetLine ¶
func (h *ExampleHistory) GetLine(i int) (string, error)
GetLine returns a line from history
func (*ExampleHistory) Len ¶
func (h *ExampleHistory) Len() int
Len returns the number of lines in history
type HintCacheFuncT ¶
type History ¶
type History interface { // Append takes the line and returns an updated number of lines or an error Write(string) (int, error) // GetLine takes the historic line number and returns the line or an error GetLine(int) (string, error) // Len returns the number of history lines Len() int // Dump returns everything in readline. The return is an interface{} because // not all LineHistory implementations will want to structure the history in // the same way. And since Dump() is not actually used by the readline API // internally, this methods return can be structured in whichever way is most // convenient for your own applications (or even just create an empty //function which returns `nil` if you don't require Dump() either) Dump() interface{} }
History is an interface to allow you to write your own history logging tools. eg sqlite backend instead of a file system. By default readline will just use the dummyLineHistory interface which only logs the history to memory ([]string to be precise).
type Instance ¶
type Instance struct { Active bool // PasswordMask is what character to hide password entry behind. // Once enabled, set to 0 (zero) to disable the mask again. PasswordMask rune // SyntaxHighlight is a helper function to provide syntax highlighting. // Once enabled, set to nil to disable again. SyntaxHighlighter func([]rune) string // History is an interface for querying the readline history. // This is exposed as an interface to allow you the flexibility to define how // you want your history managed (eg file on disk, database, cloud, or even // no history at all). By default it uses a dummy interface that only stores // historic items in memory. History History // HistoryAutoWrite defines whether items automatically get written to // history. // Enabled by default. Set to false to disable. HistoryAutoWrite bool // TabCompleter is a function that offers completion suggestions. TabCompleter func([]rune, int, DelayedTabContext) *TabCompleterReturnT MinTabItemLength int MaxTabItemLength int // MaxTabCompletionRows is the maximum number of rows to display in the tab // completion grid. MaxTabCompleterRows int // SyntaxCompletion is used to autocomplete code syntax (like braces and // quotation marks). If you want to complete words or phrases then you might // be better off using the TabCompletion function. // SyntaxCompletion takes the line ([]rune), change (string) and cursor // position, and returns the new line and cursor position. SyntaxCompleter func([]rune, string, int) ([]rune, int) // DelayedSyntaxWorker allows for syntax highlighting happen to the line // after the line has been drawn. DelayedSyntaxWorker func([]rune) []rune // HintText is a helper function which displays hint text the prompt. // HintText takes the line input from the prompt and the cursor position. // It returns the hint text to display. HintText func([]rune, int) []rune // HintColor any ANSI escape codes you wish to use for hint formatting. By // default this will just be blue. HintFormatting string // AutocompleteHistory is another customization allowing for alternative // results when [ctrl]+[r] AutocompleteHistory func(string) ([]string, map[string]string) // TempDirectory is the path to write temporary files when editing a line in // $EDITOR. This will default to os.TempDir() TempDirectory string // GetMultiLine is a callback to your host program. Since multiline support // is handled by the application rather than readline itself, this callback // is required when calling $EDITOR. However if this function is not set // then readline will just use the current line. GetMultiLine func([]rune) []rune MaxCacheSize int ScreenRefresh func() PreviewInit func() PreviewImages bool PreviewLine PreviewFuncT //ForceCrLf bool EnableGetCursorPos bool // contains filtered or unexported fields }
Instance is used to encapsulate the parameter group and run time of any given readline instance so that you can reuse the readline API for multiple entry captures without having to repeatedly unload configuration.
func NewInstance ¶
func NewInstance() *Instance
NewInstance is used to create a readline instance and initialise it with sane defaults.
func (*Instance) ForceHintTextUpdate ¶
ForceHintTextUpdate is a nasty function for force writing a new hint text. Use sparingly!
func (*Instance) Readline ¶
Readline displays the readline prompt. It will return a string (user entered data) or an error.
func (*Instance) ReadlineWithDefault ¶
Readline displays the readline prompt primed with a default value. It will return a string (user entered data) or an error. Discussion: https://github.com/lmorg/readline/issues/12
type NullHistory ¶
type NullHistory struct{}
NullHistory is a null History interface for when you don't want line entries remembered eg password input.
func (*NullHistory) GetLine ¶
func (h *NullHistory) GetLine(i int) (string, error)
GetLine returns a line from history
func (*NullHistory) Len ¶
func (h *NullHistory) Len() int
Len returns the number of lines in history
type PreviewFuncCallbackT ¶
type PreviewFuncT ¶
type PreviewFuncT func(ctx context.Context, line []rune, item string, incImages bool, size *PreviewSizeT, callback PreviewFuncCallbackT)
type PreviewSizeT ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
State contains the state of a terminal.
type TabCompleterReturnT ¶
type TabCompleterReturnT struct { Prefix string Suggestions []string Descriptions map[string]string DisplayType TabDisplayType HintCache HintCacheFuncT Preview PreviewFuncT }
type TabDisplayType ¶
type TabDisplayType int
TabDisplayType defines how the autocomplete suggestions display
type UnicodeT ¶
type UnicodeT struct {
// contains filtered or unexported fields
}
func (*UnicodeT) SetCellPos ¶
func (*UnicodeT) SetRunePos ¶
Source Files
¶
- cache.go
- codes.go
- cursor.go
- editor.go
- editor_unix.go
- errors.go
- events.go
- find.go
- godoc.go
- hint.go
- history.go
- hotkey_functions.go
- hotkey_recall.go
- instance.go
- preview.go
- raw_linux.go
- raw_unix.go
- read.go
- read_tty.go
- readline.go
- runecache.go
- signal_unix.go
- suggestions.go
- syntax.go
- tab.go
- tabfind.go
- tabgrid.go
- tabmap.go
- term.go
- timer.go
- tokenise.go
- undo.go
- unicode.go
- update.go
- vim.go
- vim_command.go
- vim_delete.go
- write.go
- write_tty.go