bchao1 / bullet

🚅 Interactive prompts made simple. Build a prompt like stacking blocks.
https://pypi.org/project/bullet/
MIT License
3.55k stars 113 forks source link

ESC_KEY doesn't trigger on macOS Mojave #52

Open antoinedelia opened 4 years ago

antoinedelia commented 4 years ago

Hey,

I tried implementing a keyboard event as seen in the check.py example.

I have something rather simple:

from bullet import Bullet, keyhandler
from bullet.charDef import ESC_KEY

class EscapeBullet(Bullet):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    @keyhandler.register(ESC_KEY)
    def accept(self):
        print('yes')
        raise Exception

But upon pressing ESC, the code doesn't do anything. If I try to change ESC_KEY with BACK_SPACE_KEY, then the code is working as intended.

Do you know what could be the issue regarding this?

Thanks a lot.

rcfox commented 4 years ago

Looks like getchar() might be preventing the return of ESC_KEY. https://github.com/Mckinsey666/bullet/blob/master/bullet/utils.py#L35

antoinedelia commented 4 years ago

Even when tweaking the code to force the return of the ESC_KEY, it looks like the getchar() function only triggers half of the time when using ESC_KEY. For other inputs, it works fine all the time.