Repository navigation
Write-Host -NoNewLine not respected #3651
Copy link
Copy link
Closed
Labels
Area-Extension TerminalBug: Pre-releaseBugs reproducing only in the pre-release extension.Bugs reproducing only in the pre-release extension.Issue-BugA bug to squash.A bug to squash.Resolution-FixedWill close automatically.Will close automatically.
Milestone
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
Write-Host -NoNewline -BackgroundColor Red -Object 'Test'
Write-Host -NoNewline -BackgroundColor Blue -Object 'Test 1'
Write-Host -NoNewline -BackgroundColor DarkGray -Object 'Test 2'Write-Color -Text 'Test1 ', 'Test2 ','Test3' -Color Red, Blue, DarkGrayPowerShell 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.1Visual Studio Code Version
1.61.2
6cba118ac49a1b88332f312a8f67186f7f3c1643
x64Extension 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.5Steps 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-Extension TerminalBug: Pre-releaseBugs reproducing only in the pre-release extension.Bugs reproducing only in the pre-release extension.Issue-BugA bug to squash.A bug to squash.Resolution-FixedWill close automatically.Will close automatically.
Type
Projects
- StatusShow more project fieldsDone


Activity
andyleejordan commentedon Oct 29, 2021
Well now this one is weird!
fflaten commentedon Oct 30, 2021
I see this with Pester too. Formatting using NoNewLine, ForegroundColor and BackgroundColor with
Write-Hostdoesn't work, so output is broken.ANSI and
[System.Console]::ForegroundColor + WriteLineseems to work finefflaten commentedon 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-Hostin 5+ uses) is being redirected.andyleejordan commentedon Nov 3, 2021
I think the color problem is likely due to PowerShell/PowerShellEditorServices#1607
SeeminglyScience commentedon 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 commentedon Nov 5, 2021
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 theWrite(ConsoleColor...-equivalent.SeeminglyScience commentedon Nov 5, 2021
You'd want to open an issue on PowerShell/PowerShell for that, we don't control that particular API surface.Nvm failed at reading1 remaining item
SeeminglyScience commentedon Nov 5, 2021
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
ConsoleHostdoes override it so might as well.andyleejordan commentedon Nov 5, 2021
Interesting...I wonder why we didn't manage to get this as fleshed out.
SeeminglyScience commentedon Nov 5, 2021
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 commentedon Nov 5, 2021
Ohh, I see! Thanks Patrick.
andyleejordan commentedon Jan 13, 2022
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
_consoleHostUIthat perhaps comes into play?andyleejordan commentedon Jan 18, 2022
Fix for this has been merged!
[-]Write-Host -NoNewLine not respected in newest preview[/-][+]`Write-Host -NoNewLine` not respected[/+]