diff --git a/fasttyper/components.py b/fasttyper/components.py index 2d809f4..f7899e6 100644 --- a/fasttyper/components.py +++ b/fasttyper/components.py @@ -77,6 +77,8 @@ class TextBox(TextComponent): self.maxy, self.maxx = None, None self.usedy, self.usedx = None, None + self.left_margin = config.get("left_margin_percentage") + def clear(self): self.elements = [] @@ -105,7 +107,11 @@ class TextBox(TextComponent): @property def max_line_x(self): - return self.maxx - 1 + return int(self.maxx * (100 - self.left_margin - self.left_margin) / 100) - 1 + + @property + def padding(self): + return " " * int(1 + self.left_margin * self.maxx / 100) def prepare_text_element(self, element): lines = [] @@ -150,11 +156,10 @@ class TextBox(TextComponent): lines[-1] = lines[-1][: -len(next_word)] lines = lines[: self.maxy - self.usedy] - return "\n".join(lines) + return ("\n" + self.padding).join(lines) def pain_element(self, screen, element): self.usedy, self.usedx = screen.getyx() - self.maxy, self.maxx = screen.getmaxyx() text = self.prepare_text_element(element) self.paint_text(screen, text, element.color) @@ -162,6 +167,8 @@ class TextBox(TextComponent): self.cursor_component.update(screen) def paint(self, screen, application): + self.maxy, self.maxx = screen.getmaxyx() + self.paint_text(screen, self.padding, 0) for element in self.elements: self.pain_element(screen, element) diff --git a/fasttyper/config.py b/fasttyper/config.py index 8318fb4..34bdd1e 100644 --- a/fasttyper/config.py +++ b/fasttyper/config.py @@ -21,7 +21,8 @@ class Config: "accuracy: {stats.accuracy:0.2f}%" ), "summary_datafile": "~/.cache/fasttyper/datafile.csv", - "top_margin_percentage": 0, + "top_margin_percentage": 30, + "left_margin_percentage": 10, } def __init__(self, configmap): diff --git a/setup.cfg b/setup.cfg index b3c54c7..54b39fa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.3.4 +current_version = 1.4.0 [wheel] universal = 1 diff --git a/setup.py b/setup.py index d0cd6cf..8cd65af 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.4", + version="1.4.0", author="Piotr Domanski", author_email="pi.domanski@gmail.com", description="Minimalistic typing exercise",