ronisbr / TerminalPager.jl

Pure Julia implementation of the command less
MIT License
116 stars 8 forks source link

Alt-left and Alt-right do not work #8

Closed bkamins closed 3 years ago

bkamins commented 3 years ago

On Polish keyboard under Linux Ubuntu Alt-left and Alt-right (:bol and :eol) do not work. Most likely because Alt-o is ó in Polish etc. but Alt-left and Alt-right are not getting a special treatment so it should work.

ronisbr commented 3 years ago

Hum, we had similar problem related before. It seems to be something related to the terminal that is "hijacking" the keystroke for some reason. I will create a debug feature to help me understanding those key codes.

ronisbr commented 3 years ago

Hi @bkamins

Using main, can you please run TerminalPager.debug_keycode() type ALT-[left,right] and tell me what appears?

bkamins commented 3 years ago
julia> using TerminalPager

julia> TerminalPager.debug_keycode()
Type any key to echo the processed keycode. Hit q to exit.

TerminalPager.Keystroke
  value: Symbol undefined
  alt: Bool true
  ctrl: Bool false
  shift: Bool false

TerminalPager.Keystroke
  value: Symbol undefined
  alt: Bool true
  ctrl: Bool false
  shift: Bool false
bkamins commented 3 years ago

I am pressing "left alt". For "right alt" it is:

julia> TerminalPager.debug_keycode()
Type any key to echo the processed keycode. Hit q to exit.

TerminalPager.Keystroke
  value: Symbol right
  alt: Bool false
  ctrl: Bool false
  shift: Bool false

TerminalPager.Keystroke
  value: Symbol left
  alt: Bool false
  ctrl: Bool false
  shift: Bool false

(and this is expected but just Alt is ignored here)

bkamins commented 3 years ago

I have checked two different terminals and this is the same.

bkamins commented 3 years ago

This is what I get in the terminal normally with showkey when pressing alt-left/right arrow:

~$ showkey -a

Press any keys - Ctrl-D will terminate this program

^[[1;3D      27 0033 0x1b
     91 0133 0x5b
     49 0061 0x31
     59 0073 0x3b
     51 0063 0x33
     68 0104 0x44
^[[1;3C      27 0033 0x1b
     91 0133 0x5b
     49 0061 0x31
     59 0073 0x3b
     51 0063 0x33
     67 0103 0x43
ronisbr commented 3 years ago

Thanks @bkamins ! I think I got it. Here ALT is Meta (9) and in your system is Alt (3). I will hardcode both to make it work in macOS and Linux.

ronisbr commented 3 years ago

I think it should be working now. Can you test again please?

bkamins commented 3 years ago

It works. A small suggestion (no need to implement it if you feel it is too much, but I see you are adding aliases):