Repository navigation
Direct Clear-Host output to terminal #10681
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use
Write-Hosthere instead? There may be cases where there isn't a console?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Steve Lee (@SteveL-MSFT): In principle,
$host.UI.Write()(orWrite-Host) is better than[Console]::Write(), but note that we're calling a terminal-specific utility anyway - see also: #10181 (comment)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ilya (@iSazonov) can you validate if this works remotely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Steve Lee (@SteveL-MSFT): No, it doesn't (see linked comment), but it also didn't work before. However, if we're willing to assume an
xtermterminal (which sounds like a safe bet), we can fix it as follows before callingclear:if (-not $env:TERM) { $env:TERM='xterm' }- probably better to reset the variable afterwards.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, we can defer the remote scenario since it doesn't work today (and I think there's a issue on that already). We can take this with the current change to address the specific problem of the VT codes emitted to the pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Steve Lee (@SteveL-MSFT): Couldn't find an issue relating to remoting specifically.
As it turns out, my suggested
$env:TERM='xterm'workaround for remoting only works with$host.UI.Write()(Write-Host -NoNewline), not with[console]::Write(), because the escape sequences must be sent to the caller's terminal.In light of that - if you don't want to incorporate the full workaround yet - it's better to switch to
$host.UI.Write().For the record, here's the complete workaround (from my personal notes):
To fix the remoting problem,
$env:TERMcan be set toxtermtemporarily, under the assumption that pretty much all terminals are Xterm-compatible these days - and that it is the caller that uses such a terminal, because the escape sequences must be printed to the caller's terminal:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the suggestion to switch to
$host.UI.Write(). Not so sure about the assumption that terminals are xterm compatible. The issue I was thinking about is #8606 where remoting was discussed but wasn't the focus.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will look
$host.UI.Write()today. I hope we could implement this step-by-step (first for local host. then remote one that would be more tricky)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the link, Steve Lee (@SteveL-MSFT), but resolving #8608 will not address the remoting problem; while there is a single comment - #8606 (comment) - that touches on the need to support non-console hosts, a separate issue should really be opened for that.
As for assuming
xterm: Anecdotally, I'd say it's a pretty safe bet, but the better solution would be to extend the$PSSenderInfoobject to include the caller's$env:TERMvalue, if any, and haveClear-Hostconsult that.