question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Background color goes beyond prompt after program execution

See original GitHub issue

Steps to reproduce

Invoke-Module 'PSReadLine'

function OnViModeChange {
  if ($args[0] -eq 'Command') {
    $script:vicolor = [ConsoleColor]::Red
  } else {
    $script:vicolor = [ConsoleColor]::Green
  }
  [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
}

Set-PSReadLineOption -EditMode Vi
Set-PSReadLineOption -ExtraPromptLineCount 2
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange

function Prompt {
  $Prompt = Write-Prompt "`n"
  $Prompt += Write-Prompt "`n DEBUG" -BackgroundColor $script:vicolor
  $Prompt += Write-Prompt ">" -ForegroundColor $script:vicolor
  if ($Prompt) { "$Prompt " } else { " " }
}

Expected behavior

Background color stops at the last character of the prompt.

Actual behavior

When I run a program (say "some_app.exe") in pwsh and quit, the background color goes beyond the prompt as shown:

image image

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.1
PSEdition                      Core
GitCommitId                    7.1.1
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Neur1ncommented, Jan 19, 2023

@Neur1n - Thank you for reporting this issue. The working group discussed this and it turns out to be an issue with Windows Terminal, which has been fixed in the latest WT preview: microsoft/terminal#11742

After testing, we could not reproduce in the latest terminal and suggest you attempt the operation again with the latest version of Terminal.

Thanks for your effort! However, it seems that this issue starts to occur when the prompt hits the last line of the terminal (I’m using WT preview 1.16.3463.0):

  1. Things go as expected so far image
  2. Issue starts to occur image
  3. And continues image
1reaction
Neur1ncommented, Feb 3, 2021

I tried running Write-Warning foo; 'bar' as mentioned in #14506, but it did not reproduce my issue. Thanks though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

prompt and change background color in a loop with native ...
1 Answer. You can loop until value of the prompt entered is null. However you won't see the color change until after you...
Read more >
How did I change color scheme of command prompt?
Navigate to HKEY_CURRENT_USER\Software\Microsoft\Command Processor and check ... the background colour, and the second one the text colour.
Read more >
Overwrite bg color of zsh prompt
I'm using zsh with prompt fade , I do not have oh-my-zsh installed. My terminal background is dark blue, not black, but the...
Read more >
Command line CMD background change color, but how ...
1.) Change the background color and foreground color in the CMD! The first hexadecimal digit defines the background of the prompt, the second ......
Read more >
Background colors on segments not rendering in MacOS ...
Steps to Reproduce. First, create example.json with the theme from the docs. Note it has a foreground and background color. Theme:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found