Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

[Regression] vi_mode segment doesn't work in next #1201

Closed
romkatv opened this issue Mar 14, 2019 · 6 comments
Closed

[Regression] vi_mode segment doesn't work in next #1201

romkatv opened this issue Mar 14, 2019 · 6 comments
Projects

Comments

@romkatv
Copy link

romkatv commented Mar 14, 2019

vi_mode in next always shows INSERT.

How to reproduce:

First with master branch:

docker run -e LANG=C.UTF-8 -e LC_ALL=C.UTF-8 -e TERM=$TERM -it --rm ubuntu bash -uexc '
  apt update && apt install -y zsh git
  git clone -b master https://github.com/bhilburn/powerlevel9k.git ~/powerlevel9k
  echo "
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=()
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(vi_mode)
    source ~/powerlevel9k/powerlevel9k.zsh-theme
    bindkey -v" >~/.zshrc
  zsh -i'

Press ESC. Observe that INSERT on the right changes to NORMAL. Press i and it goes back to INSERT. This is expected behavior.

Now replace master with next in the command and observe that the prompt always shows INSERT.

@dritter
Copy link
Member

dritter commented Mar 14, 2019

Hey @romkatv !

Thanks for the reports (this one and #1196). I scheduled both for v0.7.0, but I am out of time to fix them for the next days. So if anyone wants to take over, I'd be happy.

Pretty good catches, btw ;)

@Syphdias
Copy link
Member

Syphdias commented Mar 23, 2019

This diff should fix vi_mode. But if the second option of #1196 (comment) is implemented this would be unnecessary.

diff --git a/segments/vi_mode/vi_mode.p9k b/segments/vi_mode/vi_mode.p9k
index b9911a3..79425a8 100644
--- a/segments/vi_mode/vi_mode.p9k
+++ b/segments/vi_mode/vi_mode.p9k
@@ -232,6 +232,8 @@ function zle-keymap-select {
       *)          cursorShape ${P9K_CURSOR_SHAPE_DEFAULT};;
     esac
   fi
+  __p9k_prepare_prompts
+  zle .reset-prompt
 }

I will create a PR anyway since atm the segment is completely broken and background_jobs "merely" has an inconsistency that is harder to fix than this (for me at least).

@romkatv
Copy link
Author

romkatv commented Mar 23, 2019

I just noticed that Powerlevel9k in next overrides zle-line-init. This will break configs of people who use the documented recipe for making vicmd the default keymap.

From http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html:

The following example puts the line editor into vi command mode when it starts up.

zle-line-init() { zle -K vicmd; }
zle -N zle-line-init

I don't know how many people use it, maybe none. There is https://gist.github.com/dbb/3893091, which seems to do the same thing.

If users put their config before sourcing powerlevel9k, it just won't work. If they put it after, then prompt will always get rendered twice, becoming twice as slow. On the first render it'll show INSERT, and then on the second render (after refreshing everything, including vcs), it'll show NORMAL.

This makes vi_mode in next more broken than in master. Both branches have the double rendering issue, and both cause jarring freezes each time keymap changes (a very common operation for vi keymap users), but only next can override user's zle-line-init so that it has no effect.

FWIW, Powerlevel10k has flawless vi_mode segment. No zle-line-init hijacking, no double rendering, no freezes, instant switching.

@Syphdias
Copy link
Member

@romkatv thx, I don't intend to rewrite the segment so I'll stick with my solution. But if anyone wants to do it, feel free.

Syphdias added a commit to Syphdias/powerlevel9k that referenced this issue Mar 27, 2019
Syphdias added a commit to Syphdias/powerlevel9k that referenced this issue Mar 27, 2019
@dritter
Copy link
Member

dritter commented Mar 29, 2019

I merged #1232 yesterday. So this issue is fixed for now. Thanks @romkatv and @Syphdias

@dritter dritter closed this as completed Mar 29, 2019
v0.7.0 automation moved this from To do to Done Mar 29, 2019
@tkolleh
Copy link

tkolleh commented Mar 19, 2020

I am experiencing similar behavior. vi_mode display string remains as POWERLEVEL9K_VI_INSERT_MODE_STRING value. Currently using the master branch at 3dafd79 of Powerlevel9k.

POWERLEVEL9K_MODE='nerdfont-complete'
ZSH_THEME="powerlevel9k/powerlevel9k"
...
plugins=(git vi-mode jenv fzf ripgrep colored-man-pages gradle rbenv conda-zsh-completion zsh-completions)
...
source $ZSH/oh-my-zsh.sh
...
POWERLEVEL9K_VI_INSERT_MODE_STRING="\ue3aa"
POWERLEVEL9K_VI_COMMAND_MODE_STRING="\u26A1"
...
# LEFT PROMPT
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vi_mode dir vcs dir_writable)

POWERLEVEL9K_VI_MODE_INSERT_BACKGROUND="deepskyblue2"
POWERLEVEL9K_VI_MODE_INSERT_FOREGROUND="gold3"
POWERLEVEL9K_VI_MODE_INSERT_VISUAL_IDENTIFIER_COLOR="black"
POWERLEVEL9K_VI_MODE_NORMAL_BACKGROUND="deepskyblue2"
POWERLEVEL9K_VI_MODE_NORMAL_FOREGROUND="gold3"

Please provide guidance on this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
v0.7.0
  
Done
Development

No branches or pull requests

4 participants