Skip to content

Integrated Console Colors do not work on older Windows Versions without ANSI/VTY Support (2012R2 etc.) #3727

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

Closed
5 tasks done
mhdevop opened this issue Dec 17, 2021 · 25 comments
Labels

Comments

@mhdevop
Copy link

mhdevop commented Dec 17, 2021

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

VScode with this extension have worked great for roughly a year but at some point I'm not sure of, a weird issue started happening on my dev server (Windows Server 2012 R2). ANSI characters started showing up in the integrated console.

Expected:

PS C:\Users\me> get-host

Name : ConsoleHost
Version : 7.2.1
InstanceId : fd6bb11f-cb31-4266-a524-4ff936a460bf
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

Actual:

PS C:\Users\me> get-host

[32;1mName : [0mVisual Studio Code Host
[32;1mVersion : [0m2021.10.2
[32;1mInstanceId : [0mc1c2393e-ac91-4757-826e-b9cdb6392c14
[32;1mUI : [0mSystem.Management.Automation.Internal.Host.InternalHostUserInterface
[32;1mCurrentCulture : [0men-US
[32;1mCurrentUICulture : [0men-US
[32;1mPrivateData : [0mMicrosoft.PowerShell.EditorServices.Services.PowerShellContext.EditorServicesPSHost+ConsoleColorProxy
[32;1mDebuggerEnabled : [0mTrue
[32;1mIsRunspacePushed : [0mFalse
[32;1mRunspace : [0mSystem.Management.Automation.Runspaces.LocalRunspace

Things I've already tried:

Google of course
Un/Re install VScode
Upgraded PWSH
Tested the command directly in the native pwsh shell and works perfectly (seems to suggest something within the VScode integrated console)

PowerShell Version

PS D:\scripts> $psversiontable


[32;1mName                           Value[0m
[32;1m----                           -----[0m
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 6.3.9600
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


### Visual Studio Code Version

```console
PS D:\scripts> code --version

1.63.1
fe719cd3e5825bf14e14182fddeb88ee8daf044f
x64
PS D:\scripts>


### Extension Version

```console
PS D:\scripts> code --list-extensions --show-versions | Select-String powershell


ms-vscode.powershell@2021.10.2
ms-vscode.powershell-preview@2021.11.1
tobysmith568.run-in-powershell@1.1.1

PS D:\scripts>


### Steps to Reproduce

1.  Open VSCode on Windows Server 2012 R2
2.  Ensure the stable version of PowerShell is enabled with PowerShell 7.2.X installed
3.  Run a simple command like "Get-Host"

Extra info:
If I disable the "stable" version of the extension, reload, and enable the "preview" version, the ANSI characters are no longer displayed which is good. (No color though, not sure if it's supposed to or not. Also, another issue with Preview is that when a command finishes, the cursor is not visible until you hit enter on the keyboard so you're never sure if the command finished yet or not but that's another issue for Preview)

### Visuals

See the summary for a text preview

### Logs

What's weird is that when I enable "debug" logs, I do not see the issue (weird!). When I put it back to "normal" the issue happens again. I will send an email with the zipped files.
@mhdevop mhdevop added the Issue-Bug A bug to squash. label Dec 17, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Dec 17, 2021
@StevenBucher98
Copy link
Contributor

Thanks @mhdevop! Can you expand upon what you mean when you say Preview mostly works? Are you potentially changing your term env var set in your PowerShell profile?

Have you experienced this issue in the PowerShell terminal in VSCode (not integrated console)?

@andyleejordan
Copy link
Member

Also, do you experience this on OS's other than Windows Server 2012 R2? We can't seem to reproduce this.

@StevenBucher98 StevenBucher98 added Area-UI and removed Needs: Triage Maintainer attention needed! labels Jan 5, 2022
@andyleejordan andyleejordan added Needs: Author Feedback Please give us the requested feedback! and removed Area-UI labels Jan 5, 2022
@Qbert777
Copy link

Qbert777 commented Jan 6, 2022

`PS C:\Users> $psversiontable

Name Value


PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS C:\Users> code --version

1.63.2
899d46d82c4c95423fb7e10e68eba52050e30ba3
x64
PS C:\Users> code --list-extensions --show-versions | Select-String powershell

ms-vscode.powershell@2021.12.0`

I am seeing the same issue on Win10 but only when writing to a file. The issue seems to have started around the same time as mhdevop's post. For example, this line which writes to a txt file:

$emails | Select-Object @{Name="Type";Expression={$_.SenderAddress}}, Subject | Sort-Object -Property Status | Out-File -FilePath $fn -Append

Outputs like this:

�[32;1mType Subject�[0m �[32;1m---- -------�[0m

@ghost ghost added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Jan 6, 2022
@mhdevop
Copy link
Author

mhdevop commented Jan 6, 2022

Thanks @mhdevop! Can you expand upon what you mean when you say Preview mostly works? Are you potentially changing your term env var set in your PowerShell profile?

Have you experienced this issue in the PowerShell terminal in VSCode (not integrated console)?

Hopefully these 2 videos answer both your questions (if I misunderstood do let me know). Basically the raw shell by itself works fine but in VScode it generates ANSI. When I switch to the "preview" version, it resolves the ANSI issue but as you can see, the terminal doesn't show the terminal sequence indicating the command finished running until you hit enter and neither does it "clear" correctly. I'm making no "manual" changes to my env var or other settings beyond switching the plugin from PROD > Preview:

PreviewMostlyWorks
CompareVSCodeToTerminal

@mhdevop
Copy link
Author

mhdevop commented Jan 6, 2022

`PS C:\Users> $psversiontable

Name Value

PSVersion 7.2.1 PSEdition Core GitCommitId 7.2.1 OS Microsoft Windows 10.0.19043 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

PS C:\Users> code --version

1.63.2 899d46d82c4c95423fb7e10e68eba52050e30ba3 x64 PS C:\Users> code --list-extensions --show-versions | Select-String powershell

ms-vscode.powershell@2021.12.0`

I am seeing the same issue on Win10 but only when writing to a file. The issue seems to have started around the same time as mhdevop's post. For example, this line which writes to a txt file:

$emails | Select-Object @{Name="Type";Expression={$_.SenderAddress}}, Subject | Sort-Object -Property Status | Out-File -FilePath $fn -Append

Outputs like this:

�[32;1mType Subject�[0m �[32;1m---- -------�[0m

I can't "prove" it but I did see this issue semi-recently as well when looking in a log file I found a lot of ANSI characters. Can't remember where it was though or what generated it.

If it helps here's what I'm running:

PS D:\scripts> code --version
1.63.2
899d46d82c4c95423fb7e10e68eba52050e30ba3
x64

@andyleejordan
Copy link
Member

Ok, I think that what's happening is that the PowerShell Preview extension has no support for console colors yet, as we haven't yet implemented that part of the host. So no ANSI escape codes (which represent the colors) are being emitted by the Preview. We're tracking that issue here: PowerShell/PowerShellEditorServices#1607

@mhdevop
Copy link
Author

mhdevop commented Jan 12, 2022

Ok, I think that what's happening is that the PowerShell Preview extension has no support for console colors yet, as we haven't yet implemented that part of the host. So no ANSI escape codes (which represent the colors) are being emitted by the Preview. We're tracking that issue here: PowerShell/PowerShellEditorServices#1607

Just FYI - I was able to exactly reproduce this issue on a different 2012 R2 server (updated VScode, updated PowerShell plugin, and same version of PowerShell 7). I have asked that the server do an in-place upgrade to OS 2019 which I suspect will resolve the issue but I'll find out in the coming days/weeks. I have an existing 2019 server that works perfectly fine with this setup, just that pesky 2012R2 has issues. I'll update this issue once I know more unless you all want me to try something in between then.

@andyleejordan
Copy link
Member

That's specifically for the non-preview extension right?

@mhdevop
Copy link
Author

mhdevop commented Jan 13, 2022

That's specifically for the non-preview extension right?

Correct. Every single issue down to the letter is the exact same.

@andyleejordan
Copy link
Member

Ok, well the "stable" extension is just old code that will be updated with the "preview" extension soon enough. There's no need to keep testing it, it's the preview extension where bug fixes can be made.

@mhdevop
Copy link
Author

mhdevop commented Jan 13, 2022

Ok, well the "stable" extension is just old code that will be updated with the "preview" extension soon enough. There's no need to keep testing it, it's the preview extension where bug fixes can be made.

Understood. Look forward to the new 'preview' in this issue correcting both issues demonstrated in the 2 above screenshots then (like someone mentioned here likely due to handling colors): 1) showing the terminal start at the end of running a command 2) clearing the screen after the command

I'll let the experts get on with it then and let me know if I can provide anything else to help.

@andyleejordan
Copy link
Member

There's a good chunk of terminal improvements to be made. The underlying way we used PSReadLine changed drastically (for the better!) but it's left us with quite a bit to reimplement.

@StevenBucher98 StevenBucher98 added Area-Extension Terminal and removed Needs: Maintainer Attention Maintainer attention needed! labels Jan 18, 2022
@mhdevop
Copy link
Author

mhdevop commented Jan 21, 2022

FYI - I just had my 2012R2 to 2019 and the "non-preview" works fine now with colors as an added bonus. Preview still has the bug shown above where the command doesn't show the terminal character once it's done running so you're not sure if it ever finished until you hit enter.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jan 21, 2022
@andyleejordan
Copy link
Member

andyleejordan commented Jan 21, 2022

show the terminal character on

Awesome, sounds like it's just lack of ANSI color support in 2012R2. Newer versions of Windows with newer versions of PowerShell have much better support for it. Since the preview doesn't leave buggy unreadable output, but will eventually support ConsoleColor correctly, I think maybe this is resolved?

The terminal character issue actually appears to me to be the same bug as #3685 where the prompt isn't being rendered in the correct spot (that is, it should render after the output, but instead is rendering after its last location). The effect of this is that it doesn't look like it renders at all until you start typing letters which overwrite the output (or in your case, press enter and have the new prompt line render over the top of your output).

@shrihankp
Copy link

shrihankp commented Jan 24, 2022

I would like to +1 this. This happens for me as well. Even for simple commands like pwd.

PSVersionTable:

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

code --version:

1.63.2
899d46d82c4c95423fb7e10e68eba52050e30ba3
x64

winver:
Windows Version

I would, however, like to add that using PowerShell Core from the VSCode Terminal doesn't reproduce the issue. Same for pwsh.exe, via conhost and Cmder.

Edit: I tried to disable "PowerShell" and installed "PowerShell Preview" and it works. However, I do not have that issue where existing buffer doesn't clear after using Clear-Host.

@mhdevop
Copy link
Author

mhdevop commented Jan 25, 2022

show the terminal character on

Awesome, sounds like it's just lack of ANSI color support in 2021R2. Newer versions of Windows with newer versions of PowerShell have much better support for it. Since the preview doesn't leave buggy unreadable output, but will eventually support ConsoleColor correctly, I think maybe this is resolved?

The terminal character issue actually appears to me to be the same bug as #3685 where the prompt isn't being rendered in the correct spot (that is, it should render after the output, but instead is rendering after its last location). The effect of this is that it doesn't look like it renders at all until you start typing letters which overwrite the output (or in your case, press enter and have the new prompt line render over the top of your output).

I'll let you folks decide if this is "resolved" or not now that I have a workaround (an entire OS upgrade). I mean the issue does exist, it has been replicated on 2012R2, so it is an issue but I'm sure it's lower priority compared to other bugs.

@JustinGrote JustinGrote added OS-Windows and removed Needs: Maintainer Attention Maintainer attention needed! labels Jan 25, 2022
@JustinGrote JustinGrote changed the title Integrated Console Incorrectly Shows ANSI characters instead of colors (Preview works mostly) Integrated Console Colors do not work on older Windows Versions without ANSI/VTY Support (2012R2 etc.) Jan 25, 2022
@JustinGrote JustinGrote added the Up for Grabs Will shepherd PRs. label Jan 25, 2022
@JustinGrote
Copy link
Collaborator

@mhdevop seeing as 2012R2 is EOL in a year and a half, I doubt a lot of engineering effort is going to go into this honestly, unless someone wants to attempt a PR, which we will facilitate.

I am going to rename the issue to be 2012 specific and flag it as "up for grabs"

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jan 25, 2022
@JustinGrote JustinGrote removed the Needs: Maintainer Attention Maintainer attention needed! label Jan 25, 2022
@andyleejordan
Copy link
Member

@mhdevop Can you test the latest preview? We redirected the host's PrivateData to the underlying host and this probably fixes it.

@andyleejordan andyleejordan added the Needs: Fix Verification Please verify the fix for us! label Feb 23, 2022
@mhdevop
Copy link
Author

mhdevop commented Feb 24, 2022

@mhdevop Can you test the latest preview? We redirected the host's PrivateData to the underlying host and this probably fixes it.

Yes! The preview did fix it.

@andyleejordan
Copy link
Member

Yay!!!

@andyleejordan
Copy link
Member

All thanks to @SeeminglyScience.

@andyleejordan andyleejordan added Resolution-Fixed Will close automatically. and removed Needs: Fix Verification Please verify the fix for us! labels Feb 24, 2022
@andyleejordan andyleejordan moved this to Todo in Sea Biscuit Feb 24, 2022
@andyleejordan andyleejordan moved this from Todo to In Progress in Sea Biscuit Feb 24, 2022
@andyleejordan andyleejordan removed the Up for Grabs Will shepherd PRs. label Feb 24, 2022
@andyleejordan andyleejordan moved this from In Progress to Done in Sea Biscuit Feb 24, 2022
@ghost ghost closed this as completed Feb 24, 2022
@ghost
Copy link

ghost commented Feb 24, 2022

This issue has been marked as fixed. It has been automatically closed for housekeeping purposes.

@ocarela
Copy link

ocarela commented Jun 22, 2023

hi, all hope you are all fine, i have same issue in win 2012 r2 with colors, i saw the solution but i have no idea how to fix or implement it, any guide or help will be much appreciate it. thanks

@ghost
Copy link

ghost commented Jun 22, 2023

Thank you for your comment, but please note that this issue has been closed for over a week. For better visibility, consider opening a new issue with a link to this instead.

@JustinGrote
Copy link
Collaborator

JustinGrote commented Jun 24, 2023

@ocarela Can you provide a screenshot? As noted from the bot, a new issue would be helpful if you can reproduce!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

No branches or pull requests

7 participants