Categorygithub.com/ndsizeif/liner
modulepackage
0.0.0-20240707202954-01801cdb1cfb
Repository: https://github.com/ndsizeif/liner.git
Documentation: pkg.go.dev

# README

Liner

This fork adds minimal support for vi editing to Liner. Projects that make use of Liner have users that may be looking for vi editing functionality. The modifications in this repository offer basic vi editing behavior.

code statistics
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Go                     17         3211         2666          272          273
 Markdown                1           87            0           75           12
===============================================================================
 Total                  18         3298         2666          347          285
===============================================================================

We implement basic, single-action, vi editing functions. At present, we do not support number keys to execute multiple operations, a repeat key, or undo actions.

Users may expect a method to visually discern between vi normal and insert modes. Though we do not support changing cursor behavior, however, we can send terminal escape codes change the appearance of text in the terminal.

Vi Keys Supported

keyfunction
rreplace character under cursor
ienter insert mode
Ienter insert mode at beginning of line
aenter insert mode one character to the right
Aenter insert mode at end of line
^ Hmove cursor to the beginning of line
$ Lmove cursor to the end of line
hmove cursor one character to the left
lmove cursor one character to the right
wmove cursor to the next word
Wmove cursor to the next Word
emove cursor to the end of next word
Emove cursor to the end of next Word
bmove cursor to the previous word
xdelete the character under cursor
Xdelete the character before cursor
ddelete the next word
Ddelete from cursor to end of line
Cchange text from cursor to end of line
jnext matching history
kprevious matching history
ppaste from yank buffer
~change character case
default keys supported
keyfunction
Ctrl-A, Homemove cursor to the beginning of line
Ctrl-E, Endmove cursor to the end of line
Ctrl-B, Leftmove cursor one character to the left
Ctrl-F, Rightmove cursor one character to the right
Ctrl-Left, Alt-Bmove cursor to the previous word
Ctrl-Right, Alt-Fmove cursor to the next word
Ctrl-D, Deldelete character under cursor if line is not empty
Ctrl-Dend of file/exit if line is empty
Ctrl-Cabort input
Ctrl-Lclear screen
Ctrl-Ttranspose previous character with current character
Ctrl-H, BackSpacedelete character before cursor
Ctrl-W, Alt-BackSpacedelete word leading up to cursor
Alt-Ddelete word following cursor
Ctrl-Kdelete from cursor to end of line
Ctrl-Udelete from start of line to cursor
Ctrl-P, Upprevious match from history
Ctrl-N, Downnext match from history
Ctrl-Rreverse search history (Ctrl-S forward, Ctrl-G cancel)
Ctrl-Ypaste from yank buffer (Alt-Y to paste next yank instead)
Tabnext completion
Shift-Tab(after Tab) previous completion

Vi Functions

EnableViMode(bool)      // enable or disable vi editing functionality
EnableViPrompt(bool)    // allow liner prompt to change based on current vi mode
SetViMode(vimode)       // explicitly se the vi mode (normal, insert, replace)
SetViNormalStyle(style) // style used when in vi normal mode
SetViInsertStyle(style) // style used when in vi insert mode

# Functions

NewLiner initializes a new *State, and sets the terminal into raw mode.
TerminalMode returns the current terminal input mode as an InputModeSetter.
TerminalSupported returns true if the current terminal supports line editing features, and false if liner will use the 'dumb' fallback for input.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
HistoryLimit is the maximum number of entries saved in the scrollback history.
No description provided by the author
No description provided by the author
KillRingMax is the max number of elements to save on the killring.
No description provided by the author
No description provided by the author
Two tab styles are currently available: TabCircular cycles through each completion item and displays it directly on the prompt TabPrints prints the list of completion items to the screen after a second tab key is pressed.
Two tab styles are currently available: TabCircular cycles through each completion item and displays it directly on the prompt TabPrints prints the list of completion items to the screen after a second tab key is pressed.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrInternal is returned when liner experiences an error that it cannot handle.
ErrInvalidPrompt is returned from Prompt or PasswordPrompt if the prompt contains any unprintable runes (including substrings that could be colour codes on some platforms).
ErrNotTerminalOutput is returned from Prompt or PasswordPrompt if the platform is normally supported, but stdout has been redirected.
ErrPromptAborted is returned from Prompt or PasswordPrompt when the user presses Ctrl-C if SetCtrlCAborts(true) has been called on the State.

# Structs

State represents an open terminal.

# Interfaces

ModeApplier is the interface that wraps a representation of the terminal mode.

# Type aliases

Completer takes the currently edited line content at the left of the cursor and returns a list of completion candidates.
ShouldRestart is passed the error generated by readNext and returns true if the the read should be restarted or false if the error should be returned.
TabStyle is used to select how tab completions are displayed.
WordCompleter takes the currently edited line with the cursor position and returns the completion candidates for the partial word to be completed.