Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up and down arrow keys do not work on Linux or Mac due to Dotnet.core bug. #11

Closed
mark-hubers opened this issue May 23, 2022 · 3 comments

Comments

@mark-hubers
Copy link

mark-hubers commented May 23, 2022

I looked into this and made a fixed on my local system and I was going to make a PR for it but this project is locked down I believed. So here what I did to make this great menu work on Linux and Mac so one can use the up and down arrow vs crashing out of the menu.

In file: PSMenu/Private/Read-VKey.ps1 I added the following:

    try {
        return $CurrentHost.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    }

to

     try {
        if ($IsLinux -or $IsMacOS) {
            ## A bug with Linux and Mac where arrow keys are return in 2 chars.  First is esc follow by A,B,C,D
            $key1 = $CurrentHost.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
            
            if ($key1.VirtualKeyCode -eq 0x1B) {
            ## Found that we got an esc chair so we need to grab one more char
            $key2 = $CurrentHost.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

                ## We just care about up and down arrow mapping here for now.
                if ($key2.VirtualKeyCode -eq 0x41) {
                    # VK_UP = 0x26 up-arrow
                    $key1.VirtualKeyCode = 0x26
                }
                if ($key2.VirtualKeyCode -eq 0x42) {
                    # VK_DOWN = 0x28 down-arrow
                    $key1.VirtualKeyCode = 0x28
                }
            }
            Return $key1
        } else {
            return $CurrentHost.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
        }
    }

Hope this helps.

@mark-hubers mark-hubers changed the title Up and down arrow keys do not work on Linux or Mac due to C# bug. Up and down arrow keys do not work on Linux or Mac due to Dotnet.core bug. May 23, 2022
@Sebazzz
Copy link
Owner

Sebazzz commented May 23, 2022

Thank you. I don't think the project is locked down, but I did just make a few commits so you might run into a merge conflict.

You mention there is a .NET bug - is it tracked upstream, and if so, under which number?

@mark-hubers
Copy link
Author

It is a hard problem to point out but here are some refs:
PowerShell/PowerShell#16443
dotnet/runtime#63387
PowerShell/PowerShell#16606

@Sebazzz
Copy link
Owner

Sebazzz commented May 25, 2022

Thanks, released as v0.1.8!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants