diff --git a/README.md b/README.md index db21955..fcac1bd 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ You can use another similar projects set of words as well, for example to create `curl -s https://raw.githubusercontent.com/Miodec/monkeytype/master/static/languages/english.json | python3 -c "import sys, json; print('\n'.join(json.load(sys.stdin)['words']))" | shuf -n20 | python3 -m fasttyper` -To exit you can either finish test, use `KeyboardInterrupt` (CTRL+C) or tap **tab** then **enter**. +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. ## Example scripts diff --git a/fasttyper/__main__.py b/fasttyper/__main__.py index 81ecc8d..b46aa41 100644 --- a/fasttyper/__main__.py +++ b/fasttyper/__main__.py @@ -40,6 +40,7 @@ def initialize(configmap, rbuffer): wrapper(interface) application.summarize() + application.exit() def main(): diff --git a/fasttyper/application.py b/fasttyper/application.py index 10df1ec..e90a991 100644 --- a/fasttyper/application.py +++ b/fasttyper/application.py @@ -1,9 +1,14 @@ +import sys + + class Application: def __init__(self, listener, user_buffer, reference_buffer, config): self.listener = listener self.user_buffer = user_buffer self.reference_buffer = reference_buffer self.config = config + self.finished = False + self.silent_exit = False from .state import StateMachine @@ -38,14 +43,26 @@ class Application: self.user_buffer.handle_action(action, key) self.state.update(action, key) self.stats.update(action, self.state.valid(), self.state.running()) - except StoppingSignal: + except StoppingSignal as e: self.state.signal_stop() self.stats.signal_stop() + if e.silent: + self.silent_exit = True def summarize(self): - self.stats.summarize(self.config.get("summary_template")) - self.stats.export_to_datafile(self.config.get("summary_datafile")) + if self.finished: + self.stats.summarize(self.config.get("summary_template")) + self.stats.export_to_datafile(self.config.get("summary_datafile")) + input() + + def exit(self): + if self.finished or self.silent_exit: + sys.exit(0) + else: + sys.exit(1) class StoppingSignal(Exception): - pass + def __init__(self, *args, silent=False, **kwargs): + super().__init__(*args, **kwargs) + self.silent = silent diff --git a/fasttyper/listener.py b/fasttyper/listener.py index 5fecd8e..45e8b74 100644 --- a/fasttyper/listener.py +++ b/fasttyper/listener.py @@ -21,7 +21,7 @@ class Listener: if key == "\t": self.tabbed = True elif key == "\n" and self.tabbed: - raise StoppingSignal() + raise StoppingSignal(silent=True) elif key == 263: action = Action.del_word self.tabbed = False diff --git a/fasttyper/state.py b/fasttyper/state.py index 5f4f2cd..6dbcdc5 100644 --- a/fasttyper/state.py +++ b/fasttyper/state.py @@ -39,6 +39,7 @@ class StateMachine: self.state = State.invalid elif user_position == self.application.reference_buffer.get_lenght(): self.state = State.finished + self.application.finished = True def valid(self): return self.state in (State.valid, State.finished) diff --git a/setup.py b/setup.py index 7fc1f3e..eff7dd2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setup( name="fasttyper", - version="1.3.1", + version="1.3.2", author="Piotr Domanski", author_email="pi.domanski@gmail.com", description="Minimalistic typing exercise",