[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Prompt messed up if PS1 contains ANSI escape sequences
From: |
Gioele Barabucci |
Subject: |
Prompt messed up if PS1 contains ANSI escape sequences |
Date: |
Thu, 7 Sep 2023 10:11:50 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 |
Bash 5.2.15 (Debian 12) will produce erroneous output when PS1 contains
escape sequences. It will also misplace the cursor and corrupt the state
of the current line.
To replicate this issue:
1. Modify PS1 to contain one or more ANSI escape sequences, for example
"\e[45m" (tput setab 5, changes the background color to purple) or
"\e(B\e[m" (tput sgr0, reset for xterm terminals):
$ PS1="x$(printf '\e(B\e[m') \\\$ "
2. Press the up arrow to recall the last command. The command line will
now show [■ indicates the position of the cursor]:
x $ PS1="x$(printf '\e(B\e[m') \\\$ "■
3. Press the down arrow to go back to the empty prompt.
What one should see at this point is just the prompt
x $ ■
Instead, left-overs from the recalled line will be visible and the
cursor will be placed in the wrong spot:
x $ PS1="x■
The amount of garbage left on the prompt is proportional to the number
of escape sequences:
PS1="x$(printf '\e(B\e[m')\\\$ " => 6 left-over chars
PS1="x$(printf '\e(B\e[m%.0s' {1..2})\\\$ " => 12 left-over chars
PS1="x$(printf '\e(B\e[m%.0s' {1..4})\\\$ " => 24 left-over chars
Tested with TERM = linux, xterm, xterm-256color.
Regards,
(This bug has also been reported at <https://bugs.debian.org/1051388>.)
--
Gioele Barabucci
- Prompt messed up if PS1 contains ANSI escape sequences,
Gioele Barabucci <=
- Re: Prompt messed up if PS1 contains ANSI escape sequences, alex xmb ratchev, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, alex xmb ratchev, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, Gioele Barabucci, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, Greg Wooledge, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, Gioele Barabucci, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, Greg Wooledge, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, Gioele Barabucci, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, Gioele Barabucci, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, Andreas Kähäri, 2023/09/07
- Re: Prompt messed up if PS1 contains ANSI escape sequences, alex xmb ratchev, 2023/09/07