Skip to content

PowerShell 7.2.0 - arrow navigation does not work on Linux, outputs letters on arrow key presses #16606

Closed

Description

@blochl

Prerequisites

Steps to reproduce

  1. Install PowerShell 7.2.0 from the package here: https://github.com/PowerShell/PowerShell/releases/download/v7.2.0/powershell_7.2.0-1.deb_amd64.deb .
  2. Start it (pwsh).
  3. Try to go up in history (arrow up), or going left/right in a text line (left/right arrows).

Expected behavior

Arrow keys up/down go up/down the history, arrow keys left/right navigate within the text line.

Actual behavior

PS /home> OAOAOAOAOAOAOAODODODOCOCOCOCOCOC

...Appears when the arrow keys are pressed.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.0
PSEdition                      Core
GitCommitId                    7.2.0
OS                             Linux 5.15.7-arch1-1 #1 SMP PREEMPT Wed, 08 Dec…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Dec 13, 2021
  2. iSazonov commented on Dec 13, 2021

    @iSazonov
    Collaborator

    blochl Please install latest PSReadline version and check again. https://github.com/PowerShell/PSReadLine/releases/tag/v2.2.0-beta4

    GitHub
    2.2.0-beta4 - 2021-10-27 You can get the v2.2.0-beta4 version of the PSReadLine module from PowerShell Gallery. This release includes the following changes:

    [Low-risk Breaking Change] Generate OnI...

  3. added
    Issue-Question
    on Dec 13, 2021
  4. 237dmitry commented on Dec 13, 2021

    @237dmitry

    This may be individual linux setting or settings of PSReadline module. What outputs:

    Get-PSReadLineKeyHandler | Where { $_.key -like '*Arrow' }
    

    And one more question -- what linux distribution do you use? I am using Arco Linux (arch-based) and always install or update Powershell from tar package.

  5. added
    Waiting on Author
    on Dec 13, 2021
  6. blochl commented on Dec 13, 2021

    @blochl
    Author

    This may be individual linux setting or settings of PSReadline module. What outputs:

    Get-PSReadLineKeyHandler | Where { $_.key -like '*Arrow' }
    

    And one more question -- what linux distribution do you use? I am using Arco Linux (arch-based) and always install or update Powershell from tar package.

    > Get-PSReadLineKeyHandler | Where { $_.key -like '*Arrow' }
    
    Cursor movement functions
    =========================
    
    Key        Function     Description
    ---        --------     -----------
    LeftArrow  BackwardChar Move the cursor back one character
    RightArrow ForwardChar  Move the cursor forward one character
    
    History functions
    =================
    
    Key       Function        Description
    ---       --------        -----------
    DownArrow NextHistory     Replace the input with the next item in the history
    UpArrow   PreviousHistory Replace the input with the previous item in the history
    
    Selection functions
    ===================
    
    Key              Function           Description
    ---              --------           -----------
    Shift+LeftArrow  SelectBackwardChar Adjust the current selection to include the previous character
    Shift+RightArrow SelectForwardChar  Adjust the current selection to include the next character

    I'm using Arch Linux.

  7. daxian-dbw commented on Dec 13, 2021

    @daxian-dbw
    Member

    According to the answer in https://vi.stackexchange.com/a/15328:

    When you press Up, the terminal sends the sequence:

    • (if it's in normal mode) CSI A, where CSI means Control Sequence Introducer and is produced by ESC [; in caret notation, the >whole sequence is displayed as ^[[A
    • (if it's in application mode) SS3 A, where SS3 is described as Single Shift Select of G3 Character Set here, and is produced by ESC O; in caret notation, the whole sequence is displayed as ^[OA

    So, it looks your terminal is in application mode for some reason.

  8. blochl commented on Dec 13, 2021

    @blochl
    Author

    blochl Please install latest PSReadline version and check again. https://github.com/PowerShell/PSReadLine/releases/tag/v2.2.0-beta4

    I never needed to install PSReadline explicitly until now, and up to v7.1.5 everything worked fine. I think that I have the latest installed though, as Install-Module PSReadline returns immediately and without error.

    GitHub
    2.2.0-beta4 - 2021-10-27 You can get the v2.2.0-beta4 version of the PSReadLine module from PowerShell Gallery. This release includes the following changes:

    [Low-risk Breaking Change] Generate OnI...

  9. added
    WG-Interactive-Console
    and removed
    Waiting on Author
    on Dec 13, 2021
  10. blochl commented on Dec 13, 2021

    @blochl
    Author

    According to the answer in https://vi.stackexchange.com/a/15328:

    When you press Up, the terminal sends the sequence:

    • (if it's in normal mode) CSI A, where CSI means Control Sequence Introducer and is produced by ESC [; in caret notation, the >whole sequence is displayed as ^[[A
    • (if it's in application mode) SS3 A, where SS3 is described as Single Shift Select of G3 Character Set here, and is produced by ESC O; in caret notation, the whole sequence is displayed as ^[OA

    So, it looks your terminal is in application mode for some reason.

    In the same terminal:

    $ # Install PowerShell 7.1.5
    $ sudo pacman -U ~/AUR/powershell-bin/powershell-bin-7.1.5-1-x86_64.pkg.tar.zst
    ...
    $ pwsh
    PowerShell 7.1.5
    Copyright (c) Microsoft Corporation.
    
    https://aka.ms/powershell
    Type 'help' to get help.
    
       A new PowerShell stable release is available: v7.2.0 
       Upgrade now, or check out the release page at:       
         https://aka.ms/PowerShell-Release?tag=v7.2.0       
    
    PS /home> # Arrows work...
    PS /home> exit
    $ # Install PowerShell 7.2.0
    $ sudo pacman -U ~/AUR/powershell-bin/powershell-bin-7.2.0-1-x86_64.pkg.tar.zst
    ...
    $ pwsh
    PowerShell 7.2.0
    Copyright (c) Microsoft Corporation.
    
    https://aka.ms/powershell
    Type 'help' to get help.
    
    PS /home> OAODOCODOAODOCODOCOAODOCOAOD
    PS /home> # Arrows don't work...
    
    Vi and Vim Stack Exchange
    If I run cat under terminal (xterm-256color), and then press the up arrow button, I see ^[[A as output.

    But if I press <ctrl-v> <up> in vim insert mode, I see ^[OA as output.

    So i won...

  11. daxian-dbw commented on Dec 13, 2021

    @daxian-dbw
    Member

    Interesting, PS 7.1.5 and PS 7.2 both ship the 2.1.0 version of PSReadLine module, so it's not because of the PSReadLine module.
    PS 7.1.5 uses .NET 5 while PS 7.2 uses .NET 6. I suspect something is changed in Console.ReadKey. Can you please try [System.Console]::ReadKey($true) and press UpArrow in both PS 7.1.5 and PS 7.2 and share the results here?

  12. iSazonov commented on Dec 13, 2021

    @iSazonov
    Collaborator

    I see only one change dotnet/runtime#42432

  13. 237dmitry commented on Dec 13, 2021

    @237dmitry

    In my environment there are not problems. As I said I installed PowerShell just unpacking powershell-7.2.0-linux-x64.tar.gz to /opt/microsoft/powershell/7/ and created symbolic link from /opt/microsoft/powershell/7/pwsh to /usr/bin/pwsh.

    pushd /usr/bin
    sudo ln -s /opt/microsoft/powershell/7/pwsh
    popd 
    

    I think you have to try other terminal emulator. I am using Tilix.

  14. blochl commented on Dec 13, 2021

    @blochl
    Author

    Interesting, PS 7.1.5 and PS 7.2 both ship the 2.1.0 version of PSReadLine module, so it's not because of the PSReadLine module. PS 7.1.5 uses .NET 5 while PS 7.2 uses .NET 6. I suspect something is changed in Console.ReadKey. Can you please try [System.Console]::ReadKey($true) and press UpArrow in both PS 7.1.5 and PS 7.2 and share the results here?

    $ pwsh
    PowerShell 7.2.0
    Copyright (c) Microsoft Corporation.
    
    https://aka.ms/powershell
    Type 'help' to get help.
    
    PS /home> [System.Console]::ReadKey($true)
    
    KeyChar     Key Modifiers
    -------     --- ---------
           UpArrow         0
    
    PS /home> exit
    $ sudo pacman -U ~/AUR/powershell-bin/powershell-bin-7.1.5-1-x86_64.pkg.tar.zst
    ...
    $ pwsh
    PowerShell 7.1.5
    Copyright (c) Microsoft Corporation.
    
    https://aka.ms/powershell
    Type 'help' to get help.
    
       A new PowerShell stable release is available: v7.2.0 
       Upgrade now, or check out the release page at:       
         https://aka.ms/PowerShell-Release?tag=v7.2.0       
    
    PS /home> [System.Console]::ReadKey($true)
    
    KeyChar     Key Modifiers
    -------     --- ---------
           UpArrow         0
    
    PS /home> exit
    
  15. daxian-dbw commented on Dec 16, 2021

    @daxian-dbw
    Member

    So, it looks your terminal is in application mode for some reason.

    Actually, .NET requires application mode to support Arrow key escape sequences. So being in application mode is expected.
    Run out of clues at this point ... Can you try the PS 7.2.1 that was released yesterday? It's on top of .NET 6.0.1.

  16. blochl commented on Dec 16, 2021

    @blochl
    Author
  17. chaplina commented on Dec 18, 2021

    @chaplina

    I was having this same issue. I ssh to the Oracle Enterprise Linux 7 host from my PC using urxvt and the TERM is set to rxvt.

    I decided to export TERM=xterm and run pwsh and the command recall using arrow keys started to work again.

    Since this was working fine pre 7.2 I'd consider this a bug. :)

  18. blochl commented on Dec 20, 2021

    @blochl
    Author

    Indeed! Just as chaplina said!
    I use the rxvt-unicode terminal as my main terminal, and it worked fine with PS 7.1.x. Now, with 7.2.x, I must run TERM=xterm-256color pwsh for the arrows to work.

    Thanks, chaplina , for the workaround.

    And it does look like a bug / regression.

  19. B-Art commented on Dec 21, 2021

    @B-Art

    Problem is the same when using bastion logon to VM running and then start pwsh (7.2.1).
    TERM=xterm-256color pwsh Works.
    Possibly something to do with Ascii colorcoding from Get-PSReadLineOption?

  20. daxian-dbw commented on Jan 3, 2022

    @daxian-dbw
    Member

    7.1.x ships with 2.1.0 version of PSReadLine, and 7.2.x ships the same version PSReadLine, so the issue you ran into should have nothing to do with PSReadLine. It's likely an issue rooted in .NET 6.

  21. daxian-dbw commented on Jan 5, 2022

    @daxian-dbw
    Member

    Opened the issue dotnet/runtime#63387 on dotnet/runtime.

  22. added
    Resolution-External
    and removed
    Needs-Triage
    on Jan 5, 2022
  23. ghost closed this as completedon Jan 6, 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

    Labels

    Issue-QuestionResolution-ExternalWG-Interactive-Console

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions