From ca03caf3bacaa80cfa22c97bc61525e9c752bab1 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 26 Nov 2020 20:35:10 +0100 Subject: [PATCH] Don't render message on negative indexes --- squirrelbattle/display/display.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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: