On Sun, Oct 6, 2019 at 12:17 AM ao2 <[email protected]> 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
<https://en.wikipedia.org/wiki/ANSI_escape_code>
I don't think this is a bug and your workaround should be the best
practice. :)
-clark