magmax / python-readchar

Python library to read characters and key strokes
MIT License
143 stars 43 forks source link

allow for configuration of what raises a `KeyboardInterrupt` #90

Closed Cube707 closed 2 years ago

Cube707 commented 2 years ago

this PR intereduces a config submodle. It allows for central managment of configurations and also for the user to change these as needed.

For now this module only containes INTERRUPT_KEYS, a list of keys that result in readchar() raising a KeyboardInterrupt. It defaults to key.CTRL_C

Testing implementation:

Warning only works with the list methodes!! using config.INTERRUPT_KEYS = [] will not work

changed so that config is a class with class-attributes, this makes it much easier to interact with. Now both of these work, making it much easyer for the user:

# now works:
config.INTERRUPT_KEYS = ["q"]
# still works:
config.INTERRUPT_KEYS.clear()
config.INTERRUPT_KEYS.append("q")
coveralls commented 2 years ago

Coverage Status

Coverage increased (+0.3%) to 94.737% when pulling d3f69913f277ac6d0c6c51424c48fb5fa33afbc1 on config-interrupt-keys into b7d554ce08e5352585917c75c62586606712db07 on master.