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
key | function |
---|---|
r | replace character under cursor |
i | enter insert mode |
I | enter insert mode at beginning of line |
a | enter insert mode one character to the right |
A | enter insert mode at end of line |
^ H | move cursor to the beginning of line |
$ L | move cursor to the end of line |
h | move cursor one character to the left |
l | move cursor one character to the right |
w | move cursor to the next word |
W | move cursor to the next Word |
e | move cursor to the end of next word |
E | move cursor to the end of next Word |
b | move cursor to the previous word |
x | delete the character under cursor |
X | delete the character before cursor |
d | delete the next word |
D | delete from cursor to end of line |
C | change text from cursor to end of line |
j | next matching history |
k | previous matching history |
p | paste from yank buffer |
~ | change character case |
default keys supported
key | function |
---|---|
Ctrl-A, Home | move cursor to the beginning of line |
Ctrl-E, End | move cursor to the end of line |
Ctrl-B, Left | move cursor one character to the left |
Ctrl-F, Right | move cursor one character to the right |
Ctrl-Left, Alt-B | move cursor to the previous word |
Ctrl-Right, Alt-F | move cursor to the next word |
Ctrl-D, Del | delete character under cursor if line is not empty |
Ctrl-D | end of file/exit if line is empty |
Ctrl-C | abort input |
Ctrl-L | clear screen |
Ctrl-T | transpose previous character with current character |
Ctrl-H, BackSpace | delete character before cursor |
Ctrl-W, Alt-BackSpace | delete word leading up to cursor |
Alt-D | delete word following cursor |
Ctrl-K | delete from cursor to end of line |
Ctrl-U | delete from start of line to cursor |
Ctrl-P, Up | previous match from history |
Ctrl-N, Down | next match from history |
Ctrl-R | reverse search history (Ctrl-S forward, Ctrl-G cancel) |
Ctrl-Y | paste from yank buffer (Alt-Y to paste next yank instead) |
Tab | next 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.
# 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.