Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15484

Re: Forgets color when resizing with newline in prompt

Path csiph.com!news.mixmin.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Clark Wang <dearvoid@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Forgets color when resizing with newline in prompt
Date Tue, 8 Oct 2019 18:38:04 +0800
Lines 42
Approved bug-bash@gnu.org
Message-ID <mailman.1339.1570531129.2651.bug-bash@gnu.org> (permalink)
References <E1iGmBV-0005KB-62@jcn> <CADv8-oi9Sac8kHCy9xK7bCBHeu2tai5AMzmt8NT9BbweTMDnMQ@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1570531130 26142 209.51.188.17 (8 Oct 2019 10:38:50 GMT)
X-Complaints-To action@cs.stanford.edu
Cc "bash.bug list" <bug-bash@gnu.org>
To ao2 <ao2@jcn.localdomain>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9c5RNMsDR66+xPFtNKe+UfrYPqm5h6vg+/oprvNyfEw=; b=KHTcPWPNp+G25mVPILFZUZGCK+QwbpP5cAfwkrIaV/+YsCurD833rIKsWC38GOLGiP R6LX7+Fy1Dm16zktvNRvYPo1aLiZJgcPHOPqk0H9KVTYT3WWmKestfylcOnrfNbHZ3PH nOZesbN77t3fwlpbQUkRdNovASe5hxcCD8RXeUg2sN342eP4JTB8jZthUpWmANZrG1w9 YWiHgHbVTP+w5ynDvaBEsoBToCNSPTQUOaMaKrRwQD/E2/vefPQgHrZHwv8u1lf26JTu VmhJKwY1e0wTWVJTETS86ecXbBBbcFfgVZmuvbsBIYKGX2y8BESbh3q6MdZMcN3nKb/v pGoA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9c5RNMsDR66+xPFtNKe+UfrYPqm5h6vg+/oprvNyfEw=; b=LrhKUpA904nCplCqVEAyTXWbvIckhncBwIWiUUmlhQdahLr78VDicy4JaHaSAtEuj+ UuU07oRZhqaR8HtoC7PIY+kNCNH64C4qLuG1qpKlJBRprvXAQ6B8E3xg0e0epjgIk1Bc Zp+DN+J44o7tjkAIQZneoFD1tVrvN1vUf78c/sAdevgCY8aiAZmHSDpponZNJM9OfM75 oEPGBIIswH2Lt7P4p9PVo1e3htZdsO+/OsM1dWYEQs71//+o/c6oN994N1Fc8ML7FMfg kTw6icfx6M8EUe41jQaVrhVHDi41abIPJD8n7m0QUIwL0PMUVDT2oaZaTS/wcL7HuApQ xOZg==
X-Gm-Message-State APjAAAUo1Y+w5nC8kJxtkzXxUWlZ6yjAtinChXmXI3OPrfR1lYcs6ky4 PWiEuUYyn7w8EX1IsI4tiEVRbbNLozWJmQawArg=
X-Google-Smtp-Source APXvYqzAC0aPvlUVRrTG52iMWZtfrUEU64lIzLPOoXXKd6WN5Ks9mob/2OURjYIg9JEuQtW92h6L7sgZYAiGXjUBShc=
X-Received by 2002:a6b:ac85:: with SMTP id v127mr5273036ioe.97.1570531121676; Tue, 08 Oct 2019 03:38:41 -0700 (PDT)
In-Reply-To <E1iGmBV-0005KB-62@jcn>
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:4864:20::d33
X-Content-Filtered-By Mailman/MimeDel 2.1.23
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <CADv8-oi9Sac8kHCy9xK7bCBHeu2tai5AMzmt8NT9BbweTMDnMQ@mail.gmail.com>
X-Mailman-Original-References <E1iGmBV-0005KB-62@jcn>
Xref csiph.com gnu.bash.bug:15484

Show key headers only | View raw


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


Thread

Re: Forgets color when resizing with newline in prompt Clark Wang <dearvoid@gmail.com> - 2019-10-08 18:38 +0800

csiph-web