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

Cursor lost after KeyboardInterrupt #35

Closed jacebrowning closed 5 years ago

jacebrowning commented 5 years ago

I'm on macOS using iTerm/zsh and have tested with the latest commit: https://github.com/Mckinsey666/bullet/commit/eaf1fb7a2b82bb6a27416ef0b22f5884b8af17e0


If I break out of a Bullet list via ctrl+c, I see the following stack trace:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/Browning/.pyenv/versions/3.7.1/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File ".../scripts/controller.py", line 6, in <module>
    from framework import config, shared

  ...

  File ".../framework/data.py", line 30, in env
    value = getter()
  File ".../.venv/src/bullet/bullet/client.py", line 223, in launch
    ret = self.handle_input()
  File ".../.venv/src/bullet/bullet/keyhandler.py", line 41, in handle_input
    return handler(self)
  File ".../.venv/src/bullet/bullet/client.py", line 207, in interrupt
    raise KeyboardInterrupt
KeyboardInterrupt

And the terminal I am returned to no longer shows a cursor. Presumably bullet is not restoring the color scheme on KeyboardInterrupt?

rcfox commented 5 years ago

I can't make the change myself at the moment, but it seems like cursor.show_cursor() should be moved out of accept() and put into the finally block of a try/finally around the while loop in launch(). (Also, this applies to a few classes, don't just get the first one.)