Truncate messages if they are too large
This commit is contained in:
parent
8b187ec2b3
commit
f2318ed308
|
@ -19,7 +19,20 @@ class Display:
|
|||
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
|
||||
return curses.newpad(height, width) if self.screen else FakePad()
|
||||
|
||||
def truncate(self, msg: str, height: int, width: int) -> str:
|
||||
lines = msg.split("\n")
|
||||
lines = lines[:height]
|
||||
lines = [line[:width] for line in lines]
|
||||
return "\n".join(lines)
|
||||
|
||||
def addstr(self, pad: Any, y: int, x: int, msg: str, *options) -> None:
|
||||
"""
|
||||
Display a message onto the pad.
|
||||
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", ""):
|
||||
return pad.addstr(y, x, msg, *options)
|
||||
|
||||
def init_pair(self, number: int, foreground: int, background: int) -> None:
|
||||
|
|
Loading…
Reference in New Issue