Windows console colors do not work from a command over ssh.
"OpenSSH for Windows" version 8.0.0.0
Server OperatingSystem Windows 10 Pro
Client OperatingSystem Windows 10 Pro
What is failing Commands that produce console color output executed as a command, for example:
ssh localhost 'write-host TEST -foregroundcolor magenta'
Commands that just use an ANSI code work fine, for example:
ssh localhost 'write "`e[95mTEST`e[0m"'
works fine.
Expected output
The word TEST in magenta color.
Actual output
The word TEST in normal color.
I have PowerShell core set as the default shell, here is the output of $PSVersionTable:
Name Value
---- -----
PSVersion 7.2.0
PSEdition Core
GitCommitId 7.2.0
OS Microsoft Windows 10.0.22518
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Have you tried option -t as in
ssh -t localhost 'write-host TEST -foregroundcolor magenta'
to allocate a ConPTY and thus enable ConsoleAPI attribute translation into VT100/ANSI codes.
I forgot about this and didn't think of that, unfortunately, that does not work.
The command:
ssh -t localhost 'write-host TEST -foregroundcolor magenta'
starts a regular login session instead of running a command.
Even if this worked, it would be nice if it wasn't necessary, as Win32 console colors are output very commonly from Windows programs, for example commands like:
choco upgrade -y all
.
On Linux -t would be necessary for full terminal handling to e.g. attach to tmux or run an editor, but for just outputting colors it would be reasonable to expect this to not be needed, regardless of the underlying implementation.