Repository navigation
change cursor shape depending on edit mode - #494
Conversation
|
I love it! |
|
@CozyPenguin I gave this a test drive on different terminal emulators across Windows and Linux and I didn't encounter unforeseen problems. I know this overrides the previously set cursor. I think there might be a way to read out the set cursor from a ANSI device (https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Device-Control-functions) but I am not sure if that is worth it for a minimal viable product if not every terminal emulator implements that protocol. I would be open to land it in this stage and accept further improvements down the line. |
|
I am fine with it being merged in its current form. There is crossterm-rs/crossterm#646 where someone has a fork in which retrieving the cursor shape is implement, but I don't know what the status of that one is and if it will be merged due to concerns with windows compatibility. I will try to come back to this and implement the additional functionality when I have a bit more time left over. |
|
I wondered why my cursor recently changed to a block. I change it in Windows Terminal to be a bar. Hit enter and it's a block again. LOL. It would be nice if this were configurable somewhere. |
|
I'm going to add an option to configure this, I just don't have that much time right now. |
|
It seems like this change also overrides ansi escape sequences to change the cursor, which is unfortunate. |
Modal editors such as vim/neovim/etc. often use different cursors for different edit modes.
In it's current state, this pr changes the cursor to a line if the user is in insert mode, and uses a block cursor for all other modes (including custom and emacs).
Unfortunately, there is no way to retrieve the current cursor shape in crossterm that I know of, so restoring the previous cursor when exiting reedline could prove to be quite difficult. I currently can think of two solutions for this:
Regarding configurability, I think it should be possible to configure the cursor depending on the mode, this would be quite useful for nushell as it would allow customizing the behaviour in the config record. Depending on how the implementation ends up looking, it might also be a good idea to hide this behind a
with_custom_cursors()function.Once I've resolved all those problems, I might also look into enabling/disabling cursor blinking. Uni is starting next week so it could take a while until this is in a polished state, but I will try to come back to this regularly.