Spaceship-prompt: Clearing the buffer without clearing the status line

Created on 28 May 2019  路  4Comments  路  Source: denysdovhan/spaceship-prompt

Basically, when you clear the buffer with Cmd + K, since the status line is printed above the actual prompt, it also gets cleared. This doesn't, however, happen with a simple clear.

I'm hoping someone has a clever way to get around this. So far I've been clearing the buffer then clearing normally immediately after, but it's not ideal.

Environment

Spaceship version: 3.10.0
Zsh version: zsh 5.3 (x86_64-apple-darwin17.0)
Zsh framework: oh-my-zsh
Zsh plugin manager: None
Terminal emulator: iTerm
Operating system: macOS

Demonstration

Imgur

Most helpful comment

function clear-scrollback-buffer {
  # clear screen
  clear
  # clear buffer
  printf '\e[3J'
  # .reset-prompt: bypass the zsh-syntax-highlighting wrapper
  # https://github.com/sorin-ionescu/prezto/issues/1026
  # https://github.com/zsh-users/zsh-autosuggestions/issues/107#issuecomment-183824034
  # -R: redisplay the prompt to avoid old prompts being eaten up
  # https://github.com/Powerlevel9k/powerlevel9k/pull/1176#discussion_r299303453
  zle .reset-prompt && zle -R
}

zle -N clear-scrollback-buffer
bindkey '^L' clear-scrollback-buffer

All 4 comments

Firstly, your problem has nothing to do with this prompt theme. I don't understand why you opened a issue here.

Clear Buffer with Cmd + K is a terminal function exclusive to iTerm. It's implemented by the terminal to delete the history output.

While clear means clear screen and it just hides the content to the top, which is implemented by the shell.

If you only need a key binding to clear the screen, try Ctrl-L. If it doesn't work, use this

bindkey "^L" clear-screen

It is related to the prompt theme. I'm not saying it's an issue with the theme, but my issue is because of the theme.

With spaceship prompt, the status line is printed above the prompt as a separate line. When you clear the buffer, it clears the status line.

I understand the difference between clearing the buffer and clear. Thank you for your explanation, though.

I was wondering if anybody had a workaround for this, whilst still clearing the buffer. Simply clearing the screen is not enough. That is why I opened this support request.

Thanks for your time.

function clear-scrollback-buffer {
  # clear screen
  clear
  # clear buffer
  printf '\e[3J'
  # .reset-prompt: bypass the zsh-syntax-highlighting wrapper
  # https://github.com/sorin-ionescu/prezto/issues/1026
  # https://github.com/zsh-users/zsh-autosuggestions/issues/107#issuecomment-183824034
  # -R: redisplay the prompt to avoid old prompts being eaten up
  # https://github.com/Powerlevel9k/powerlevel9k/pull/1176#discussion_r299303453
  zle .reset-prompt && zle -R
}

zle -N clear-scrollback-buffer
bindkey '^L' clear-scrollback-buffer

That's a great solution, thanks @laggardkernel :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChadTaljaardt picture ChadTaljaardt  路  4Comments

jwhipp picture jwhipp  路  3Comments

salmanulfarzy picture salmanulfarzy  路  3Comments

MatthiasJ picture MatthiasJ  路  4Comments

martincartledge picture martincartledge  路  4Comments