Modified default summary template

This commit is contained in:
Doman 2022-06-06 22:17:29 +02:00
parent e9b3223203
commit 001aeede80
6 changed files with 39 additions and 28 deletions

View file

@ -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,
)

View file

@ -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()

View file

@ -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 <Tab> to continue, <Ctrl>C to exit",
"resume_text": " press <Tab> to continue, <Ctrl>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):

View file

@ -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

View file

@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.2
current_version = 2.1.3
[wheel]
universal = 1

View file

@ -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",