Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Under some conditions, when typing next cmd during previous cmd execution, prompt formatting gets mangled #39

Open
AndydeCleyre opened this issue Apr 4, 2022 · 8 comments
Assignees

Comments

@AndydeCleyre
Copy link
Contributor

Hello!

Sometimes I begin typing the next command while the previous one is running, and this works, even with this bug. But the prompt display gets temporarily mangled in this event.

This is hard for me to reliably reproduce with a clean setup, and so I'm sorry for such a messy report.

I think that to reproduce we need:

  • set the left-only prompt variable
  • set my ridiculous custom RPROMPT
  • be in a git repo folder (certain git status needed?)
  • be in a tmux session
  • load zcontinuum/fast-syntax-highlighting (?)

Here's my prompt-related code:

setopt promptsubst

() {
  emulate -L zsh

  local usual_distro='Arch Linux' usual_host='pop-os' usual_user='andy'
  local ptime='%D{%L:%M}'

  local agkozakpath p10kpath
  agkozakpath=~/Code/plugins/zsh/agkozak-zsh-prompt/agkozak-zsh-prompt.plugin.zsh
  p10kpath=~/Code/plugins/zsh/powerlevel10k/powerlevel10k.zsh-theme

  if [[ -r $agkozakpath ]] {
    if [[ $HOST != $usual_host || $USERNAME != $usual_user ]] {
      AGKOZAK_USER_HOST_DISPLAY=1
    } else {
      AGKOZAK_USER_HOST_DISPLAY=0
    }
    AGKOZAK_CUSTOM_SYMBOLS=('⇣⇡' '' '' '+' 'x' '!' '>' '?' 'S')
    AGKOZAK_LEFT_PROMPT_ONLY=1
    AGKOZAK_PROMPT_CHAR=('%F{white}%B->>%b%f' '#' ':')
    AGKOZAK_PROMPT_DIRTRIM=4
    AGKOZAK_PROMPT_DIRTRIM_STRING=…
    if [[ $TMUX ]] && [[ $TMUX != *tmate* ]] {
      AGKOZAK_CUSTOM_RPROMPT='${(j: :)${(f)"$(tmux lsw -F "#{?#{==:#{pane_tty},$TTY},%B%F{white#},%F{blue#}}#{?#{!=:#W,zsh},#W,%%}#{?#{!=:#{window_panes},1},+,}%f%b" 2>/dev/null)"}} %F{green}'$ptime'%f'
    } else {
      AGKOZAK_CUSTOM_RPROMPT='%F{green}'$ptime'%f'
    }

    . $agkozakpath

  } elif [[ -r $p10kpath ]] {

    # ...

  } else {
    # ...
  }
}

PROMPT2='%B%F{blue}->…%f%b '

When run within a tmux session, run sleep 1, and then keep typing while that finishes:

~/Code/zpy (develop S)
->> sleep 1                                                           % 12:37
xxxxxxxxxxxxxx%                                                               }~/Code/zpy} (develop S)${AGKOZAK_PROMPT_WHITESPACE}}${AGKOZAK_PROMPT_CHAR[1]:-%} xxxxxxxxxxxxxxxxxxxxx

image

@agkozak agkozak self-assigned this Apr 4, 2022
@agkozak
Copy link
Owner

agkozak commented Apr 4, 2022

Hello, @AndydeCleyre! Thanks for the report. I have seen something like that myself on occasion, but I have never been able to pinpoint the exact conditions. I'll give your configuration a try.

@agkozak
Copy link
Owner

agkozak commented Apr 4, 2022

Your configuration is great -- I've gotten the problem to occur a couple of times already. I'll get to work on this.

@agkozak
Copy link
Owner

agkozak commented Apr 4, 2022

I only seem to have this problem if I use zdharma-continuum/fast-syntax-highlighting (it doesn't happen with zsh-users/zsh-syntax-highlighting). In fact, I run into it reliably with a mere

source /path/to/agkozak-zsh-prompt.plugin.zsh
source /path/to/fast-syntax-highlighting.plugin.zsh

in my .zshrc, and sleep 1, followed by fast typing, at the command line -- as you pointed out.

Reversing the order in which I load the two plugins seems to help slightly; if any garbling occurs, it is corrected when I switch to vi command mode. Interesting.

I'll keep playing around with this.

@AndydeCleyre
Copy link
Contributor Author

Thanks! The FSH interaction was something I only considered while writing this issue, and your corroboration spurred me to try a bisect on FSH. Over here, it looks like the problem started with:

commit 08a4ce96953764f03d617f1c52e9a2a3ad6f58c2
Author: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Date:   Sun Feb 23 01:01:14 2020 +0100

    plugin.zsh: Use emulate instead of bare setopt

diff --git a/fast-syntax-highlighting.plugin.zsh b/fast-syntax-highlighting.plugin.zsh
index f11177d..4b88d3f 100644
--- a/fast-syntax-highlighting.plugin.zsh
+++ b/fast-syntax-highlighting.plugin.zsh
@@ -72,7 +72,9 @@ _zsh_highlight()
     return $ret
   fi
 
-  setopt localoptions warncreateglobal noksharrays noshwordsplit extendedglob typesetsilent nokshglob
+  emulate -LR zsh
+  setopt extendedglob warncreateglobal typesetsilent noshortloops
+
   local REPLY # don't leak $REPLY into global scope
   local -a reply

@AndydeCleyre
Copy link
Contributor Author

AndydeCleyre commented Apr 5, 2022

So I checked output of setopt just after that sets the options, from before and after:

--- BEFORE.txt	2022-04-04 22:25:12.080597430 -0400
+++ AFTER.txt	2022-04-04 22:26:08.085803758 -0400
@@ -1,22 +1,13 @@
-alwaystoend
-autopushd
-nocaseglob
-completeinword
 extendedglob
-noflowcontrol
-globdots
-histignorealldups
-histignorespace
-histverify
 interactive
-interactivecomments
 localoptions
+localpatterns
+localtraps
 login
 monitor
-promptsubst
-pushdignoredups
-sharehistory
 shinstdin
+noshortloops
 typesetsilent
 warncreateglobal
 zle

@AndydeCleyre
Copy link
Contributor Author

AndydeCleyre commented Apr 5, 2022

I'm currently testing with promptsubst added to the list. So far, so good.

EDIT: Nope, reproduced.

@AndydeCleyre
Copy link
Contributor Author

AndydeCleyre commented Jul 14, 2022

I haven't seen this since locally reverting zdharma-continuum/fast-syntax-highlighting@08a4ce9. I'll open an issue there linked to this one.

@agkozak
Copy link
Owner

agkozak commented Jul 14, 2022

Fascinating. Thanks for staying on top of this issue, @AndydeCleyre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants