Colored Prompts Confuse Windows Terminal #9026

Closed
opened 2026-01-31 01:44:09 +00:00 by claunia · 3 comments
Owner

Originally created by @cawoodm on GitHub (Jun 14, 2020).

If users have colored prompts on linux (via SSH) or WSL systems e.g. with:

export PS1="\e[0;33;1m[\u@\h \W]\$ \e[m"

Then the bash history (up arrow) gets really confused about where the user is typing and where the command is.

In the following example I pressed up arrow and then home to return to the beginning of the last command. However I end up at the wrong position as shown by me typing FF
image

I wanted to type HERE curl https:/sudo usermod -g root someuser but I ended up typing curl https:/HEREsudo usermod -g root someuser. The previous command was sudo usermod -g root someuser and the curl https:/ is some other previous command I arrowed past if that makes sense.

My suspicion is the terminal has calculated the length of my prompt \e[0;33;1m[\u@\h \W]\$ \e[m incorrectly (too long).

This is windows 10 and WT 1.0.1401.0.

Originally created by @cawoodm on GitHub (Jun 14, 2020). If users have colored prompts on linux (via SSH) or WSL systems e.g. with: ``` export PS1="\e[0;33;1m[\u@\h \W]\$ \e[m" ``` Then the bash history (up arrow) gets really confused about where the user is typing and where the command is. In the following example I pressed up arrow and then home to return to the beginning of the last command. However I end up at the wrong position as shown by me typing `FF` ![image](https://user-images.githubusercontent.com/498834/84602793-23f1f200-ae8a-11ea-9c35-345067a86a0c.png) I wanted to type `HERE curl https:/sudo usermod -g root someuser` but I ended up typing ` curl https:/HEREsudo usermod -g root someuser`. The previous command was `sudo usermod -g root someuser` and the `curl https:/` is some other previous command I arrowed past if that makes sense. My suspicion is the terminal has calculated the length of my prompt `\e[0;33;1m[\u@\h \W]\$ \e[m` incorrectly (too long). This is windows 10 and WT 1.0.1401.0.
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 01:44:09 +00:00
Author
Owner

@DHowett commented on GitHub (Jun 14, 2020):

So, line wrapping and cursor positioning is in this case controlled by the shell.

There’s a long-standing “gotcha” with using escape sequences in your prompt, that a lot of folks overlook: you need to tell the shell which regions of your prompt are nonprinting so that it can position the cursor correctly.

More info in this StackOverflow thread

@DHowett commented on GitHub (Jun 14, 2020): So, line wrapping and cursor positioning is in this case controlled by the shell. There’s a long-standing “gotcha” with using escape sequences in your prompt, that a lot of folks overlook: you need to tell the shell _which regions of your prompt are nonprinting_ so that it can position the cursor correctly. More info in [this StackOverflow thread](https://unix.stackexchange.com/questions/105958/terminal-prompt-not-wrapping-correctly)
Author
Owner

@cawoodm commented on GitHub (Jun 15, 2020):

Thanks! I'd never had this problem with other console/terminals so I thought it must be WT but it was just me using a new fancy colored prompt!

Here's the escaped version in case it helps anyone else:

export PS1="\[\e[0;33;1m\][\u@\h \W]\$ \[\e[m\]"
@cawoodm commented on GitHub (Jun 15, 2020): Thanks! I'd never had this problem with other console/terminals so I thought it must be WT but it was just me using a new fancy colored prompt! Here's the escaped version in case it helps anyone else: ``` export PS1="\[\e[0;33;1m\][\u@\h \W]\$ \[\e[m\]" ```
Author
Owner

@DHowett commented on GitHub (Jun 15, 2020):

Thanks!
Glad it helped.

@DHowett commented on GitHub (Jun 15, 2020): Thanks! Glad it helped.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#9026