min width handling

This commit is contained in:
doman 2022-08-01 13:51:36 +02:00
parent d88cb7bbef
commit 69140dd89f
5 changed files with 24 additions and 5 deletions

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.2.0
current_version = 2.3.0
[wheel]
universal = 1

View file

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