Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background color goes beyond prompt after program execution #14686

Closed
neur1n opened this issue Feb 1, 2021 · 12 comments
Closed

Background color goes beyond prompt after program execution #14686

neur1n opened this issue Feb 1, 2021 · 12 comments
Labels
Needs-Repro The issue author needs to provide repro steps. Needs-Triage The issue is new and needs to be triaged by a work group. WG-Interactive-Console the console experience

Comments

@neur1n
Copy link

neur1n commented Feb 1, 2021

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
@neur1n neur1n added the Needs-Triage The issue is new and needs to be triaged by a work group. label Feb 1, 2021
@neur1n
Copy link
Author

neur1n commented Feb 2, 2021

So I tested using different colors for the colored characters:
image

@daxian-dbw daxian-dbw added the WG-Interactive-Console the console experience label Feb 2, 2021
@daxian-dbw
Copy link
Member

@neur1n The repro steps you provided don't work. Invoke-Module and Write-Prompt are both not defined. Please update your repro steps.

@daxian-dbw daxian-dbw added the Needs-Repro The issue author needs to provide repro steps. label Feb 2, 2021
@neur1n
Copy link
Author

neur1n commented Feb 3, 2021

Sorry, here is the minimal configuration:

if ($IsWindows -and (Get-ExecutionPolicy) -ne 'RemoteSigned') {
  Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm
}

function Invoke-Module ($name) {
  if (Get-Module -ListAvailable -Name $name) {
    Import-Module $name
  } else {
    Write-Host 'Installing missinged module ' $name '...'
    Install-Module $name -Scope CurrentUser -AllowPrerelease -Force
  }
}

Invoke-Module 'posh-git'
Invoke-Module 'PSReadLine'

$script:indicator = ''  # u+e0b0
$script:vimode = '[I]'
$script:vicolor = [ConsoleColor]::Green

function OnViModeChange {
  if ($args[0] -eq 'Command') {
    $script:vimode = '[N]'
    $script:vicolor = [ConsoleColor]::Red
  } else {
    $script:vimode = '[I]'
    $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 += & $GitPromptScriptBlock
  $Prompt += Write-Prompt "`n $script:vimode" -BackgroundColor $script:vicolor
  $Prompt += Write-Prompt "$script:indicator" -ForegroundColor $script:vicolor
  if ($Prompt) { "$Prompt " } else { " " }
}

@mklement0

This comment has been minimized.

@neur1n
Copy link
Author

neur1n commented Feb 3, 2021

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

@daxian-dbw daxian-dbw removed the Needs-Repro The issue author needs to provide repro steps. label Feb 4, 2021
@stanciuadrian
Copy link

Not sure if related but I get the same kind of behavior with C# code ran in a PowerShell (Core & Legacy) console.

Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.Black;
Console.Write("Hello World!");
Console.ResetColor();
Console.WriteLine();

Executing dotnet run in PowerShell gives the expected behavior:

image

After resizing the shell window I get a full red line:

image

@theJasonHelmick theJasonHelmick added Resolution-Fixed The issue is fixed. Resolution-External The issue is caused by external component(s). and removed Needs-Triage The issue is new and needs to be triaged by a work group. Resolution-Fixed The issue is fixed. labels Jan 18, 2023
@theJasonHelmick
Copy link
Collaborator

theJasonHelmick commented Jan 18, 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.

@neur1n
Copy link
Author

neur1n commented 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

@daxian-dbw
Copy link
Member

@neur1n Had the issue always happened when the prompt hit the last line of the terminal, or that's only the case with the latest WT version? I'm asking because I want to understand whether this is still a variant of the linked Windows Terminal issue.

Your prompt configuration is too complex to reason what might be the cause -- several factors in play: posh-git, PSReadLine, the VI edit mode, and the Windows Terminal (by the way, Write-Prompt and $GitPromptScriptBlock are still missing from your scripts above). Can you maybe provide a simplified repro? For example, does this repro when not using posh-git? Or when not having PSReadLine imported (you can archive this by starting pwsh by pwsh -noprofile -noninteractive)?

@daxian-dbw daxian-dbw added Needs-Triage The issue is new and needs to be triaged by a work group. Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept Needs-Repro The issue author needs to provide repro steps. and removed Resolution-External The issue is caused by external component(s). labels Jan 19, 2023
@ghost
Copy link

ghost commented Jan 27, 2023

This issue has been marked as "Waiting on Author" and has not had any activity for 7 day. It has been closed for housekeeping purposes.

@ghost ghost closed this as completed Jan 27, 2023
@Fred-Vatin
Copy link

Reopen

@neur1n
Copy link
Author

neur1n commented Jan 28, 2023

Sorry about my late response. My minimal ps1 file to reproduce the issue:

function Invoke-Module ($name) {
  if (Get-Module -ListAvailable -Name $name) {
    Import-Module $name
  } else {
    Write-Host 'Installing missinged module ' $name '...'
    Install-Module $name -Scope CurrentUser -AllowPrerelease -Force
  }
}

Invoke-Module 'PSReadLine'

$script:indicator = ''
$script:vimode = '[I]'
$script:vicolor = [ConsoleColor]::Green

function OnViModeChange {
  if ($args[0] -eq 'Command') {
    $script:vimode = '[N]'
    $script:vicolor = [ConsoleColor]::Red
  } else {
    $script:vimode = '[I]'
    $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 += & $GitPromptScriptBlock
  $Prompt += Write-Prompt "`n $script:vimode" -BackgroundColor $script:vicolor
  $Prompt += Write-Prompt "$script:indicator" -ForegroundColor $script:vicolor
  if ($Prompt) { "$Prompt " } else { " " }
}

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jan 28, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Repro The issue author needs to provide repro steps. Needs-Triage The issue is new and needs to be triaged by a work group. WG-Interactive-Console the console experience
Projects
None yet
Development

No branches or pull requests

6 participants