Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add readline keybindings to read function #236

Closed

Conversation

SquidDev
Copy link
Contributor

@SquidDev SquidDev commented May 12, 2017

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 large bios.lua. However it does make inputting long text (especially in the lua program) slightly easier. I guess you can make up your mind for yourself 馃槃.

Keybindings

This provides the most basic keybindings as given here.

  • C-a / C-e to jump to beginning/end of line
  • C-d to exit read without inputting anything. This could cause problems as read can now return nil. However, it does mean you can exit lua and shell without having to type an explicit "exit".
  • C-b / C-f to move left/right one character
  • M-b / M-f to move left/right one word.
  • C-p / C-n to move backwards/forwards in history or completions.
  • C-u / C-k to delete to the beginning/end of line.
  • C-w / M-d to delete to the beginning of the previous word/end of next word. (Note, the docs say it should be M-DEL rather than C-w. However, most of the things I've experimented with use the latter).

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:

  • Trigger key_up events when the terminal is closed.
  • Include modifier keys in the 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.

This includes:

 - C-a / C-e to jump to beginning/end of line
 - C-d to exit read without inputting anything. This could cause
   problems as read can now return nil. However, it does mean you can
   exit lua and shells without having to type an explicit "exit".
 - C-b / C-f to move left/right one character
 - M-b / M-f to move left/right one word.
 - C-p / C-n to move backwards/forwards in history or completions.
 - C-u / C-k to delete to the beginning/end of line.
 - C-w / M-d to delete to the beginning of the previous word/end of next
   word.
@SquidDev SquidDev changed the title Add readline keybindings to read functions Add readline keybindings to read function May 12, 2017
@dan200
Copy link
Owner

dan200 commented May 13, 2017

Not a fan of these, sorry. CraftOS is not unix!

@dan200 dan200 closed this May 13, 2017
@SquidDev
Copy link
Contributor Author

That's fine, I wasn't too sure about it myself 馃槃.. I don't there is an equivalent set of key bindings you'd consider using instead? For instance Ctrl+Left/Right to jump forwards/backwards words?

ccserver pushed a commit to ccserver/ComputerCraft that referenced this pull request Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants