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

The last character in the first line of my custom prompt is missing #8002

Closed
EFanZh opened this issue May 15, 2021 · 5 comments
Closed

The last character in the first line of my custom prompt is missing #8002

EFanZh opened this issue May 15, 2021 · 5 comments
Milestone

Comments

@EFanZh
Copy link

EFanZh commented May 15, 2021

Fish version: 3.2.2.

This issue does not happen for fish 3.0.2 and 3.1.0.

I have a custom prompt for my fish shell:

function fish_prompt --description 'Write out the prompt'
    set -l cmd_status $status
    set -l duration "0$CMD_DURATION"

    set -l duration_days (math "floor($duration / 86400000)")
    set -l duration_days_text

    if [ $duration_days -gt 0 ]
        set duration_days_text "$duration_days d"
    end

    set -l duration_hours (math "floor($duration / 3600000) % 24")
    set -l duration_hours_text

    if [ $duration_hours -gt 0 ]
        set duration_hours_text "$duration_hours h"
    end

    set -l duration_minutes (math "floor($duration / 60000) % 60")
    set -l duration_minutes_text

    if [ $duration_minutes -gt 0 ]
        set duration_minutes_text "$duration_minutes m"
    end

    set -l duration_seconds (math "floor($duration / 1000) % 60")
    set -l duration_seconds_text

    if [ $duration_seconds -gt 0 ]
        set duration_seconds_text "$duration_seconds s"
    end

    set -l duration_milliseconds (math "$duration % 1000")
    set -l duration_milliseconds_text

    if [ '(' $duration_milliseconds -gt 0 ')' -o '(' $duration -eq 0 ')' ]
        set duration_milliseconds_text "$duration_milliseconds ms"
    end

    set -l cmd_duration (string join ' ' $duration_days_text \
                                         $duration_hours_text \
                                         $duration_minutes_text \
                                         $duration_seconds_text \
                                         $duration_milliseconds_text)

    set -l separator_length (math $COLUMNS - (string length "  $cmd_status   $cmd_duration "))
    set -l separator (string repeat -n $separator_length -N '-')

    set -l prompt_separator (set_color brblack)$separator(set_color normal)

    set -l status_color green

    if [ $cmd_status -ne 0 ]
        set status_color $fish_color_error
    end

    set -l prompt_duration (set_color -r bryellow)" $cmd_duration "(set_color normal)
    set -l prompt_status (set_color -r $status_color)" $cmd_status "(set_color normal)

    set -l virtualenv_prompt

    if set -q VIRTUAL_ENV
        set virtualenv_prompt '('(basename $VIRTUAL_ENV)') '
    end

    set -l prompt_cwd (set_color $fish_color_cwd)(prompt_pwd)(set_color normal)
    set -l prompt_vcs (__fish_git_prompt)

    set -l prompt_suffix '$'

    echo -ns \
        \r $prompt_separator ' ' $prompt_duration ' ' $prompt_status \n \
        $virtualenv_prompt $prompt_cwd $prompt_vcs ' ' $prompt_suffix ' '
end

It should look like this (fish 3.1.0):

image

Instead, a space is missing in the first line (notice the space after the green background “0”):

image

Also, even for fish 3.2.2, this problem does not happen if it is running inside a tmux panel:

image

@faho
Copy link
Member

faho commented May 15, 2021

I can't reproduce this, and it depends on which terminal you are using. This appears to be tmux, but what's the outer terminal? What is your tmux configuration?

If you just do

set -l status_color green

echo (set_color -r $status_color)" $status "(set_color normal)

What does that look like?

Also, if you want prompt things to appear on the right, you should just be using the fish_right_prompt function and save yourself all the drawing and repeating.

@EFanZh
Copy link
Author

EFanZh commented May 15, 2021

I can reproduce the problem using the following terminals:

I don’t have any custom tmux configuration.

The result of your code looks OK. Also, if I type and run fish_prompt manually, the result is also OK:

image

As for fish_right_prompt, I want to display a horizontal line as a separator, can I achieve it with fish_right_prompt?

@ridiculousfish
Copy link
Member

Ugh. If your prompt is exactly the width of the screen, then in some terminals, the clr_eol fish emits will cause the last character to be erased. This means we need to track the width of each line of the the (possibly truncated) prompt.

@ridiculousfish
Copy link
Member

Ah ha, we can cheat by just clearing the line first, before outputting its contents. Easy fix!

@ridiculousfish ridiculousfish added this to the fish 3.3.0 milestone May 18, 2021
@ridiculousfish
Copy link
Member

Verified the fix with alacritty and VSCode; please reopen if you still see it

faho added a commit that referenced this issue Jul 24, 2021
This means, if we repaint with a shorter prompt, we won't overwrite the longer parts.

This reintroduces #8002, but that's a much rarer usecase - having a prompt that fills the entire screen,
in certain terminals.

This reverts commit d3ceba1.

Fixes #8163.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants