diff --git a/fasttyper/components.py b/fasttyper/components.py index 6a07b67..353c12a 100644 --- a/fasttyper/components.py +++ b/fasttyper/components.py @@ -12,9 +12,13 @@ class WindowComponent: self._width = None self._begin_x = None self._begin_y = None + self.interface = None self.cursor_x, self.cursor_y = 0, 0 + def set_interface(self, interface): + self.interface = interface + def update_size(self, height, width, begin_x, begin_y): self._height = height self._width = width @@ -33,6 +37,7 @@ class WindowComponent: self._window.box(i, i) def paint_text(self, row, col, text, color): + color = self.interface.normalize_color(color) self._window.addstr(row, col, text, curses.color_pair(color)) def move(self, x, y): diff --git a/fasttyper/interface.py b/fasttyper/interface.py index 3649972..6978a53 100644 --- a/fasttyper/interface.py +++ b/fasttyper/interface.py @@ -9,6 +9,13 @@ class Interface: self.summary_components = summary_components self.no_cursor = no_cursor self.colors = True + self.max_color = None + + for component in self.components: + component.set_interface(self) + + for component in self.summary_components: + component.set_interface(self) def init_colors(self): try: @@ -21,7 +28,11 @@ class Interface: curses.use_default_colors() for i in range(0, curses.COLORS): - curses.init_pair(i + 1, i, -1) + self.max_color = i + 1 + try: + curses.init_pair(i + 1, i, -1) + except Exception: + break def init(self, screen): screen.clear() @@ -35,6 +46,12 @@ class Interface: for component in self.summary_components: component.paint(screen, self.application) + def normalize_color(self, color): + if not self.colors: + 0 + + return color % self.max_color + def __call__(self, screen): """ Main running loop diff --git a/requirements.txt b/requirements.txt index a664aa0..c51a3e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ readchar +requests +windows-curses; sys_platform == 'win32' or sys_platform == 'cygwin' diff --git a/setup.cfg b/setup.cfg index 325797d..9ca90c9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.1.3 +current_version = 2.2.0 [wheel] universal = 1 diff --git a/setup.py b/setup.py index edb6474..d6112ec 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.3", + version="2.2.0", author="Piotr Domanski", author_email="pi.domanski@gmail.com", description="Minimalistic typing exercise",