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

This commit is contained in:
Yohann D'ANELLO 2021-01-09 18:42:11 +01:00
parent 93a9e5e4c4
commit 8cb2b2388f
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85

View File

@ -124,15 +124,24 @@ class Display:
return pad.addstr(y, x, msg, attr)
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) \
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:
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:
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,
resize_pad: bool = True) -> None: