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()
|
return curses.newpad(height, width) if self.screen else FakePad()
|
||||||
|
|
||||||
def truncate(self, msg: str, height: int, width: int) -> str:
|
def truncate(self, msg: str, height: int, width: int) -> str:
|
||||||
|
height = max(0, height)
|
||||||
|
width = max(0, width)
|
||||||
lines = msg.split("\n")
|
lines = msg.split("\n")
|
||||||
lines = lines[:height]
|
lines = lines[:height]
|
||||||
lines = [line[:width] for line in lines]
|
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
|
If the message is too large, it is truncated vertically and horizontally
|
||||||
"""
|
"""
|
||||||
height, width = pad.getmaxyx()
|
height, width = pad.getmaxyx()
|
||||||
msg = self.truncate(msg, height - y, width - x)
|
msg = self.truncate(msg, height - y, width - x - 1)
|
||||||
if msg.replace("\n", ""):
|
if msg.replace("\n", "") and x >= 0 and y >= 0:
|
||||||
return pad.addstr(y, x, msg, *options)
|
return pad.addstr(y, x, msg, *options)
|
||||||
|
|
||||||
def init_pair(self, number: int, foreground: int, background: int) -> None:
|
def init_pair(self, number: int, foreground: int, background: int) -> None:
|
||||||
|
|
Loading…
Reference in New Issue