Skip to content

[System.Console]::ReadKey() returns escape sequence characters when pressing arrow keys in PowerShell on Linux #75305

Closed

Description

@daxian-dbw

Description

This is with PowerShell 7.3.0-preview.7, which runs on top of .NET 7-preview.7.

Running [System.Console]::ReadKey() in PowerShell, and then press UpArrow, it returns the escape sequences character by character -- Escape and then A.
It's the same to other arrow keys: DownArrow, LeftArrow, RightArrow

However, when using Console.ReadKey in an EXE built against .NET 7-preview.7, it returns UpArrow (and other arraow keys) as expected. Any ideas about what may cause this difference?

Related PowerShell issue: PowerShell/PowerShell#16443

Reproduction Steps

  1. Run PowerShell 7.3.0-preview.3, which runs on top of .NET 7-preview.7.
  2. Run [System.Console]::ReadKey()
  3. Press UpArrow

Expected behavior

[System.Console]::ReadKey() returns a ConsoleKeyInfo with those values: KeyChar: 0, Key: UpArrow, Modifier: 0

Actual behavior

[System.Console]::ReadKey() returns a ConsoleKeyInfo with the Escape key, and then a second ReadKey returns A

image

However, when using Console.ReadKey from an EXE that's built against .NET 7-preview.7, it works as expected:

image

Regression?

Not as far as I know. I observe the same behavior in .NET 6.

Known Workarounds

No response

Configuration

Which version of .NET is the code running on?
.NET 7-preview.7

What OS and version, and what distro if applicable?
Ubuntu 18.04

What is the architecture (x64, x86, ARM, ARM64)?
x64

Other information

No response

Activity

  1. ghost added
    untriaged
    on Sep 8, 2022
  2. daxian-dbw commented on Sep 8, 2022

    @daxian-dbw
    ContributorAuthor

    Is this also addressed by f1de614?

  3. adamsitnik commented on Sep 9, 2022

    @adamsitnik
    Member

    Any ideas about what may cause this difference?

    Is there any chance PowerShell could set TERM env variable?

    Is this also addressed by f1de614?

    I am not 100% sure as I don't know what caused the difference in first place. Could you please test it with RC1?

  4. added this to the 8.0.0 milestone on Sep 9, 2022
  5. ghost removed
    untriaged
    on Sep 9, 2022
  6. daxian-dbw commented on Sep 9, 2022

    @daxian-dbw
    ContributorAuthor

    PowerShell doesn't set TERM env variable, it just derives that env variable:

    PS:6> $env:TERM
    xterm-256color
    

    The PSReadLine module running in PowerShell depends on Console.ReadKey and it works as expected, however, running [Console]::ReadKey directly in PowerShell console doesn't. This is really puzzling and any help is much appreciated.

  7. adamsitnik commented on Sep 15, 2022

    @adamsitnik
    Member

    @daxian-dbw RC1 was shipped yesterday, could you please check if it works as expected now?

  8. daxian-dbw commented on Sep 15, 2022

    @daxian-dbw
    ContributorAuthor

    Thanks @adamsitnik, we are preparing a release targeting RC1. Will verify this soon.

  9. daxian-dbw commented on Sep 15, 2022

    @daxian-dbw
    ContributorAuthor

    This is fixed with the .NET 7-RC1 release ❤️ Thanks @adamsitnik!
    But I'm still curious about why it only doesn't work when running in PowerShell directly for the previous .NET versions ... what a mystery 😵‍💫

    image

  10. adamsitnik commented on Sep 16, 2022

    @adamsitnik
    Member

    But I'm still curious about why it only doesn't work when running in PowerShell directly for the previous .NET versions ... what a mystery

    Based on #75289 (comment) it looks that I'll have to solve this mystery anyway ;)

  11. adamsitnik commented on Sep 16, 2022

    @adamsitnik
    Member

    @daxian-dbw thanks for testing it and letting me know!

  12. ghost locked as resolved and limited conversation to collaborators on Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions