ronisbr / TerminalPager.jl

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

Support Option key on macOS #2

Closed carstenbauer closed 3 years ago

carstenbauer commented 3 years ago

Great package!

The help says that ALT + →/← can be used to jump to the last/first column. Would be great if the macOS pendant (OPTION key) was also supported, since there is no ALT key on macOS.

ronisbr commented 3 years ago

Hi @crstnbr ,

I called ALT just out of habit. I am using macOS and the OPTION key seems to be working here (iTerm2). Are you having problem with this? I can add a verification to change the help if the system is a macOS to show OPTION instead of ALT.

George9000 commented 3 years ago

On macOS 10.15.7, using iTerm2 the keys all work as described. Using the standard Terminal app in macOS, the Shift-arrow combinations work. The Alt/Option-arrows do not. Neither do the PgUp/Down or the Home/End: these all manipulate the Terminal screen itself, that is, the entire scrollback history not the pager in Julia. I tried with the profile/Keyboard setting in Terminal for 'Use Option as Meta key' checked and unchecked: no difference.

So this seems to be a difference in the keycodes that iTerm2 and Terminal are sending.

All that said, this gave me a chance to try out iTerm2, which is delightful.

carstenbauer commented 3 years ago

Are you having problem with this?

Yes, I'm on macOS 11.2.3 (not sure if this matters), iTerm2 3.4.5, Julia 1.6 and Option + Arrow Key doesn't work for me. (It also doesn't work in the regular Terminal app.

ronisbr commented 3 years ago

Thanks @George9000 , I can reproduce this exactly behavior.

Are you having problem with this?

Yes, I'm on macOS 11.2.3 (not sure if this matters), iTerm2 3.4.5, Julia 1.6 and Option + Arrow Key doesn't work for me. (It also doesn't work in the regular Terminal app.

I see, I think we will have a lot of similar problems. I am treating the key codes right, the problem is that some terminals does not pass those key codes to the software. For example, Terminal.app instead of passing Page Up to Julia, it moves the screen up. less solves this by some way I did not figure out yet. Any suggestions?

ronisbr commented 3 years ago

I just pushed a WIP keybinding system. I think it is better for now to let the user decide it since I cannot design one that will work in all cases, can you please test?

julia> using TerminalPager

julia> TerminalPager.set_keybinding('h', :left)

julia> TerminalPager.set_keybinding('H', :fastleft)

julia> TerminalPager.set_keybinding('j', :down)

julia> TerminalPager.set_keybinding('J', :fastdown)

julia> TerminalPager.set_keybinding('k', :up)

julia> TerminalPager.set_keybinding('K', :fastup)

julia> TerminalPager.set_keybinding('l', :right)

julia> TerminalPager.set_keybinding('L', :fastright)

julia> rand(100,100) |> pager

And know you have somewhat Vim movement keys (with faster movement if SHIFT is pressed).

George9000 commented 3 years ago

Thanks. I ran all of the above and added the following:

julia> TerminalPager.set_keybinding('G', :end)

julia> TerminalPager.set_keybinding('g', :home)

julia> TerminalPager.set_keybinding('^', :bol)

julia> TerminalPager.set_keybinding('$', :eol)

I could not use gg as in vim since only a single character is allowed in the keybinding.

The vim movement keys work in both macOS 10.15.7 with Terminal (2.10) and iTerm2 (3.4.5).

ronisbr commented 3 years ago

Nice! Thanks for feedback. Supporting key sequences for an action would complicate a lot the logic. I think we need to keep this package as simple as possible so that others can use without much penalty in loading time.

carstenbauer commented 3 years ago

I did

julia> TerminalPager.set_keybinding(:up, alt = true, :home)

julia> TerminalPager.set_keybinding(:down, alt = true, :end)

julia> TerminalPager.set_keybinding(:up, ctrl = true, :fastup)

julia> TerminalPager.set_keybinding(:down, ctrl = true, :fastdown)

and everything is working as expected, nice!

ronisbr commented 3 years ago

Ok, so I will close for now since we have an option to adjust if the default ones are not working.