joouha / euporie

Jupyter notebooks in the terminal
https://euporie.readthedocs.io
MIT License
1.54k stars 36 forks source link

Feature Request: Change terminal cursor shape depending on mode #34

Closed zharmany closed 1 year ago

zharmany commented 1 year ago

Howdy!

I'm really loving the direction euporie is headed. One small request would be to allow customization of the cursor depending on the editing mode. Many people who use modal text editors (e.g., Vim, but not trying to flame any wars) configure their editors to change the cursor shape depending on the mode. For instance, I use a block cursor for command mode and a vertical bar for insert mode (as well as an underline for replace mode, but the former is way more important).

This could be done easily by allowing the user to set a string that may contain escape sequences that is emitted during mode changes, akin to Readline's vi-ins-mode-string and vi-cmd-mode-string. This would also enable further creative uses.

If you'd be willing to provide some pointers to spots in the codebase, I'd be happy to attempt an implementation.

Thanks again for your awesome work!

joouha commented 1 year ago

Hello,

I'm glad you like euporie!

I've actually already implemented this in the dev branch (here), it just hasn't made it into a release yet.

I'll create a new release with this in soon.

zharmany commented 1 year ago

Awesome! I feel silly not checking out activity on dev first, so thanks for the reply.

I had also just discovered the E for $EDITOR shortcut, which is also quite fantastic and makes the above less crucial. Although this does make me want to ask, are there are any plans to be able to embed Neovim inside cells? It's totally insane, but would certainly eliminate some friction there.

Feel free to close this issue, unless you'd like to close it when the feature is released. Until then, I'm absolutely going to try out the dev branch.

joouha commented 1 year ago

I've released v2.0.8, which has the cursor-shape changes in.

I think it might be possible to achieve an "embedded neovim" type effect by running euporie inside tmux, and setting the external editor command to open your editor in a pop-up tmux pane. It would look a bit like this:

_editor-embed.webm

I'd need to make some changes in euporie to allow a custom editor command to be configured, and to inject the position parameters into the command, but I think it might work.

zharmany commented 1 year ago

Awesome work. I've been using the dev branch and really like the cursor behavior. Well done!

joouha commented 1 year ago

Hello again,

With v2.1.0 it's now possible to simulate embedding an external editor inside cells.

You need to run euporie inside a tmux session, and set the new external_editor configuration option to launch your editor in a tmux popup as follows:

euporie-notebook --external-editor="tmux display-popup -x {left} -y {bottom} -w {width} -h {height} -B -E neovim" my-notebook.ipynb

The positional arguments in the external-editor command get replaced with the cell's position by euporie, resulting in the popup appearing directly over the cell being edited.