diff options
| author | troido <troido@protonmail.com> | 2018-05-22 20:31:45 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2018-05-22 20:31:45 +0200 |
| commit | 7ce18903de5e4af2434911a5117177dbc4286bec (patch) | |
| tree | 7b3c784fcef1954e9ce64950da16854ae9b8c654 /asciifarm/client/display | |
| parent | 2e6fe20cc75fc0ce5e6da772e28e9dbb11aa35e4 (diff) | |
client doesn't crash anymore when screen too small
Diffstat (limited to 'asciifarm/client/display')
| -rw-r--r-- | asciifarm/client/display/screen.py | 3 | ||||
| -rw-r--r-- | asciifarm/client/display/window.py | 27 |
2 files changed, 15 insertions, 15 deletions
diff --git a/asciifarm/client/display/screen.py b/asciifarm/client/display/screen.py index e806b2d..21d7200 100644 --- a/asciifarm/client/display/screen.py +++ b/asciifarm/client/display/screen.py @@ -52,7 +52,8 @@ class Screen: def makeWin(self, x, y, width, height): if width < 1 or height < 1: win = None - win = curses.newwin(height, width, y, x) + else: + win = curses.newwin(height, width, y, x) return Window(win, self.colours) def getWin(self, name): diff --git a/asciifarm/client/display/window.py b/asciifarm/client/display/window.py index 7723f7b..d5c3945 100644 --- a/asciifarm/client/display/window.py +++ b/asciifarm/client/display/window.py @@ -6,13 +6,8 @@ class Window: def __init__(self, win, colours=None): - self.setWin(win) - self.colours = colours - - - - def setWin(self, win): self.win = win + self.colours = colours def getSize(self): if not self.win: @@ -30,6 +25,9 @@ class Window: """Draw a string that does not contain newlines or characters with larger width long lines are cropped to fit in the window""" + + if not self.win: + return x, y = pos width, height = self.getSize() string = string[:width-x] @@ -41,6 +39,8 @@ class Window: def _addstr(self, y, x, string, *args): + if not self.win: + return width, height = self.getSize() if y == height-1 and x+len(string) == width: if len(string) > 1: @@ -58,18 +58,17 @@ class Window: self.win.addstr(y, x, string, *args) def erase(self): - self.win.erase() + if self.win: + self.win.erase() def noutrefresh(self): - self.win.noutrefresh() - - def getCh(self, pos): - x, y = pos - return self.win.getch(y, x) + if self.win: + self.win.noutrefresh() def setAttr(self, pos, attr, num=1): - x, y = pos - self.win.chgat(y, x, num, attr) + if self.win: + x, y = pos + self.win.chgat(y, x, num, attr) |
