From afe232dd598f3449787bb1a00912546d20ba8690 Mon Sep 17 00:00:00 2001 From: Doman Date: Fri, 18 Mar 2022 14:33:13 +0100 Subject: [PATCH] =?UTF-8?q?fix=20=C4=85=20character...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fasttyper/listener.py | 23 +++++++++++++++++------ setup.cfg | 2 +- setup.py | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/fasttyper/listener.py b/fasttyper/listener.py index 5cea91b..321fd79 100644 --- a/fasttyper/listener.py +++ b/fasttyper/listener.py @@ -20,6 +20,18 @@ class Listener: def __init__(self, backspace_debug=False): self.backspace_debug = not backspace_debug + def action_for_char(self, key): + if key == "\t": + raise StoppingSignal(silent=True) + + if ord(key) in (8, 127): + return self.action_for_key(ord(key)) + + if key in string.whitespace: + return Action.add_space + + return Action.add_char + def action_for_key(self, key): if (self.backspace_debug and key == 263) or ( not self.backspace_debug and key == 127 @@ -37,17 +49,16 @@ class Listener: if key in WHITE: return Action.add_space - return Action.add_char - def handle_key(self, key): action = Action.invalid if isinstance(key, str): - key = ord(key) + action = self.action_for_char(key) + else: + action = self.action_for_key(key) + key = chr(key) - action = self.action_for_key(key) - - return action, chr(key) + return action, key def listen(self, screen): try: diff --git a/setup.cfg b/setup.cfg index 8681f72..cb515df 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.2 +current_version = 2.0.3 [wheel] universal = 1 diff --git a/setup.py b/setup.py index 2de83b1..83b6a7f 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ with open("requirements.txt", "r", encoding="utf-8") as fh: setup( name="fasttyper", - version="2.0.2", + version="2.0.3", author="Piotr Domanski", author_email="pi.domanski@gmail.com", description="Minimalistic typing exercise",