IlanCosman/tide

[Workaround] Make cursor shape changable in vi mode

ruslanSorokin opened this issue · 2 comments

Environment

fish version: fish, version 3.6.1
wezterm version: wezterm 20230712-072601-f4abf8fd
tide version: tide, version 5.6.0
OS version: macOS 11.6.4

Question

I'm encountering an issue with the cursor - its shape does not change either in vanilla fish or with the tide plugin.

Vanilla mode

image image

_ is the default shape of the wezterm terminal.


I've found a workaround that works for me in the vanilla mode:

Vanila mode with custom fish_mode_prompt

image image image image

But this workaround seems to be not suitable for the tide - it doesn't update the builtin tide's vi mode indicator and in visual mode cursor gets broken:

Tide with custom fish_mode_prompt

image image image image

So, I've tried to inject this logic that changes the cursor into the tide's logic for the indicator:

# ~/.config/fish/functions/_tide_item_vi_mode

function _tide_item_vi_mode
    test "$fish_key_bindings" != fish_default_key_bindings && switch $fish_bind_mode
        case default
            echo -en "\e[2 q"
            tide_vi_mode_bg_color=$tide_vi_mode_bg_color_default tide_vi_mode_color=$tide_vi_mode_color_default \
                  _tide_print_item vi_mode $tide_vi_mode_icon_default

        case insert
           echo -en "\e[6 q"
           tide_vi_mode_bg_color=$tide_vi_mode_bg_color_insert tide_vi_mode_color=$tide_vi_mode_color_insert \
                _tide_print_item vi_mode $tide_vi_mode_icon_insert

        case replace replace_one
            echo -en "\e[4 q"
            tide_vi_mode_bg_color=$tide_vi_mode_bg_color_replace tide_vi_mode_color=$tide_vi_mode_color_replace \
                _tide_print_item vi_mode $tide_vi_mode_icon_replace

        case visual
            echo -en "\e[2 q"
            tide_vi_mode_bg_color=$tide_vi_mode_bg_color_visual tide_vi_mode_color=$tide_vi_mode_color_visual \
                _tide_print_item vi_mode $tide_vi_mode_icon_visual
    end
end

It works properly, but I don't think it's the best solution. I believe, that there are better ways to implement this, but I have 0 experience with debuging shell rendering. So, If someone who also uses vi mode with tide and has more experience in debuging shell stuff can look at this and share their thoughts, solutions - I would appreciate it.

Afaict this would be the proper way of doing the workaround in Tide. The VI mode item is the perfect place to run those escape codes that change the cursor shape.

glyh commented

Is it possible to have this included in tide? I don't know how to both keep tide up to date and having this feature.