Issues with getting previous command and backspace #14643

Closed
opened 2026-01-31 04:15:42 +00:00 by claunia · 3 comments
Owner

Originally created by @ibqasim on GitHub (Jul 22, 2021).

Windows Terminal version (or Windows build number)

1.8.1521.0

Other Software

Using bash on WSL on Windows Terminal.

Steps to reproduce

Using bash on WSL on Windows Terminal.

  • Type some command and run it.
  • Then try to go back to a previous command (up arrow), and backspace to clear it.

Note that this does not happen every time. Sometimes the command can be cleared as expected, sometimes it cannot.

See below:
bash

The first line ran fine. Then I tried to select a previous command, and was able to clear it fine, and pressed enter. Then again, same thing. But third time I tried to backspace, and it would not go past the li. However, the text actually get's cleared, as if I press enter it gives no output, and I can type additional commands and they work as expected. But visually, the text is still there.

I should add that I have seen similar behaviour before on the online IDE platform repl.it, where commands do not fully get deleted visually.

Apologies if this is a possible duplicate.

Expected Behavior

You should be able to clear the entire command.

Actual Behavior

Only some of the previous command gets cleared, and new text gets appended to it. However the actual text has been deleted, but it doesn't show.

Originally created by @ibqasim on GitHub (Jul 22, 2021). ### Windows Terminal version (or Windows build number) 1.8.1521.0 ### Other Software Using bash on WSL on Windows Terminal. ### Steps to reproduce Using bash on WSL on Windows Terminal. - Type some command and run it. - Then try to go back to a previous command (up arrow), and backspace to clear it. Note that this does not happen every time. Sometimes the command can be cleared as expected, sometimes it cannot. See below: ![bash](https://user-images.githubusercontent.com/8299797/126688983-c7ea17ea-a887-445f-8c4c-0edff6fb406b.png) The first line ran fine. Then I tried to select a previous command, and was able to clear it fine, and pressed enter. Then again, same thing. But third time I tried to backspace, and it would not go past the li. However, the text actually get's cleared, as if I press enter it gives no output, and I can type additional commands and they work as expected. But visually, the text is still there. I should add that I have seen similar behaviour before on the online IDE platform repl.it, where commands do not fully get deleted visually. Apologies if this is a possible duplicate. ### Expected Behavior You should be able to clear the entire command. ### Actual Behavior Only some of the previous command gets cleared, and new text gets appended to it. However the actual text has been deleted, but it doesn't show.
Author
Owner

@zadjii-msft commented on GitHub (Jul 23, 2021):

What's your PS1 in bash?

@zadjii-msft commented on GitHub (Jul 23, 2021): What's your `PS1` in `bash`?
Author
Owner

@ibqasim commented on GitHub (Jul 23, 2021):

What's your PS1 in bash?

$(horizontal_line)\n\# \t \w $(virtualenv_prompt)\n$

horizontal_line just draws dashes the width of the window.
virtualenv_prompt adds the name of the current python virtual environment.

My PS1 is set as follows (multiple lines are just so it's easier to edit):

PS1=""
PS1="$PS1$(tput setaf 8)\$(horizontal_line)\n"
PS1="$PS1$(tput setaf 1)\# "
PS1="$PS1$(tput setaf 6)\t "
PS1="$PS1$(tput setaf 3)\w "
PS1="$PS1$(tput setaf 5)\$(virtualenv_prompt)\n"
PS1="$PS1$(tput setaf 2)$(tput bold)\$ "
PS1="$PS1$(tput sgr0)"
export PS1
@ibqasim commented on GitHub (Jul 23, 2021): > What's your `PS1` in `bash`? `$(horizontal_line)\n\# \t \w $(virtualenv_prompt)\n$` horizontal_line just draws dashes the width of the window. virtualenv_prompt adds the name of the current python virtual environment. My PS1 is set as follows (multiple lines are just so it's easier to edit): ``` PS1="" PS1="$PS1$(tput setaf 8)\$(horizontal_line)\n" PS1="$PS1$(tput setaf 1)\# " PS1="$PS1$(tput setaf 6)\t " PS1="$PS1$(tput setaf 3)\w " PS1="$PS1$(tput setaf 5)\$(virtualenv_prompt)\n" PS1="$PS1$(tput setaf 2)$(tput bold)\$ " PS1="$PS1$(tput sgr0)" export PS1 ```
Author
Owner

@zadjii-msft commented on GitHub (Jul 26, 2021):

Yep, that's what I suspected. When you're using escape sequences to format your bash prompt, you need to wrap them up so that bash knows that they're not visible characters.

From the docs

              \[     begin a sequence of non-printing characters,
                     which could be used to embed a terminal con­
                     trol sequence into the prompt
              \]     end a sequence of non-printing characters

If you slap those on either side of the $(tput ...) commands, that should fix it.

@zadjii-msft commented on GitHub (Jul 26, 2021): Yep, that's what I suspected. When you're using escape sequences to format your `bash` prompt, you need to wrap them up so that `bash` knows that they're not visible characters. From [the docs](https://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html) ``` \[ begin a sequence of non-printing characters, which could be used to embed a terminal con­ trol sequence into the prompt \] end a sequence of non-printing characters ``` If you slap those on either side of the `$(tput ...)` commands, that should fix it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14643