[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Prompt messed up if PS1 contains ANSI escape sequences
From: |
alex xmb ratchev |
Subject: |
Re: Prompt messed up if PS1 contains ANSI escape sequences |
Date: |
Thu, 7 Sep 2023 15:01:09 +0200 |
sorry \] missing bug
PS1=$'\u\[\e[1m\]\h\[\e[0m\]- '
On Thu, Sep 7, 2023, 15:00 alex xmb ratchev <fxmbsw7@gmail.com> wrote:
> u have to \[ esc-seq \]
> eg inside \[ and \]
>
> PS1=$'\u\[\e[1m\]\h\[\e[0m- '
>
> should display hostname bold
>
> On Thu, Sep 7, 2023, 14:55 Gioele Barabucci <gioele@svario.it> wrote:
>
>> 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, 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,
alex xmb ratchev <=
- 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
- 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, Kerin Millar, 2023/09/07