Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15484
| From | Clark Wang <dearvoid@gmail.com> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: Forgets color when resizing with newline in prompt |
| Date | 2019-10-08 18:38 +0800 |
| Message-ID | <mailman.1339.1570531129.2651.bug-bash@gnu.org> (permalink) |
| References | <E1iGmBV-0005KB-62@jcn> <CADv8-oi9Sac8kHCy9xK7bCBHeu2tai5AMzmt8NT9BbweTMDnMQ@mail.gmail.com> |
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
<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
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: Forgets color when resizing with newline in prompt Clark Wang <dearvoid@gmail.com> - 2019-10-08 18:38 +0800
csiph-web