Use custom function to render a string message onto a pad

This commit is contained in:
Yohann D'ANELLO
2020-11-26 12:35:52 +01:00
parent b6f5fe9364
commit 8b187ec2b3
5 changed files with 27 additions and 23 deletions

View File

@ -19,6 +19,9 @@ class Display:
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
return curses.newpad(height, width) if self.screen else FakePad()
def addstr(self, pad: Any, y: int, x: int, msg: str, *options) -> None:
return pad.addstr(y, x, msg, *options)
def init_pair(self, number: int, foreground: int, background: int) -> None:
return curses.init_pair(number, foreground, background) \
if self.screen else None
@ -68,7 +71,7 @@ class VerticalSplit(Display):
def display(self) -> None:
for i in range(self.height):
self.pad.addstr(i, 0, "")
self.addstr(self.pad, i, 0, "")
self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1, self.x)
@ -88,7 +91,7 @@ class HorizontalSplit(Display):
def display(self) -> None:
for i in range(self.width):
self.pad.addstr(0, i, "")
self.addstr(self.pad, 0, i, "")
self.pad.refresh(0, 0, self.y, self.x, self.y, self.x + self.width - 1)
@ -99,10 +102,11 @@ class Box(Display):
self.pad = self.newpad(self.rows, self.cols)
def display(self) -> None:
self.pad.addstr(0, 0, "" + "" * (self.width - 2) + "")
self.addstr(self.pad, 0, 0, "" + "" * (self.width - 2) + "")
for i in range(1, self.height - 1):
self.pad.addstr(i, 0, "")
self.pad.addstr(i, self.width - 1, "")
self.pad.addstr(self.height - 1, 0, "" + "" * (self.width - 2) + "")
self.addstr(self.pad, i, 0, "")
self.addstr(self.pad, i, self.width - 1, "")
self.addstr(self.pad, self.height - 1, 0,
"" + "" * (self.width - 2) + "")
self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1,
self.x + self.width - 1)