-
Notifications
You must be signed in to change notification settings - Fork 12
Write-Host: remote sessions support #6
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
base: master
Are you sure you want to change the base?
Conversation
@beatcracker : I updated following the suggestion you made in #5. |
@@ -71,11 +70,14 @@ function Write-Host { | |||
$item = $AnsiTemplate -f $AnsiColor[$ForegroundColor.value__], $item, 39 | |||
} | |||
|
|||
[System.Console]::$Method($item) | |||
if ($Host.Name -eq "ServerRemoteHost") { | |||
if ($NoNewLine) { Microsoft.PowerShell.Utility\Write-Host -NoNewLine $item } else { Microsoft.PowerShell.Utility\Write-Host $item } |
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.
Looks great! Can be simplified even further by dropping if
like this:
Microsoft.PowerShell.Utility\Write-Host -NoNewLine:$NoNewLine -Object $item
@@ -71,11 +70,14 @@ function Write-Host { | |||
$item = $AnsiTemplate -f $AnsiColor[$ForegroundColor.value__], $item, 39 | |||
} | |||
|
|||
[System.Console]::$Method($item) | |||
if ($Host.Name -eq "ServerRemoteHost") { |
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.
Suggested comment to add:
# [console]:write* doesn't work in remote sessions
# https://github.com/PowerShell/PowerShell/issues/20054
# https://github.com/beatcracker/Powershell-Misc/issues/5
@@ -57,8 +57,7 @@ function Write-Host { | |||
Process { | |||
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters#escape-e | |||
# https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf/whats-new/console-improvements#vt100-support | |||
if ($Host.UI.SupportsVirtualTerminal) { | |||
$Method = if ($NoNewline) { 'Write' } else { 'WriteLine' } | |||
if ($Host.UI.SupportsVirtualTerminal -or $Host.Name -eq "ServerRemoteHost") { |
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 suggest to use single quotes here, since we're not doing variable expansion:
$Host.Name -eq 'ServerRemoteHost'
As mentioned in #5, using
System.Console.Write(Line)
functions doesn't work from inside remote sessions. Using the baseWrite-Host
here is just simpler and should work in all situations.