Pure: Pure eats the last line of output from some commands

Created on 25 Apr 2018  路  2Comments  路  Source: sindresorhus/pure

General information

  • Pure version: 1.7.0
  • ZSH version: 5.5.1
  • Terminal program & version: guake 3.2.0
  • ZSH framework: oh-my-zsh

I have:

  • [x] Tested with another terminal program and can reproduce the issue: xterm 332 & termite 13
  • [x] Followed the Integration instructions for my framework

Problem description

For some commands, pure seems to fail to add it's additional newline:
2018-04-25_10-10-25_493x151

If I then hide guake and bring it back up, the last line of the output of the previous command disappears:
2018-04-25_10-10-37_414x149

I'm using i3-wm and the same happens with xterm and termite, if I move it to the scratchpad and bring it back. Or if I resize the window.

This only happens since the update to pure 1.7.0.

Reproduction steps

  1. Focus guake
  2. Execute curl https://rest.bandsintown.com/
  3. See the additional newline missing
  4. Hide guake
  5. Focus guake again
  6. See the last line of output disappeared

My .zshrc:

autoload -U promptinit; promptinit
prompt pure

Most helpful comment

Thank you very much for your fast reply. It's absolutely possible, that this was an issue before 1.7.0 and I was just lucky not running into it.

With your proposed patch, the problem is gone.

All 2 comments

I seem to be able to reproduce this with either Pure 1.6.0 or 1.7.0.

By doing: print -n hello world, then resize terminal window.

It seems to be a problem with having the "initial newline" as part of PROMPT. Zsh seems to clear the entire line when the prompt is updated.

This patch should fix it:

diff --git a/pure.zsh b/pure.zsh
index 01c1980..5a9dd64 100644
--- a/pure.zsh
+++ b/pure.zsh
@@ -141,18 +141,15 @@ prompt_pure_preprompt_render() {
    local cleaned_ps1=$PROMPT
    local -H MATCH MBEGIN MEND
    if [[ $PROMPT = *$prompt_newline* ]]; then
-       # When the prompt contains newlines, we keep everything before the first
-       # and after the last newline, leaving us with everything except the
-       # preprompt. This is needed because some software prefixes the prompt
-       # (e.g. virtualenv).
-       cleaned_ps1=${PROMPT%%${prompt_newline}*}${PROMPT##*${prompt_newline}}
+       # Remove everything from the prompt until the newline. This
+       # removes the preprompt and only the original PROMPT remains.
+       cleaned_ps1=${PROMPT##*${prompt_newline}}
    fi
    unset MATCH MBEGIN MEND

    # Construct the new prompt with a clean preprompt.
    local -ah ps1
    ps1=(
-       $prompt_newline           # Initial newline, for spaciousness.
        ${(j. .)preprompt_parts}  # Join parts, space separated.
        $prompt_newline           # Separate preprompt and prompt.
        $cleaned_ps1
@@ -167,7 +164,10 @@ prompt_pure_preprompt_render() {
    local expanded_prompt
    expanded_prompt="${(S%%)PROMPT}"

-   if [[ $1 != precmd ]] && [[ $prompt_pure_last_prompt != $expanded_prompt ]]; then
+   if [[ $1 == precmd ]]; then
+       # Initial newline, for spaciousness.
+       print
+   elif [[ $prompt_pure_last_prompt != $expanded_prompt ]]; then
        # Redraw the prompt.
        zle && zle .reset-prompt
    fi

There are other reasons to apply this patch as well, e.g. https://github.com/sindresorhus/pure/issues/376.

Thank you very much for your fast reply. It's absolutely possible, that this was an issue before 1.7.0 and I was just lucky not running into it.

With your proposed patch, the problem is gone.

Was this page helpful?
0 / 5 - 0 ratings