Don't render message on negative indexes
This commit is contained in:
parent
f2318ed308
commit
ca03caf3ba
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue