diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index 17d8c29..55e23a8 100644 --- a/squirrelbattle/display/display.py +++ b/squirrelbattle/display/display.py @@ -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: