Merge branch 'fix-tty-colors' into 'master'

Don't use custom colors on unsupported screens, fixes #67

Closes #67

See merge request ynerant/squirrel-battle!61
This commit is contained in:
ynerant 2021-01-09 21:52:03 +01:00
commit 5b5180d44a
1 changed files with 12 additions and 3 deletions

View File

@ -124,15 +124,24 @@ class Display:
return pad.addstr(y, x, msg, attr) return pad.addstr(y, x, msg, attr)
def init_pair(self, number: int, foreground: int, background: int) -> None: def init_pair(self, number: int, foreground: int, background: int) -> None:
foreground = foreground if self.screen and curses.can_change_color() \
and foreground < curses.COLORS \
else curses.COLOR_WHITE
background = background if self.screen and curses.can_change_color() \
and background < curses.COLORS \
else curses.COLOR_WHITE
return curses.init_pair(number, foreground, background) \ return curses.init_pair(number, foreground, background) \
if self.screen else None if self.screen and curses.can_change_color() \
and number < curses.COLOR_PAIRS else None
def color_pair(self, number: int) -> int: def color_pair(self, number: int) -> int:
return curses.color_pair(number) if self.screen else 0 return curses.color_pair(number) if self.screen \
and number < curses.COLOR_PAIRS else 0
def init_color(self, number: int, red: int, green: int, blue: int) -> None: def init_color(self, number: int, red: int, green: int, blue: int) -> None:
return curses.init_color(number, red, green, blue) \ return curses.init_color(number, red, green, blue) \
if self.screen else None if self.screen and curses.can_change_color() \
and number < curses.COLORS else None
def resize(self, y: int, x: int, height: int, width: int, def resize(self, y: int, x: int, height: int, width: int,
resize_pad: bool = True) -> None: resize_pad: bool = True) -> None: