diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index 0a06c65..d5e3078 100644 --- a/squirrelbattle/display/display.py +++ b/squirrelbattle/display/display.py @@ -20,6 +20,8 @@ class Display: return curses.newpad(height, width) if self.screen else FakePad() def truncate(self, msg: str, height: int, width: int) -> str: + height = max(0, height) + width = max(0, width) lines = msg.split("\n") lines = lines[:height] lines = [line[:width] for line in lines] @@ -31,8 +33,8 @@ class Display: If the message is too large, it is truncated vertically and horizontally """ height, width = pad.getmaxyx() - msg = self.truncate(msg, height - y, width - x) - if msg.replace("\n", ""): + msg = self.truncate(msg, height - y, width - x - 1) + if msg.replace("\n", "") and x >= 0 and y >= 0: return pad.addstr(y, x, msg, *options) def init_pair(self, number: int, foreground: int, background: int) -> None: