-
Notifications
You must be signed in to change notification settings - Fork 722
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
Switch away from ncurses to terminfo-based input handling #2554
Comments
I agree. Just to clarify, do you suggest we should also drop ncurses for rendering or should this be tackled in a separate task? |
If possible, I suggest to tackle that separately, primarily to simplify the transition. |
Abandoning ncurses' input-handling and using raw terminfo would make it easier to handle keys like
|
Well somehow nvim is able to distinguish certain mappings that kakoune cannot (such as I admit my collection of issues might not be perfect, I mostly wanted to showcase a scale of how often this topic is brought up. |
Normally Kitty's "full keyboard mode" does not appear in its terminfo database, so terminfo support won't help with that. Just to be clear, I'm not arguing that we shouldn't replace ncurses input handling with raw terminfo handling. I'm sure it would make the code cleaner, and a bit more flexible since some extended terminfo keys (like |
Thanks for explaining, interesting. In summary, if I understood everything correctly, by switching to raw handling we will be limited not by a library of choice, but by terminals themselves: for old terminals there will be little advantage, but for modern terminals we will be able to distinguish more, or even all keyboard shortcuts. As a user of a modern terminal I consider this a big advantage 😄 I'll open an issue in kitty so by the time this ticket is addressed, kitty's terminfo database will be ready for full keyboard mode 😉 |
Thanks for reaching out to kitty @maximbaz Plainly supporting modern terminals will also mean having nice support for UI features like curly underlines. With the goal of fully removing ncurses in the long run (kakoune will be dependency-free), I think it would make sense to approach the development by copying |
Just want to mention, this is another perfect example why removing dependency is beneficial: I reported an issue to kitty and 2 hours later it was fixed, new terminfo file is already available for download. Imagine how many years it would take for ncurses to update kitty's terminfo before ncurses will be able to detect that kitty supports this new term capability (I assume this is how it works, this is why ncurses bundles various terminfo files in its distribution). |
I think I would prefer to avoid duplicating all that code. If we want to experiment while keeping a fallback (not really the traditional Kakoune way, which has often been to just break it), adding a Once we get rid of ncurses, we just have to remove our dependency on the standard C++ library and we are done ! (kidding, or am I ?) |
And then rewrite everything in Rust. |
Since there's no real point to keep |
Let's try to recap the current state of the art to see if we're on the same page. As far as I understand, both http://www.leonerd.org.uk/code/libtermkey/
The idea behind these libs is explained in http://www.leonerd.org.uk/hacks/fixterms/ But then, 1 year ago, the authors of From what I understand, the Don't hesitate to correct me or add other pieces of info, so we can get a broader image of the current solutions. |
One small question: if Kakoune will ever have official GUI (what? I think that the project can benefit a lot if it will have both TUI and GUI, like Emacs. It also adds lots of features beyond fancy window), would it be as restricted in terms of keyboard support as it's terminal version? E.g. in Emacs some keys are bound to corresponding terminal ones by default, like Ctrl+m is mapped to Return, despite the fact that GUI Emacs can distinguish it from return key, but that brings consistent behaviour between GUI and TUI. |
Since there is no official GUI yet, nobody can definitively say what it would or would not be able to do. However, I've worked on an unofficial GUI, and (among other things) it can definitely distinguish |
We can do the work progressively on master, fix whats detected as broken, and once ncurses_ui does not use ncurses anymore, rename it.
Its unlikely that Kakoune will come bundled with an official GUI, as this would mean blessing some kind of UI toolkit and dependency. UIs can be implemented through the json-rpc ui protocol, and I designed the UI system with non-terminal UIs in mind (although its not very well tested, so as @Screwtapello said, their might be some arbitrary restrictions we need to lift). Except for a few hacks, Kakoune should not have any terminal specific knowledge outside of ncurses_ui.cc. |
I support this approach as well. |
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.
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.
A spreadsheet compiling support for escape sequences in modern terminal: |
If you're going to make a list of terminals and their escape sequences, maybe make it a wiki page? Apart from the terminals mentioned, It's also worth pointing out that the terminfo database that ships with ncurses is a wealth of information - both for the actual tested descriptions of what sequences are used by which terminals, but also the long and in-depth comments about individual terminals and terminal emulation in general - nearly 50% of the file is comments. |
I'm not the original author of this document, this spreadsheet was recently shared on lobste.rs by JustinMK, the Neovim leadev. |
Some abstraction refactoring has started in afd45c6 |
The builtin-terminal-input branch is implementing this, I am keen to merge it but would like a bit of testing on setup different from mine (different terminal emulators mostly). |
seems to work in GNOME Terminal |
That has been done for a while. |
This was brought up many times, and is indirectly implied by a few existing issues asking to distinguish certain keyboard mappings regardless of the taken approach. Contrary to all those issues, this ticket is proposing a specific approach: switching away from ncurses to terminfo-based input handling.
Input handling is a key aspect of code editor, I strongly believe this should be done directly using terminfo and not via some third-party wrapper libraries such as ncurses or libtickit. The current limitations of ncurses are simply embarrassing. Terminals evolve, if a new solution / xterm protocol extension gets adopted, we must be able to enable it quickly, not wait for months or years until it's adopted by a library of choice.
If this is implemented, this fixes issues like #2553, #2209, #1527, #1270, #997, #970 and #1012.
The text was updated successfully, but these errors were encountered: