Skip to content

Write-Host -NoNewLine not respected #3651

Closed

Description

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

Activity

  1. ghost added
    Needs: TriageMaintainer attention needed!
    on Oct 29, 2021
  2. andyleejordan commented on Oct 29, 2021

    @andyleejordan
    Member

    Well now this one is weird!

  3. fflaten commented on Oct 30, 2021

    @fflaten
    Contributor

    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

  4. fflaten commented on Nov 3, 2021

    @fflaten
    Contributor

    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.

  5. andyleejordan commented on Nov 3, 2021

    @andyleejordan
    Member

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

  6. SeeminglyScience commented on Nov 5, 2021

    @SeeminglyScience
    Collaborator

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

  7. fflaten commented on Nov 5, 2021

    @fflaten
    Contributor

    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.

  8. SeeminglyScience commented on Nov 5, 2021

    @SeeminglyScience
    Collaborator

    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

  9. 1 remaining item

  10. SeeminglyScience commented on Nov 5, 2021

    @SeeminglyScience
    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.

  11. andyleejordan commented on Nov 5, 2021

    @andyleejordan
    Member

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

  12. SeeminglyScience commented on Nov 5, 2021

    @SeeminglyScience
    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.

  13. andyleejordan commented on Nov 5, 2021

    @andyleejordan
    Member

    Ohh, I see! Thanks Patrick.

  14. andyleejordan commented on Jan 13, 2022

    @andyleejordan
    Member

    Unfortunately Patrick Meinecke (@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?

  15. andyleejordan commented on Jan 18, 2022

    @andyleejordan
    Member

    Fix for this has been merged!

  16. changed the title [-]Write-Host -NoNewLine not respected in newest preview[/-] [+]`Write-Host -NoNewLine` not respected[/+] on Jan 18, 2022
  17. ghost closed this as completedon Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions