diff --git a/fasttyper/components.py b/fasttyper/components.py index 353c12a..4502219 100644 --- a/fasttyper/components.py +++ b/fasttyper/components.py @@ -70,6 +70,7 @@ class BorderedBox(WindowComponent): self.pos_y = config.get("top_margin_percentage") / 100 self.pos_x = config.get("left_margin_percentage") / 100 + self.min_width = config.get("min_width") self.height = height self.border = border self.width = None @@ -84,11 +85,20 @@ class BorderedBox(WindowComponent): def init(self, screen, application): self.application = application self.width = int(self.maxx * (1 - 2 * self.pos_x)) + + pos_x = int(self.pos_x * self.maxx) - 1 + pos_y = int(self.pos_y * self.maxy) - 1 + + if self.width < self.min_width: + width = min(self.maxx, self.min_width) + self.width = width + pos_x = int(max(0, (self.maxx - width) / 2 - 1)) + self.update_size( self.height + 2, self.width + 2, - int(self.pos_x * self.maxx) - 1, - int(self.pos_y * self.maxy) - 1, + pos_x, + pos_y, ) self.init_window() self.set_box(self.border) diff --git a/fasttyper/config.py b/fasttyper/config.py index 89e5008..d82532c 100644 --- a/fasttyper/config.py +++ b/fasttyper/config.py @@ -9,6 +9,7 @@ class Config: "summary_datafile": "~/.cache/fasttyper/datafile.csv", "top_margin_percentage": 40, "left_margin_percentage": 35, + "min_width": 80, "lines_on_screen": 3, "border": 1, "logo": " ~ FastTyper ~ ", diff --git a/fasttyper/listener.py b/fasttyper/listener.py index 98dcaa7..ed57e06 100644 --- a/fasttyper/listener.py +++ b/fasttyper/listener.py @@ -1,3 +1,4 @@ +import os import enum import string import curses @@ -7,6 +8,10 @@ from .application import StoppingSignal WHITE = [ord(c) for c in string.whitespace] TAB = ord("\t") +TERMINALS_WITH_NORMAL_SPACE = [ + "xterm-kitty", +] + class Action(enum.Enum): add_char = "add_char" @@ -19,7 +24,10 @@ class Action(enum.Enum): class Listener: def __init__(self, backspace_debug=False): - self.backspace_debug = not backspace_debug + self.backspace_debug = backspace_debug + + if os.environ.get("TERM", "") in TERMINALS_WITH_NORMAL_SPACE: + self.backspace_debug = not self.backspace_debug def action_for_char(self, key): if key == "\t": diff --git a/setup.cfg b/setup.cfg index 9ca90c9..5deb0d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.2.0 +current_version = 2.3.0 [wheel] universal = 1 diff --git a/setup.py b/setup.py index d6112ec..f100604 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.2.0", + version="2.3.0", author="Piotr Domanski", author_email="pi.domanski@gmail.com", description="Minimalistic typing exercise",