added better windows support

This commit is contained in:
Doman 2022-07-11 12:40:49 +02:00
parent 001aeede80
commit d88cb7bbef
5 changed files with 27 additions and 3 deletions

View file

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

View file

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

View file

@ -1 +1,3 @@
readchar
requests
windows-curses; sys_platform == 'win32' or sys_platform == 'cygwin'

View file

@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.3
current_version = 2.2.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.1.3",
version="2.2.0",
author="Piotr Domanski",
author_email="pi.domanski@gmail.com",
description="Minimalistic typing exercise",