When dealing with VT terminals I need to be able to Read-Host from the terminal input, without waiting for {Enter}, and on Windows, we use $Host.UI.RawUI.ReadKey("NoEcho") for that, but it's failing elsewhere.
Steps to reproduce
On Windows, the following allows me to read responses from the terminal (without having them show up):
function Read-Terminal {
[CmdletBinding()]
param([string]$EscSequence)
$Host.UI.Write($EscSequence)
-join $(while ($Host.UI.RawUI.KeyAvailable) {
$Host.UI.RawUi.ReadKey("NoEcho,IncludeKeyDown").Character
})
}
So for instance, the CSI code 6n causes the terminal to report the cursor location, and we can read our X, Y from the terminal like this:
$answer = Read-Terminal "`e[6n"
"Row {0}, Column {1}" -f @($answer -split ';' -replace '\D')
Will get something like:
Actual behavior
But when I try to run the same code on linux (even in the WSL terminal) the $Host.UI.RawUI seems to echo no matter what I do, so the terminal's response is completely unsuppressable.
PS /root> cls; $answer = Read-Terminal "`e[6n"
^[[1;1R
I would be remiss not to point out that in addition to this being unreadable, the escape sequence is being shown as ^[ instead of the expected `e
Environment data
Name Value
---- -----
PSVersion 6.2.2
PSEdition Core
GitCommitId 6.2.2
OS Linux 4.4.0-18362-Microsoft #1-Microsoft Mon Mar 18 12:02:00 PST 2019
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
When dealing with VT terminals I need to be able to Read-Host from the terminal input, without waiting for {Enter}, and on Windows, we use
$Host.UI.RawUI.ReadKey("NoEcho")for that, but it's failing elsewhere.Steps to reproduce
On Windows, the following allows me to read responses from the terminal (without having them show up):
So for instance, the CSI code 6n causes the terminal to report the cursor location, and we can read our X, Y from the terminal like this:
Will get something like:
Actual behavior
But when I try to run the same code on linux (even in the WSL terminal) the
$Host.UI.RawUIseems to echo no matter what I do, so the terminal's response is completely unsuppressable.I would be remiss not to point out that in addition to this being unreadable, the escape sequence is being shown as ^[ instead of the expected `e
Environment data