-
Notifications
You must be signed in to change notification settings - Fork 721
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
Parse xterm-keys for motion directly #2609
Conversation
I am particularly interested in Alt+Arrows, because I am building something that matches my muscle memory from other editors. |
The "proper" way to handle these keys (according to
Compared to this patch, such an algorithm would work for all modifiable keys, not just the arrow keys, Home, and End. Also, it would work for any terminal in the terminfo database, not just ones that exactly copy xterm's encoding. On the other hand, such an algorithm would be a much more invasive change, and nobody's actually done the work to implement it, while this patch is already here and ready. |
if ( f == NULL ) | ||
{ | ||
ungetch(c3); ungetch(c2); ungetch(c1); break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if the functor (from above) has a valid target, instead of checking for the NULL
value (in C++, you should rather use std::nullptr
, but it won't matter with a functor).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've switched to nullptr
. I didn't embed this check into the switch, because we don't want the break
on the inner one, we want it on the outer one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullptr is a built in, so no need for std:: in front. but you are correct, we use nullptr in Kakoune codebase.
@lenormf I've updated based on your feedback. @Screwtapello Good to know. An efficient way to implement the dynamic switch would be a trie from key sequences to key encodings and have the reading code explore that trie and have a default case of letting the bytes through. This is essentially just a tokenization/scanner (lex) problem, so there's lots of efficient techniques to do it well if you know the mapping between strings and values you want. The problem is that doing it smart would be out-of-scope for Kakoune and you don't want to depend on other libraries. Just using std::map as a trie is likely to be much less efficient, but doable. |
Updated again re: @lenormf |
@mawww Anything else you'd like changed before merging? |
I added my copyright waiver. |
Ideally, something better should be done (re mawww#2554) but this is a decent intermediate step for some useful keys. Note: NCurses supports parsing these keys when shifted (KEY_SR, _SLEFT, S_RIGHT, etc), but it does not do the same thing for the other modifiers.
I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
Hi, I tried to test that PR locally, and I could not get it to work proprerly, what settings do you put xterm in ? I see that putting it in 8-bit mode generates those keys, except that the CSI sequence is sent as 8-bits as well, which is not parsed correctly. I have local changes to handle all that, but I was wondering what settings you were using. |
I don't use xterm. I am using iterm2/tmux and kitty on OS X. kitty has default settings. iterm2 has the "xterm defaults" and tmux has the xterm keys on. |
If I start a genuine xterm and run:
...and then press Ctrl+Up, I see the output:
...which would be parsed as |
It seems here ncurses parses some keys, such as , for which I get immediatly '553' out of wgetch. I assume this is an internal value ncurses uses, and it seems disabling the 'keypad' call fixes, however I then get |
The jeapostrophe's situation is that while their terminal sends those encodings, their terminfo database doesn't describe them, so ncurses doesn't recognise them and passes them straight through to the application uninterpreted. |
I merged this and used it as a base to refactor key parsing slightly, I am still unsure what direction we should take from here, at lease this adds more support for key combinations while preserving what we had, I am tempted to evolve that in the direction Screwtape described, but maybe we can hope for a common, forward compatible key encoding scheme that we can implement (maybe the one Leonerd suggested, or the kitty one...) |
Ideally, something better should be done (re #2554) but this is a decent
intermediate step for some useful keys.
Note: NCurses supports parsing these keys when shifted (KEY_SR,
_SLEFT, S_RIGHT, etc), but it does not do the same thing for the other
modifiers.