1.4.1 - unclutter backspace

This commit is contained in:
doman 2022-02-10 16:45:10 +01:00
parent 21eef90307
commit 9254692511
5 changed files with 25 additions and 7 deletions

View file

@ -37,6 +37,10 @@ You can use another similar projects set of words as well, for example to create
To exit you can either finish test, use `KeyboardInterrupt` (CTRL+C) or tap **tab** then **enter**. After you finish test, there will be summary printed, use enter to exit from it.
# When backspace does wierd shiet
Some terminal emulators send different values for key presses of backspace and ctrl+backspace. To fix it, simply add `b` flag to `python3 -m fasttyper`.
## Example scripts
```sh

View file

@ -19,7 +19,7 @@ import argparse
import json
def initialize(configmap, rbuffer):
def initialize(configmap, rbuffer, backspace_debug):
config = Config(configmap)
reference_buffer = Buffer(rbuffer)
@ -32,7 +32,7 @@ def initialize(configmap, rbuffer):
reference_text = ReferenceText(config, text_box)
stats_component = StatsComponent(config)
listener = Listener()
listener = Listener(backspace_debug)
application = Application(listener, user_buffer, reference_buffer, config)
interface = Interface(
@ -67,6 +67,13 @@ def main():
help="configuration file",
default="~/.config/fasttyper/config.json",
)
parser.add_argument(
"--unclutter-backspace",
"-b",
action="store_true",
help="unclutter backspace, when it raises ctrl+backspace instead",
default=False,
)
args = parser.parse_args()
if is_tty:
@ -86,7 +93,7 @@ def main():
except FileNotFoundError:
configmap = {}
initialize(configmap, rbuffer)
initialize(configmap, rbuffer, args.unclutter_backspace)
if __name__ == "__main__":

View file

@ -12,8 +12,9 @@ class Action(enum.Enum):
class Listener:
def __init__(self):
def __init__(self, backspace_debug=False):
self.tabbed = False
self.backspace_debug = backspace_debug
def handle_key(self, key):
action = Action.invalid
@ -22,12 +23,18 @@ class Listener:
self.tabbed = True
elif key == "\n" and self.tabbed:
raise StoppingSignal(silent=True)
elif self.backspace_debug and key == chr(8):
action = Action.del_word
self.tabbed = False
elif key == 263 and self.backspace_debug:
action = Action.del_char
self.tabbed = False
elif key == 263:
action = Action.del_word
self.tabbed = False
elif isinstance(key, int):
self.tabbed = False
elif key == chr(127):
elif key in chr(127):
action = Action.del_char
self.tabbed = False
elif key == " ":

View file

@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.4.0
current_version = 1.4.1
[wheel]
universal = 1

View file

@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setup(
name="fasttyper",
version="1.4.0",
version="1.4.1",
author="Piotr Domanski",
author_email="pi.domanski@gmail.com",
description="Minimalistic typing exercise",