romkatv / powerlevel10k

A Zsh theme
MIT License
45.26k stars 2.15k forks source link

_p9k_deschedule_redraw prints to the command line during typing #1628

Closed mrincredibleu closed 2 years ago

mrincredibleu commented 2 years ago

Occasionally in the middle of typing on the command line this is printed by _p9k_deschedule_redraw and a new prompt is generated below:

_p9k_deschedule_redraw:zle:2: No handler installed for fd 33
_p9k_deschedule_redraw:3: file descriptor 33 used by shell, not closed

This usually happens within tmux after the pane running zsh has been resized a lot (with the mouse in my testing) when there is a prompt with git widgets. It has no other functional sideeffects as far as I can discern.

This shows a backlog of it happening. The reprinted prompts and commands are caused by the resizing of the tmux pane. I really don't know what to type to trigger the messages so I've repeatedly typed random things at the prompt deleted them with ^U and typed again until the messages were printed.

スクリーンショット 2021-11-05 17 18 22

Here is another example:

image

It appears to happen when there is the following lazy buildup of the prompt widgets at the beginning of the backlog.

image

From my standpoint an acceptable solution would be to disable any output for the commands in question inside of _p9k_deschedule_redraw in internal/p10k.zsh as there are no other discernible side effects other than that a new prompt is generated because of the output.

function _p9k_deschedule_redraw() {
  (( _p9k__redraw_fd )) || return
  zle -F $_p9k__redraw_fd
  exec {_p9k__redraw_fd}>&-
  _p9k__redraw_fd=0
}

The .zshrc I used for testing:

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-mrincredible.zsh" ]]; then
 source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-mrincredible.zsh"
fi

#plugins
#zinit source must be above compinit
source ~/.zinit/bin/zinit.zsh

zinit light-mode for \
  zsh-users/zsh-history-substring-search \
  zsh-users/zsh-autosuggestions \

zinit wait lucid light-mode for \
   atload"zicompinit; zicdreplay" \
     zdharma/fast-syntax-highlighting \
   atload"zicompinit; zicdreplay" blockf \
     zsh-users/zsh-completions \
   Aloxaf/fzf-tab \
   hlissner/zsh-autopair \
   atload"compdef _cd __enhancd::cd" blockf \
     b4b4r07/enhancd \
   urbainvaes/fzf-marks \
   softmoth/zsh-vim-mode \
   MichaelAquilina/zsh-you-should-use \
   wfxr/forgit \
   marlonrichert/zsh-hist \
   zdharma/history-search-multi-word \
   zdharma/zui \
   zdharma/zbrowse \
   skywind3000/z.lua \
   changyuheng/fz \
   kutsan/zsh-system-clipboard \
   @asdf-vm/asdf \
   unixorn/git-extra-commands \
   peterhurford/git-it-on.zsh \
   supercrabtree/k \
   RobSis/zsh-completion-generator \
   skx/sysadmin-util \
   jhwohlgemuth/zsh-pentest \
   srijanshetty/docker-zsh \

zinit ice as"program" pick"bin/git-fuzzy"
  zinit light bigH/git-fuzzy

zinit ice as"program" pick"clitest"
  zinit light aureliojargas/clitest

zinit ice as"theme" depth"1"
  zinit light romkatv/powerlevel10k \

zinit ice atclone"sed -i -e 's/^DIR.*$/DIR 00;36/g' LS_COLORS; dircolors -b LS_COLORS > clrs.zsh" \
 atpull'%atclone' pick"clrs.zsh" nocompile'!' \
 atload='zstyle ":completion:*" list-colors ${(s.:.)LS_COLORS}' 
zinit light trapd00r/LS_COLORS

[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
romkatv commented 2 years ago

This is almost certainly caused by a bug in one of the plugins you are using. Try disabling all of them except for powerlevel10k. If the error goes away, try to pinpoint which plugin causes issues.

mrincredibleu commented 2 years ago

zdharma/fast-syntax-highlighting appears to be the culprit. I've tested for a while and could not reproduce this issue with that plugin disabled. That plugin does not appear to be maintained any longer, I do however really like it since there don't seem to exist any other similarly good syntax highlighting plugins for zsh.

Do you know any alternative plugins or would it be possible to disable the output of _p9k_deschedule_redraw at least for this plugin?

romkatv commented 2 years ago

The error is no joke. It's a serious bug that shouldn't be masked. This error says that another plugin has closed a file descriptor it didn't own. A rogue plugin like that can cause serious havoc.

If you really want to suppress this error message, you'll have to fork powerlevel10k and edit its source code. Alternatively, you can hot-patch code at runtime. I don't recommend this!

The only alternative to zdharma/fast-syntax-highlighting is zsh-users/zsh-syntax-highlighting.

mrincredibleu commented 2 years ago

I see, I'll consider switching back to zsh-users/zsh-syntax-highlighting then since the problem probably won't be fixed anymore in zdharma/fast-syntax-highlighting. Thanks for providing some info on this!

stepanzak commented 1 year ago

I fixed this issue by loading syntax highlighting as the last plugin.