-
Notifications
You must be signed in to change notification settings - Fork 20
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
Key bindings don't work inside neovim session #71
Comments
Can you post some full daemon logs as well as client logs with the verbosity cranked up? From that log snippet we can tell that the keybinding engine is correctly recognizing the keybinding, but it's not enough to figure out why the detach action isn't working as expected. To do that, you can run |
I'm sorry if I wasn't clear: the log messages that I've posted only appear when I press the keybinding outside of a neovim session. If I press the keybinding inside neovim, then nothing appears in the log. |
Oh yeah I see that now, sorry didn't read your post closely enough. I would still like to get the full logs I requested. There isn't much I can do to diagnose the issue without them since disconnect works fine for me when I'm in a neovim session. |
I've attached the requested log files. For this session, I was using the following config file: prompt_prefix = "[$SHPOOL_SESSION_NAME]"
session_restore_mode = { lines = 30000 }
[[keybinding]]
binding = "Ctrl-b d"
action = "detach" Accordingly, I've reproduced the bug by starting neovim, then pressing Thanks! |
I don't see Unfortunately, the only thing I can think of that could change control codes is different terminal emulators, and it looks like you are using alacritty the same way that I am
The biggest difference I see in our setups is that you are using fish while I'm using bash, though when I manually launch fish and enter neovim inside it the detach keybinding still works. |
I believe the line in the daemon log that corresponds to me pressing Ctrl-B is this one:
That's what I see when I use
So it appears that The client-side log seems to have a similar log entry. When I use
When I use
That said, I have no idea why all these ANSI codes are being sent...
I am indeed using As you've noticed, my shell environment has |
Oh yeah you're right about that I don't set |
I can reproduce this with Neovim (0.10) and Kitty, iTerm2, WezTerm but not in Terminal.app. My guess is that it is related to CSI u |
That's interesting. I don't have a mac to test with right now, but I should be able to get to one tomorrow and I'll see if I can reproduce with that setup then (though I guess I can probably try Kitty and WezTerm on my linux box). @someplaceguy what OS are you using? I'd been assuming you were on linux, but now I'm wondering if alacritty could generate different control codes on different OSes for compatibility reasons or something like that. |
@ethanpailes I'm using NixOS Linux 24.05. |
I can reproduce with Alacritty as well (version 0.14-dev). Alacritty implemented the kitty keyboard protocol in December 2023 so I tried an older version (0.12) and in which I cannot reproduce the issue. EDIT: so my guess now is that it is related to the kitty keyboard protocol :-) |
I'm still on alacritty 0.12, so that makes sense. |
Reading through https://sw.kovidgoyal.net/kitty/keyboard-protocol/#quickstart I've started to develop a working theory about what is going on here. I suspect that neovim supports the kitty keybinding protocol, which means that when it puts the terminal in alternate screen mode, it sends a control code asking to switch to the kitty protocol ( The fix for this from shpool's perspective is that we need to introduce some sort of notion of keybinding mode. To start off with, this will look like
where Each mode will have its own binding engine, and we will switch between the active engine when we observe the shell program we have launched emitting a protocol switch code. Exactly how we will do this is not yet clear to me, since I'm not sure how kitty protocol enabled programs like neovim determine if their mode switch control sequence actually worked. If they all do add-hoc tests, rather than there being some sort of well-defined handshake, this could get pretty hairy. Another complication is that the keybinding engine currently just scanns over the input stream, and mode switch bindings seem like they go in the other opposite direction, so we may need to attach a scanning trie to the output stream as well and coordinate between it and the keybinding engine. Otherwise if this was all just in the input stream, we could just introduce a new |
It looks like the terminal switching codes are a little more complex than the quickstart guide explains: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement. The codes the quickstart guide mentions mean "push the disambiguated escape code mode to the stack" and "pop off the stack". It seems we will need to scan for and interpret these flags control codes, as well as implement a stack structure of our own to mirror the one in kitty enabled terminals, and since the kitty protocol calls for seperate stacks for the main and alternate screen we will need to track transitions between those as well. One thing that's not clear to me is how the |
I'm also realizing that we'll probably need some new scanning infrastructure, since simple tries don't handle parsing CSI sequences very well. The main problem is that CSI control sequences contain numbers that need to extracted and processed. The right tool for the job here is really an online regular expression engine with capture group support, but we can get away with just extending our trie based matcher with support for character classes, capture groups, and eager kleene star, which should allow us to continue to use a DFA without resorting to the subset construction and blowing up our ability to track capture groups. This is starting to feel like something where I should look for a library. |
Looks like we might be able to use Edit: looking at the API and README of regex-cursor a bit, it seems like it is not currently designed for handling streaming chunks of data due to lookaround concerns. It is really only able to work on discontinuous in-memory data structures. |
Thinking about it some more, an NFA simulation is going to be a lot slower than the DFA we can have if we do something tailored to our particular usecase, and having to deal with all the lookaround and unicode baggage of the rust regex ecosystem will probably wind up being more troulbe than it is worth. If there was something we could use out of the box, that would be one thing, but it seems like I would probably have to send patches to |
Actually, we can probably just create a |
Without looking deeply into it, IMHO having the matcher depend on terminal state machine sounds like the proper way to do this. Otherwise we might run into similar problems down the road with some other arcane terminal states... I need to take this into account for #46. I wonder if it's possible to generalize the Parser concept to other terminal crates. |
Yeah, handling this in the in-memory terminal would be one advantage of doing something homebrew |
What happened
When I run neovim inside a shpool session, the shpool key bindings don't work.
I've tried the default key binding for detaching, as well as changing the default to
Ctrl-a d
andCtrl-b d
, but no matter which key binding I use, neovim still interprets the key binding rather than shpool.The key bindings work fine once I exit neovim.
What I expected to happen
I expected the session to detach when I press shpool's detach key binding.
To Reproduce
shpool attach -f test
neovim
inside the shpool test sessionVersion info
shpool 0.6.2
Logs
Nothing appears in the log when I press the key binding inside neovim. If I exit neovim and press the key binding, then I do see:
The text was updated successfully, but these errors were encountered: