From 001aeede803692de19e10b5a08210898519a924d Mon Sep 17 00:00:00 2001 From: Doman Date: Mon, 6 Jun 2022 22:17:29 +0200 Subject: [PATCH] Modified default summary template --- fasttyper/cli.py | 6 +++--- fasttyper/components.py | 28 +++++++++++++++++----------- fasttyper/config.py | 19 ++++++++++++------- fasttyper/interface.py | 10 +++++----- setup.cfg | 2 +- setup.py | 2 +- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/fasttyper/cli.py b/fasttyper/cli.py index c2c8958..5a6b600 100644 --- a/fasttyper/cli.py +++ b/fasttyper/cli.py @@ -2,7 +2,7 @@ from .application import Application from .interface import Interface from .components import ( TextBox, - StatsBox, + Summary, ) from .listener import Listener from .buffer import Buffer @@ -34,7 +34,7 @@ def initialize(config_path, rbuffer, backspace_debug, no_cursor, runtime_config) config = Config(configmap) text_box = TextBox(config) - stats_box = StatsBox(config) + summary = Summary(config) stats = Stats(runtime_config) buffer = Buffer(rbuffer, text_box, stats) @@ -48,7 +48,7 @@ def initialize(config_path, rbuffer, backspace_debug, no_cursor, runtime_config) text_box, ], [ - stats_box, + summary, ], no_cursor, ) diff --git a/fasttyper/components.py b/fasttyper/components.py index 5c422cc..6a07b67 100644 --- a/fasttyper/components.py +++ b/fasttyper/components.py @@ -59,14 +59,14 @@ class BorderedBox(WindowComponent): Adds border to WindowComponent """ - def __init__(self, config): + def __init__(self, config, height, border): super().__init__(config) - self.maxy, self.maxx = None, None self.pos_y = config.get("top_margin_percentage") / 100 self.pos_x = config.get("left_margin_percentage") / 100 - self.height = config.get("lines_on_screen") + self.height = height + self.border = border self.width = None self.application = None @@ -86,7 +86,7 @@ class BorderedBox(WindowComponent): int(self.pos_y * self.maxy) - 1, ) self.init_window() - self.set_box(1) + self.set_box(self.border) screen.refresh() @@ -97,7 +97,7 @@ class BorderWithImprintedStats(BorderedBox): """ def __init__(self, config): - super().__init__(config) + super().__init__(config, config.get("lines_on_screen"), config.get("border")) self.stats_template = config.get("stats_template").replace("\n", " ") self.stats_color = config.get("stats_color") @@ -326,19 +326,22 @@ class TextBox(BufferDependentComponent): self.refresh() -class StatsBox(BorderedBox): +class Summary(BorderedBox): """ - Displays stats + Displays summary """ def __init__(self, config): - super().__init__(config) + super().__init__( + config, config.get("summary_lines"), config.get("summary_border") + ) self.logo = config.get("logo") self.logo_color = config.get("logo_color") self.resume_text = config.get("resume_text") self.resume_text_color = config.get("resume_text_color") - self.template = config.get("end_template") - self.color = config.get("end_color") + self.template = config.get("summary_template") + self.color = config.get("summary_color") + self.centered = config.get("summary_centered") def paint_logo(self): if len(self.logo) <= self.width: @@ -364,7 +367,10 @@ class StatsBox(BorderedBox): return for i, text in enumerate(lines): - self.paint_text(i, 1, text, self.color) + offset = 0 + if self.centered: + offset = self.width // 2 - len(text.split("|")[0]) - 1 + self.paint_text(i, offset, text, self.color) def paint(self, screen, application): self.maxy, self.maxx = screen.getmaxyx() diff --git a/fasttyper/config.py b/fasttyper/config.py index d021ae4..89e5008 100644 --- a/fasttyper/config.py +++ b/fasttyper/config.py @@ -10,16 +10,21 @@ class Config: "top_margin_percentage": 40, "left_margin_percentage": 35, "lines_on_screen": 3, - "logo": "~FastTyper~", + "border": 1, + "logo": " ~ FastTyper ~ ", "logo_color": 8, - "resume_text": "press to continue, C to exit", + "resume_text": " press to continue, C to exit ", "resume_text_color": 9, - "end_template": ( - "wpm: {wpm:.1f}/{peak_wpm:.1f} raw: {raw_wpm:.1f}/{peak_raw_wpm:.1f}", - "acc: {accuracy:.1f} chars: {correct_chars}/{total_chars} words: {correct_words}/{total_words}", - "time: {total_seconds:.1f}s", + "summary_template": ( + "wpm: {wpm:5.1f} | peak: {peak_wpm:5.1f}", + "raw: {raw_wpm:5.1f} | peak: {peak_raw_wpm:5.1f}", + "acc: {accuracy:5.1f}% | words: {correct_words}/{total_words}", + "time: {total_seconds:5.1f}s ", ), - "end_color": 9, + "summary_centered": True, + "summary_color": 9, + "summary_lines": 4, + "summary_border": 0, } def __init__(self, configmap): diff --git a/fasttyper/interface.py b/fasttyper/interface.py index 22cde93..3649972 100644 --- a/fasttyper/interface.py +++ b/fasttyper/interface.py @@ -3,10 +3,10 @@ from .application import StoppingSignal class Interface: - def __init__(self, application, components, end_components, no_cursor=False): + def __init__(self, application, components, summary_components, no_cursor=False): self.application = application self.components = components - self.end_components = end_components + self.summary_components = summary_components self.no_cursor = no_cursor self.colors = True @@ -31,8 +31,8 @@ class Interface: for component in self.components: component.paint(screen, self.application) - def draw_end(self, screen): - for component in self.end_components: + def draw_summary(self, screen): + for component in self.summary_components: component.paint(screen, self.application) def __call__(self, screen): @@ -54,7 +54,7 @@ class Interface: if self.application.summarize(): screen.clear() curses.curs_set(0) - self.draw_end(screen) + self.draw_summary(screen) while self.application.action(screen): pass diff --git a/setup.cfg b/setup.cfg index 8fb17b0..325797d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.1.2 +current_version = 2.1.3 [wheel] universal = 1 diff --git a/setup.py b/setup.py index 0206890..edb6474 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.1.2", + version="2.1.3", author="Piotr Domanski", author_email="pi.domanski@gmail.com", description="Minimalistic typing exercise",