Skip to content

Windows: $host.UI.RawUI.KeyAvailable has false positives. #959

Open
@mklement0

Description

@mklement0

Environment data

PS version: 7.0.0-preview.1
PSReadline version: 2.0.0-beta4
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 7.0.0.0
BufferWidth: 180
BufferHeight: 9999

Steps to reproduce or exception report

Note: The problem surfaces on Windows only.

Run the following code with and without PSReadLine imported:

# Show a spinner until the user presses a key.
$i=0; while (-not $host.UI.RawUI.KeyAvailable) { Write-Host -NoNewline ("`r{0}" -f '/―\|'[($i++ % 4)]); start-sleep -ms 200 }

Expected: A spinner should appear and keep spinning until the user presses a key.

Actual, with PSReadLine imported: The while loop is either never entered (1st invocation immediately after start of the PS session) or stops after one iteration even if no key is pressed (subsequent invocations).

Once you run Remove-Module PSReadLine, the behavior is as expected in regular console windows; interestingly, the problem persists in a Windows Terminal window.

For consoles / terminals only, using [Console]::KeyAvailable in lieu of $host.UI.RawUI.KeyAvailable is an effective workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-More InvestigationInitial investigation is done, but need to follow up.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions