PowerShell custom prompt bugs out last character on a "syntax error" line #20712

Closed
opened 2026-01-31 07:21:56 +00:00 by claunia · 4 comments
Owner

Originally created by @azurenekowo on GitHub (Oct 21, 2023).

Windows Terminal version

1.19.2682.0

Windows build number

10.0.19045.0

Other Software

No response

Steps to reproduce

My custom prompt is implemented via the following (added into $profile):

function prompt {
     "$BASE[38;5;141m$env:username@$env:computername$BASE[38;5;228m: $BASE[38;5;250m$pwd $BASE[38;5;14m~#$RESET "
}

By default, it should show up as : username@DESKTOP-xxxxxx: C:\Users\username ~#

However, when I, say enter an invalid syntax (just typing echo ", not even executing it), it will bug out the last character (in this case, # with a red m).

image

It will persist until I press Enter, which executes the command and prompts again.
image

Expected Behavior

It shouldn't bug out the last character of the prompt.

Actual Behavior

It did bug out.
image

Originally created by @azurenekowo on GitHub (Oct 21, 2023). ### Windows Terminal version 1.19.2682.0 ### Windows build number 10.0.19045.0 ### Other Software _No response_ ### Steps to reproduce My custom prompt is implemented via the following (added into `$profile`): ```powershell function prompt { "$BASE[38;5;141m$env:username@$env:computername$BASE[38;5;228m: $BASE[38;5;250m$pwd $BASE[38;5;14m~#$RESET " } ``` By default, it should show up as : `username@DESKTOP-xxxxxx: C:\Users\username ~#` However, when I, say enter an invalid syntax (just typing `echo "`, not even executing it), it will bug out the last character (in this case, `#` with a red `m`). ![image](https://github.com/microsoft/terminal/assets/67498765/19bb1170-48fc-4be4-a098-ea18747f9326) It will persist until I press <kbd>Enter</kbd>, which executes the command and prompts again. ![image](https://github.com/microsoft/terminal/assets/67498765/3a0fee46-9e6a-4155-ba18-20bd8191de8e) ### Expected Behavior It shouldn't bug out the last character of the prompt. ### Actual Behavior It did bug out. ![image](https://github.com/microsoft/terminal/assets/67498765/0394266b-140e-40b6-a235-fb1f5914e79d)
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 07:21:56 +00:00
Author
Owner

@j4james commented on GitHub (Oct 21, 2023):

@azurenekowo As far I understand, this is a feature of PowerShell. When there is a syntax error in the command line, it redraws part of the prompt in red as a warning. However, in order for that to work correctly, it needs to know what your prompt looks like. You can control that with the PromptText option (see Using the PromptText parameter).

I'm not sure why you're getting a red m though, since by default it should be a >. Is it possible that you've already set the PromptText option without realising it?

And if you don't want the prompt to change at all, you can probably just set the PromptText to a blank string.

@j4james commented on GitHub (Oct 21, 2023): @azurenekowo As far I understand, this is a feature of PowerShell. When there is a syntax error in the command line, it redraws part of the prompt in red as a warning. However, in order for that to work correctly, it needs to know what your prompt looks like. You can control that with the `PromptText` option (see [Using the PromptText parameter]( https://learn.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-7.3#example-9-using-the-prompttext-parameter)). I'm not sure why you're getting a red `m` though, since by default it should be a `>`. Is it possible that you've already set the `PromptText` option without realising it? And if you don't want the prompt to change at all, you can probably just set the `PromptText` to a blank string.
Author
Owner

@azurenekowo commented on GitHub (Oct 22, 2023):

@j4james Hi, turns out I haven't set the PromptText option after doing function prompt {}.

After a bit of configuring, it worked. Thank you so much!

@azurenekowo commented on GitHub (Oct 22, 2023): @j4james Hi, turns out I haven't set the PromptText option after doing `function prompt {}`. After a bit of configuring, it worked. Thank you so much!
Author
Owner

@237dmitry commented on GitHub (Oct 22, 2023):

I couldn't reproduce it either in Windows Terminal or in conhost.exe

Screenshot 2023-10-22 173958

@237dmitry commented on GitHub (Oct 22, 2023): I couldn't reproduce it either in Windows Terminal or in conhost.exe ![Screenshot 2023-10-22 173958](https://github.com/microsoft/terminal/assets/78153320/23eae13f-7cbc-40fb-a282-8ff9950646e6)
Author
Owner

@lhecker commented on GitHub (Oct 23, 2023):

If I'm understanding you correctly, the issue has been resolved right? I'll be closing it then. 🙂

@lhecker commented on GitHub (Oct 23, 2023): If I'm understanding you correctly, the issue has been resolved right? I'll be closing it then. 🙂
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20712