[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changing PSI and PS0 leads to four characters at beginning of user input
From: |
lisa-asket |
Subject: |
Changing PSI and PS0 leads to four characters at beginning of user input |
Date: |
Sun, 4 Jul 2021 21:45:18 +0200 (CEST) |
Have now changed the code to include \[ and \]
tfb_normal=$(tput sgr0)
taf_red=$(tput setaf 9)
taf_cyan1=$(tput setaf 51)
taf_gold1=$(tput setaf 220)
PS1='\n\[${taf_cyan1}\]\u@\h:\n'
PS1=$PS1'+ \[${taf_gold1}\]\w\n\[${taf_red}\]'
PS0='\[${tfb_normal}\]' # use regular foreground color
But I am getting two strange boxes where the two Xs are.
lisa@poca:
+ ~
lisa@poca:
+ ~
cd
XX
lisa@poca:
+ ~
From: Greg Wooledge <greg@wooledge.org>
To: help-bash@gnu.org
Subject: Re: Changing PSI and PS0 leads to four characters at beginning of user
input
Date: 04/07/2021 21:32:58 Europe/Paris
On Sun, Jul 04, 2021 at 09:11:54PM +0200, lisa-asket@perso.be wrote:
> \[ \] to enclose the tput commands? I thought those were only used when
> using
>
> escape sequences only.
It doesn't matter whether the characters are hard-coded or produced by
an expansion. The point is that bash needs to know where the cursor is
at all times. It CANNOT ask the terminal, because terminals simply
don't work that way.
Bash tracks the cursor position by assuming that each time it prints
a prompt, the cursor was in the leftmost column to begin with, and then
keeping track of each character that it prints, either as a result of
expanding the prompt, or as a result of the user typing on the keyboard.
So, for every character in PS1, bash needs to know whether that character
moves the cursor forward, or not. You have to tell it, by enclosing any
characters that do NOT move the cursor inside \[ \]. Otherwise, bash
has no way to know.
- Changing PSI and PS0 leads to four characters at beginning of user input, lisa-asket, 2021/07/04
- Re: Changing PSI and PS0 leads to four characters at beginning of user input, Greg Wooledge, 2021/07/04
- Changing PSI and PS0 leads to four characters at beginning of user input, lisa-asket, 2021/07/04
- Re: Changing PSI and PS0 leads to four characters at beginning of user input, Lawrence Velázquez, 2021/07/04
- Re: Changing PSI and PS0 leads to four characters at beginning of user input, Greg Wooledge, 2021/07/04
- Changing PSI and PS0 leads to four characters at beginning of user input,
lisa-asket <=
- Re: Changing PSI and PS0 leads to four characters at beginning of user input, Greg Wooledge, 2021/07/04
- Changing PSI and PS0 leads to four characters at beginning of user input, lisa-asket, 2021/07/04
- Re: Changing PSI and PS0 leads to four characters at beginning of user input, Greg Wooledge, 2021/07/04
- Re: Changing PSI and PS0 leads to four characters at beginning of user input, David, 2021/07/05
- Changing PSI and PS0 leads to four characters at beginning of user input, lisa-asket, 2021/07/05
- Re: Changing PSI and PS0 leads to four characters at beginning of user input, Lawrence Velázquez, 2021/07/04
- Re: Changing PSI and PS0 leads to four characters at beginning of user input, Chet Ramey, 2021/07/06