romkatv / powerlevel10k

A Zsh theme
MIT License
46.81k stars 2.21k forks source link

[Question] Prompt at the bottom of the terminal window? #563

Closed bwoodruff closed 4 years ago

bwoodruff commented 4 years ago

I noticed in a number of your screen recordings where transient prompt is enabled you've got the prompt at the bottom of the terminal window.

e.g. https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/performance.gif

Is this just a visual trick with the recording, or do you really have a way to have GNOME terminal start with the prompt at the bottom of the window? If the latter, would you mind sharing?

Thanks for building such a useful and enjoyable tool.

Aloxaf commented 4 years ago

or do you really have a way to have GNOME terminal start with the prompt at the bottom of the window

put this line in your zshrc, before load instant prompt.

printf '\n%.0s' {1..100}
romkatv commented 4 years ago

put this line in your zshrc, before load instant prompt.

Yes, that's pretty much how I've recorded this. You can even see cursor in the top-left corner on the first frame of the gif.

I found that for users who aren't familiar with transient prompt it's much easier to follow what's going on when prompt is at the bottom. After you use transient prompt for a little while, it becomes natural regardless of prompt position.

ForestBeaver commented 4 years ago

To bump a closed issue; I think this would be a good configuration option. When I saw the gif for transient prompts I expected (and was hoping) it would push the input to the bottom.

romkatv commented 4 years ago

It's easy to push cursor to the bottom of the screen when you start zsh. The problem is that it can be pushed up by zle, zle widgets and external commands. When this happens, there is no way to push it back down without filling (a portion of) screen with empty space. This feature could be implemented in a terminal but not on the level of applications running in the terminal.

nfbyte commented 4 years ago

When using xterm with these lines in .zshrc (set before powerlevel10k, which is configured with sparse lines, instant prompt and transient prompt),

# Change cursor to I-beam
printf '\033[5 q\r'

# Move prompt to the bottom
printf '\n%.0s' {1..100}

the prompt appears at shell startup like so:

.
.
.
.
.
.
.~/my-prompt
.❯ |
.

but after using a command, it shifts to the bottommost line like so:

.
.
.
.❯ echo 123
.123
.
.~/my-prompt
.❯ |

Would it be possible to fix this inconsistency (i.e. have the prompt either always have an empty line under it or always show on the bottommost line - ideally the former)?

romkatv commented 4 years ago

Would it be possible to fix this inconsistency (i.e. have the prompt either always have an empty line under it

This is impossible without patching the source code of your terminal emulator.

or always show on the bottommost line

You can do this by adding the following parameter to ~/.p10k.zsh:

typeset -g POWERLEVEL9K_INSTANT_PROMPT_COMMAND_LINES=0

It doesn't matter where exactly in ~/.p10k.zsh you add it. Next to the existing POWERLEVEL9K_INSTANT_PROMPT would be sensible.

Once you add the parameter, restart zsh (e.g., with exec zsh) twice.

t-dub commented 1 year ago

Rather than choosing an arbitrarily high number of blank lines to print, you can use the actual height of the terminal which is (usually) set in the environment variable $LINES. So then the line in your .zshrc becomes:

printf '\n%.0s' {1..$LINES}

Note that this should be placed in your .zshrc before the p10k instant prompt. It runs fast enough to not negate the benefits of the instant prompt and will ensure you don't get "judder" with your heavily decorated p10k prompt showing at the top of the terminal (however briefly) before jumping to the bottom.

romkatv commented 1 year ago

FWIW, zsh4humans can put cursor at the bottom of the terminal and keep it there. You can see how it works in this screencast:

asciicast

ajay007e commented 1 year ago

Rather than choosing an arbitrarily high number of blank lines to print, you can use the actual height of the terminal which is (usually) set in the environment variable $LINES. So then the line in your .zshrc becomes:

printf '\n%.0s' {1..$LINES}

Note that this should be placed in your .zshrc before the p10k instant prompt. It runs fast enough to not negate the benefits of the instant prompt and will ensure you don't get "judder" with your heavily decorated p10k prompt showing at the top of the terminal (however briefly) before jumping to the bottom.

But it goes up when we use clear ?? So do you guys have any hack to solve this issue ?

romkatv commented 1 year ago

If you are using zsh4humans, see https://github.com/romkatv/zsh4humans/blob/master/tips.md#prompt-at-bottom

If not, improvise.

ajay007e commented 1 year ago

No, I am not using zsh4humans. I am using the typewriter theme.

romkatv commented 1 year ago

Then improvise.

Aqa-Ib commented 1 year ago

But it goes up when we use clear ?? So do you guys have any hack to solve this issue ?

alias clear="clear && printf '\n%.0s' {1..$LINES}"

rwmitchell commented 1 year ago
printf "\e[H\ec\e[${LINES}B"

This avoids printing a bunch of newlines and also does the 'clear'

fuchsg commented 1 year ago

You could also use something like:

clear && tput cup $LINES 0

And to make sure the prompt stays down after using something like fzf, I have this in my zsh hooks:

function bottom_prompt {
  tput cup $(($LINES-2)) 0
}
add-zsh-hook precmd bottom_prompt

The $(($LINES-2)) statement is just to avoid scrolling with my multiline prompt. Depending on your prompt design you might have to adjust that number to avoid unnecessary scrolling in one direction or overwriting some output in the other.

Domiragi commented 3 months ago

For my case, I don't want the prompt to be permanently at the bottom, I just want to make it so that when terminal starts filling down, the prompt never fully touches the bottom and stays a certain distance from the bottom to be within reasonably readable range.

Before using Powerlevel10k, I configured my zsh prompt to use this solution: https://unix.stackexchange.com/questions/698587/keep-cursor-prompt-vertically-centered-in-zsh-fish/698626#698626

When I tried to adapt this to Powerlevel10k, I found that adding user-defined prompt segment didn't work. The way I adapted this was to make change to pre_cmd:

precmd() {
    # This makes the prompt stays at least 8 lines from the bottom
    print $'\n\n\n\n\n\n\n\n\e[8A'
}

Which will works exactly as expected. The only downsides are that: (1) because this will output during zsh initialization, you might want to set in your .p10k.zsh: typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet to avoid the warning ; and (2) sending an interrupt signal to the terminal, such as by pressing Ctrl+C, will not run the precmd section and as such the prompt will go down to the bottom. But running any other commands will make the behavior normal again.