Add readline keybindings to read function #236
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a selection of keybindings to the
read
function which mirror those provided by readline (shell command prompts, several REPLs, etc...). I'm not entirely sure whether this should actually be included - it does bloat the already largebios.lua
. However it does make inputting long text (especially in thelua
program) slightly easier. I guess you can make up your mind for yourself 馃槃.Keybindings
This provides the most basic keybindings as given here.
read
can now returnnil
. However, it does mean you can exitlua
andshell
without having to type an explicit "exit".This doesn't define any of the more complex command like undo, transpose, yanking, etc... I'm happy to add them if people really want them, but it feels rather overkill.
Implementation
I'm currently listening to
key_down
/key_up
events to track the status of control/alt keys. This is fine most of the time, though could cause problems with multiple users or people exiting the GUI with keys down. A couple of changes which could be made elsewhere to fix this:key_up
events when the terminal is closed.key
event. I'm not a fan of this as it seems too "friendly" for the user, but it is the most fool-proof way.Possible extensions
It might be nice to add similar shortcuts to
edit
. A similar system could also be added to the pager described in #212. I'd be happy to add them if people want.