[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forgets color when resizing with newline in prompt

From: Clark Wang
Subject: Re: Forgets color when resizing with newline in prompt
Date: Tue, 8 Oct 2019 18:38:04 +0800

On Sun, Oct 6, 2019 at 12:17 AM ao2 <ao2@jcn.localdomain> wrote:

> [...]
> Description:
>         I noticed that when there is a newline in the prompt bash "forgets"
>         about ANSI color sequences when the window is resized. I am not
> sure
>         f this is general for other kinds of ANSI escape codes.
> Repeat-By:
>         1. Set the prompt to something like:
>              PS1='\[\033[36m\]cyan\ncyan\[\033[0m\]\$ '
>            or equivalently to:
>              PS1='\[$(tput setaf 6)\]cyan\ncyan\[$(tput sgr0)\]\$ '
>         2. Resize the terminal window and see the second line of the prompt
>            loosing the color.

Did a strace when resizing the tty and it outputs this:

    ioctl(0, TIOCGWINSZ, {ws_row=73, ws_col=228, ws_xpixel=0, ws_ypixel=0})
= 0
    write(2, "\r\33[Kcyan\33[m\17# ", 14)   = 14

So it seems like Bash only reprint the last line of the prompt string when
SIGWINCH is received.

    \r -- move cursor to the beginning of current line
    \33[K -- clear from cursor to the end of the line

I don't think this is a bug and your workaround should be the best
practice. :)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]