|
From: | Chet Ramey |
Subject: | Re: Changing PSI and PS0 leads to four characters at beginning of user input |
Date: | Tue, 6 Jul 2021 09:53:57 -0400 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 |
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.
This would be correct if you replace each instance of "bash" with "readline". The distinction matters, and makes some things clearer, like why you need to do this for PS1 (the prompt that gets passed to readline when obtaining a line of input) and don't need it for PS0 (which bash simply outputs to the terminal). -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
[Prev in Thread] | Current Thread | [Next in Thread] |