-
Notifications
You must be signed in to change notification settings - Fork 62
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Emacs-like shortcuts from TextArea::input
#51
Comments
I certainly think that ctrlz,ctrlx,ctrlc,ctrlv should be standard. And ctrla. I added ctrlc and ctrlx in the select PR BTW - I am working on a table lookup key dispatch mechanism making it much easier for the caller to change the key mappings. At present I have basically had to copy and paste the entire input function into my gitui code just to tweak a few keys |
I think most CLI users would expect Emacs key bindings to work as a default (I actually use Ctrl+A/E/U/etc. everywhere in macOS as there's an OS level switch for turning on the shortcuts), and Ctrl+C to always mean SIGINT rather than copy. Strong preference for keeping that the default so that apps built with tui-textarea generally "just work", and instead making the non-emacs mode the opt-in / configurable approach. |
Ctrlc does not always equal sigint . Raw mode passes it through as a plain ol keystroke. Interestingly this is bound to the other new issue about clipboard etc |
Sure - but IMO your app should probably do something reasonable with that rather than treating it as copy at least in the default situation. |
It is up to the app author to decide what ctrlc should do. If they pass that keystroke to tta rather than acting on it themselves then doing a copy is reasonable. The app I am working on exits cleanly on ctrlc but if tta has focus then it will pass it to tta |
I see your point that its the app creator that decides, but I'd caution that there's a problem with that approach. It leads to building apps that all act slightly inconsistently with respect to how they handle keystrokes. For the most part I find it jarring when an application changes widely held conventions. Ctrl+C is basically never copy on macOS (that's Cmd+C). So my point isn't that the shortcuts shouldn't be customizable - it should be. My point is that out of the box the defaults should respect and be consistent with the operating system defaults. P.S. if you're interested, there's some discussion about how to design keybinding more generally at ratatui/ratatui#627. It would be worth feeding some ideas about how libs can take advantage of something like that. |
Sorry for the delay in response. I was working on refactorying and bug fix.
It would be useful as a separate crate. For me,
Ah, nice point. I've not thought about C-c sends signal. Is it common sense for general ratatui applications? General TUI app users' expectations would be:
I'd like to enable both Emacs shortcuts and copy/paste/undo/redo shortcuts in general textarea in browser. The problem is C-a. |
It might be a good idea to follow key bindings of micro text editor: Using
|
I'm not 100% sure what the general rule for this should be, but probably a TUI that's just a display type UI should stop running when Ctrl+C is pressed, editor type TUIs are probably a bit different. Ctrl+Z should put the app into the background rather than being undo (try it in vim).
This brings me back to the comment about respecting the conventions of the operating system / environment. For that reason, I'd suggest avoiding this option. |
My 10cents The key dispatch logic in I would
You need to make sure that if I have my own input interpreter it has the same features that the in box one has - ie no secret hooks into tta. You could argue that the input interpreter should be separate sample / crate. |
I tried
Yes, that's what I assume. Key shortcuts are very application specific.
I would suggest to create separate crate for this. use your_crate::InputState;
// Input state such as current pending key sequence and table of key shortcuts
let mut input_state = InputState::default();
// event loop
loop {
let input: Input = crossterm::event::read()?.into();
// Receive new single input and modify textarea state if necessary
input_state.apply(input, &mut textarea);
// ...
} |
The problem
Currently
TextArea::input
supports Emacs-like keyboard shortcuts. This was a good idea when tui-textarea had less features. However, now tui-textarea supports more features and adds more default key shortcuts and running out key combinations. And now it causes some conflicts.C-a
is used for moving to head of line in Emacs, but usually it is used for selecting all text in normal textareaC-v
is used for moving to the next page in Emacs, but usually it is used for pasting yanked textCurrent default key shortcuts can be found here: https://github.com/rhysd/tui-textarea#minimal-usage
Emacs solves the problem by key sequence (like
C-x b
) but tui-textarea doesn't have the functionality (and should not have for avoiding complexity).tui-textarea aims to be something like
<textarea>
element in HTML as described in the first sentence of README.md. So the default shortcuts should be intuitive and kept simple.The solution
Remove Emacs-like shortcuts from
TextArea::input
and addTextArea::input_with_emacs_shortcuts
instead.Supported key shortcuts are as follows.
TextArea::input
Ctrl+H
,Backspace
Delete
Enter
Alt+Backspace
Alt+Delete
Ctrl+Z
Alt+Z
Ctrl+C
Ctrl+X
Ctrl+V
Ctrl+A
Ctrl+F
,→
Ctrl+B
,←
Ctrl+P
,↑
Ctrl+N
,↓
Ctrl+→
Ctrl+←
Ctrl+↑
Ctrl+↓
End
,Ctrl+Alt+→
Home
,Ctrl+Alt+←
Ctrl+Alt+↑
Ctrl+Alt+↓
PageDown
PageUp
Note:
Alt+Z
is unusual, butCtrl+Shift+Z
cannot be detected due to limitation of the terminal escape sequence.Note:
Ctrl+N
,Ctrl+P
,Ctrl+F
,Ctrl+B
,Ctrl+H
remain because they are supported on macOS by default key shortcuts.TextArea::input_with_emacs_shortcuts
Ctrl+H
,Backspace
Ctrl+D
,Delete
Ctrl+M
,Enter
Ctrl+K
Ctrl+J
Ctrl+W
,Alt+H
Alt+D
Ctrl+U
Ctrl+R
Ctrl+Y
Ctrl+Space
Ctrl+W
Alt+W
Ctrl+G
Ctrl+F
,→
Ctrl+B
,←
Ctrl+P
,↑
Ctrl+N
,↓
Alt+F
Atl+B
Alt+]
,Alt+P
Alt+[
,Alt+N
Ctrl+E
,End
,Ctrl+Alt+F
Ctrl+A
,Home
,Ctrl+Alt+B
Alt+<
,Ctrl+Alt+P
,Alt+>
,Ctrl+Alt+N
,Ctrl+V
,PageDown
Alt+V
,PageUp
The text was updated successfully, but these errors were encountered: