starship / starship

☄🌌️ The minimal, blazing-fast, and infinitely customizable prompt for any shell!
https://starship.rs
ISC License
44.18k stars 1.92k forks source link

More informative VI mode indicator #625

Closed rbpatt2019 closed 2 years ago

rbpatt2019 commented 4 years ago

Feature Request

Is your feature request related to a problem? Please describe.

Recognise this might be a Fish-specific problem. Delving onwards...

Migrating from SpaceFish, where the vi-mode indicator gave feed back on whether you were in replace, visual, insert or normal mode, as described here. I must admit, I'm a big fan of the character switching between insert and normal mode! But it gives me confusing information on visual or replace mode.

If you are in normal mode and then switch into either visual or replace mode, the prompt character switches back to insert mode. This is incredibly confusing, as there is now no clear indication of whether you are in insert, replace, or visual. When you then exit visual/replace mode, it switches back to the normal mode character, as expected.

Describe the solution you'd like

Solution A: Allow custom configuration of characters for each mode. Basically, the currently implementation expanded to have a character for visual and replace modes.

Solution B: Allow inclusion of the default fish_mode_prompt, though I suspect this would be more complicated.

Describe alternatives you've considered

I have manually configured fish_mode_prompt, but this is blocked/disabled by Starship.

seanag0234 commented 4 years ago

@rbpatt2019 I was able to add an indicator by adding this to my starship.toml.

[character]
symbol = "[I] >"
vicmd_symbol = "[N] >"
max-sixty commented 4 years ago

Would be great to be able to chose colors as well as the character change

rbpatt2019 commented 4 years ago

@seanag0234 As was I! To clarify, what I'm looking for is an indicator not for Insert or command/normal mode (which I was able to achieve), but an indicator for visual mode and replace mode. Right now visual, replace, and insert mode are all indicated by the same symbol - " [I] >>>>" in my .toml - and there isn't an option to differentiate between the three.

Adrian-Grimm commented 4 years ago

@rbpatt2019 I was able to add an indicator by adding this to my starship.toml.

[character]
symbol = "[I] >"
vicmd_symbol = "[N] >"

I didn't get it to work ... Character stays the same in every VI-Mode... My current config: https://raw.githubusercontent.com/Adrian-Grimm/DotFiles/master/.config/starship.toml (Would be nice to have something like a config validation included... but that's another topic...)

rbpatt2019 commented 4 years ago

As an update, I'm now using zsh on my work laptop and cannot find a way to add a visual/replace mode indicator there either.

pbnj commented 4 years ago

@Adrian-Grimm & @rbpatt2019 - I was able to replicate the issue on bash and didn't see a bug filed for this, so I created one: #1171

Worth noting that vicmd_symbol seems to work just fine on Fish. I haven't had a chance to test this behavior on Zsh.

sagittarius-a commented 3 years ago

After an hour of fiddling it seems that zsh does not report clear information regarding it's mode.

When inspecting KEYMAP variable in the zle-keymap-select hook, the only two values observed are main & vicmd, while I was switching from Command, Replace, Visual, Insert and Normal modes.

Based on this code that is in charge to identify the current mode,

    let mode = match (&context.shell, keymap.as_str()) {
        (Shell::Fish, "default") | (Shell::Zsh, "vicmd") => ShellEditMode::Normal,
        _ => ASSUMED_MODE,
    };

it is not possible to know if the mode is different than Normal and Insert :(


As I was writing this message, I found a very informative comment on a SO thread which states:

Visual mode is not a single state in zsh: it's defined by the combination of the mark being set, region being active and vi command mode. You can change those states independently with a custom widget or with emacs widgets. viopp and visual are only ever used as local keymaps with vicmd remaining the selected keymap. This means you don't need to repeat many vi style bindings across three keymaps: bindings in vicmd are shared, Note how few bindings visual and viopp contain compared to vicmd. But it also means that they are never selected triggering the callback

Adrian-Grimm commented 3 years ago

My issue is solved: https://github.com/starship/starship/issues/1171#issuecomment-711085024

lilyball commented 3 years ago

I'm hitting this right now in fish. starship only has two modes: "normal" and "insert". It maps Fish's "default" mode or Zsh's "vicmd" mode to "normal", and everything else to "insert".

https://github.com/starship/starship/blob/af43aeefba1cc12044f05a09a8b6f0ae309a556c/src/modules/character.rs#L34-L37

But fish has 6 different modes (default, insert, paste, replace, replace_one, and visual). "paste" can generally be ignored, it's just for bracketed paste mode (even fish_default_mode_prompt prints nothing for it). But the others should be configurable, both character and style.


FWIW anyone who wants to restore the original mode prompt can do so by just redefining it after sourcing the starship init. The simplest way is probably source $__fish_data_dir/functions/fish_mode_prompt.fish. The downside to this is having fish_mode_prompt defined means starship won't be rerun on mode changes, so you're giving up on having character reflect this. But it will sometimes get repainted in other modes, so you'll need to figure out workarounds for that.

mrjones2014 commented 2 years ago

I'd love to see a fix for this as well

adelarsq commented 2 years ago

It's there any way to add this behaviour on PowerShell at moment?