Skip to content

Write-Host -NoNewLine not respected #3651

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
PrzemyslawKlys opened this issue Oct 29, 2021 · 15 comments
Closed
5 tasks done

Write-Host -NoNewLine not respected #3651

PrzemyslawKlys opened this issue Oct 29, 2021 · 15 comments
Assignees
Labels
Area-Extension Terminal Bug: Pre-release Bugs reproducing only in the pre-release extension. Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.

Comments

@PrzemyslawKlys
Copy link
Contributor

PrzemyslawKlys commented Oct 29, 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

I have written PowerShell module PSWriteColor which uses Write-Host -NoNewLine pretty much all the time

image

Write-Host -NoNewline -BackgroundColor Red -Object 'Test'
Write-Host -NoNewline -BackgroundColor Blue -Object 'Test 1'
Write-Host -NoNewline -BackgroundColor DarkGray -Object 'Test 2'

image

Write-Color -Text 'Test1 ', 'Test2 ','Test3' -Color Red, Blue, DarkGray

PowerShell Version

Name                           Value
----                           -----
PSVersion                      5.1.22000.282
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22000.282
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visual Studio Code Version

1.61.2
6cba118ac49a1b88332f312a8f67186f7f3c1643
x64

Extension Version

ironmansoftware.powershell-universal@2.3.0
ms-vscode.powershell@2021.10.2
ms-vscode.powershell-preview@2021.10.3
tobysmith568.run-in-powershell@1.1.1
TylerLeonhardt.vscode-inline-values-powershell@0.0.5

Steps to Reproduce

Type in powershell editor, press F5

Write-Host -NoNewline -BackgroundColor Red -Object 'Test'
Write-Host -NoNewline -BackgroundColor Blue -Object 'Test 1'
Write-Host -NoNewline -BackgroundColor DarkGray -Object 'Test 2'

Visuals

No response

Logs

No response

@PrzemyslawKlys PrzemyslawKlys added the Issue-Bug A bug to squash. label Oct 29, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Oct 29, 2021
@andyleejordan
Copy link
Member

Well now this one is weird!

@andyleejordan andyleejordan added the Bug: Pre-release Bugs reproducing only in the pre-release extension. label Oct 29, 2021
@fflaten
Copy link
Contributor

fflaten commented Oct 30, 2021

I see this with Pester too. Formatting using NoNewLine, ForegroundColor and BackgroundColor with Write-Host doesn't work, so output is broken.

ANSI and [System.Console]::ForegroundColor + WriteLine seems to work fine

@andyleejordan andyleejordan added this to the Consider-vNext milestone Nov 1, 2021
@andyleejordan andyleejordan removed the Needs: Triage Maintainer attention needed! label Nov 1, 2021
@andyleejordan andyleejordan self-assigned this Nov 1, 2021
@fflaten
Copy link
Contributor

fflaten commented Nov 3, 2021

Does the new PSES backend rely on stream-redirection? I just remembered this issue in Pester about formatting being lost when information stream (which Write-Host in 5+ uses) is being redirected.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Nov 3, 2021
@andyleejordan
Copy link
Member

I think the color problem is likely due to PowerShell/PowerShellEditorServices#1607

@SeeminglyScience
Copy link
Collaborator

SeeminglyScience commented Nov 5, 2021

EditorServicesConsolePSHostUserInterface needs to implement the virtual (and otherwise empty) method WriteInformation(InformationRecord) (it can just redirect to the origin host like the other methods).

@fflaten
Copy link
Contributor

fflaten commented Nov 5, 2021

EditorServicesConsolePSHostUserInterface needs to implement the virtual (and otherwise empty) method WriteInformation(InformationRecord) (it can just redirect to the origin host like the other methods).

Yeah that's sounds more like what I'd expect as it would also affect the NoNewLine-part. 👍

Not really related to this issue but should it also implement WriteLine(ConsoleColor, ConsoleColor, String)? It's also missing unlike the Write(ConsoleColor...-equivalent.

@SeeminglyScience
Copy link
Collaborator

SeeminglyScience commented Nov 5, 2021

Not really related to this issue but should it also implement WriteLine(ConsoleColor, ConsoleColor, String)? It's also missing unlike the Write(ConsoleColor...-equivalent.

You'd want to open an issue on PowerShell/PowerShell for that, we don't control that particular API surface. Nvm failed at reading

@fflaten
Copy link
Contributor

fflaten commented Nov 5, 2021

Not really related to this issue but should it also implement WriteLine(ConsoleColor, ConsoleColor, String)? It's also missing unlike the Write(ConsoleColor...-equivalent.

You'd want to open an issue on PowerShell/PowerShell for that, we don't control that particular API surface.

I meant implemented in EditorServicesConsolePSHostUserInterface. 🙂

@SeeminglyScience
Copy link
Collaborator

I meant implemented in EditorServicesConsolePSHostUserInterface. 🙂

Oops! 😁

Yeah that'd be good to add as well, thanks for catching that. I don't think it'll cause any bugs since the method does have a default implementation but ConsoleHost does override it so might as well.

@andyleejordan
Copy link
Member

Interesting...I wonder why we didn't manage to get this as fleshed out.

@SeeminglyScience
Copy link
Collaborator

Interesting...I wonder why we didn't manage to get this as fleshed out.

Incredibly easy to miss tbh. They don't get generated from the code action to implement an abstract type. You need the one that says "Generate all overrides" or something like that. Though even with that you need to be careful not to override a method with a default implementation you need to keep. Kind of a rough extension model to have empty virtual methods rather than abstract, but it's what you gotta to to not introduce breaking changes.

@andyleejordan
Copy link
Member

Ohh, I see! Thanks Patrick.

@andyleejordan
Copy link
Member

Unfortunately @SeeminglyScience there seems to be a bit more to it than just overriding those abstract methods. I'll open a draft PR, but in my testing it's not seeming to fix it. There's also a _consoleHostUI that perhaps comes into play?

@andyleejordan
Copy link
Member

Fix for this has been merged!

@andyleejordan andyleejordan added the Resolution-Fixed Will close automatically. label Jan 18, 2022
@andyleejordan andyleejordan changed the title Write-Host -NoNewLine not respected in newest preview Write-Host -NoNewLine not respected Jan 18, 2022
@ghost ghost closed this as completed Jan 18, 2022
@ghost
Copy link

ghost commented Jan 18, 2022

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

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extension Terminal Bug: Pre-release Bugs reproducing only in the pre-release extension. Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.
Projects
No open projects
Status: Done
5 participants