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

Add support for more keys #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/pick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ class Option:
value: Any


GITBASH_KEY_UP = 450
GITBASH_KEY_DOWN = 456
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is gitbash?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an Windows application that provides an emulation layer for a Git command line experience in a familiar bash interface.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of hard-code these special codes here, it would be better to have a method for users to config them

Copy link
Contributor

@Henri-ColibrITD Henri-ColibrITD May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to fork pick to have the ability to exit!
This would combine nicely with the ability to set custom keys (so pick doesn't have to have custom keys for gitbash, or VS code as I saw in another issue).
I could work on this if the author of this PR is not interested to work on it anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after thinking a bit about it (and this may be already clear for the maintainers), custom key bindings are already supported by the ability to set them at the module level. For instance to support the numpad to navigate, one might simply do

import pick
pick.KEYS_UP += (ord("8"),)
pick.KEYS_DOWN += (ord("2"),)
KEY_NUMPAD_ENTER = 459
pick.KEYS_ENTER += (KEY_NUMPAD_ENTER,)

Because of this, I will only tackle the exit option, to reduce the scope of my PR

KEY_ESCAPE = 27
KEYS_ENTER = (curses.KEY_ENTER, ord("\n"), ord("\r"))
KEYS_UP = (curses.KEY_UP, ord("k"))
KEYS_DOWN = (curses.KEY_DOWN, ord("j"))
KEYS_UP = (curses.KEY_UP, ord("k"), GITBASH_KEY_UP)
KEYS_DOWN = (curses.KEY_DOWN, ord("j"), GITBASH_KEY_DOWN)
KEYS_SELECT = (curses.KEY_RIGHT, ord(" "))
KEYS_QUIT = (ord("q"), KEY_ESCAPE)


SYMBOL_CIRCLE_FILLED = "(x)"
SYMBOL_CIRCLE_EMPTY = "( )"
Expand Down Expand Up @@ -137,7 +142,9 @@ def run_loop(self, screen) -> Union[List[PICK_RETURN_T], PICK_RETURN_T]:
while True:
self.draw(screen)
c = screen.getch()
if c in KEYS_UP:
if c in KEYS_QUIT:
return None, None
elif c in KEYS_UP:
self.move_up()
elif c in KEYS_DOWN:
self.move_down()
Expand Down