1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-06-23 06:25:26 +00:00

Don't draw out of bounds

This commit is contained in:
Ivan Habunek 2018-01-13 13:03:45 +01:00
parent 5463e86d5d
commit e829ce2714
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -1,12 +1,10 @@
def draw_horizontal_divider(window, y):
height, width = window.getmaxyx()
if y > height:
raise ValueError("y out of bounds")
line = '' + '' * (width - 2) + ''
window.addstr(y, 0, line)
# Don't draw out of bounds
if y < height - 1:
line = '' + '' * (width - 2) + ''
window.addstr(y, 0, line)
def enumerate_lines(generator, default_color):
@ -22,7 +20,9 @@ def enumerate_lines(generator, default_color):
def draw_lines(window, lines, x, y, default_color):
height, _ = window.getmaxyx()
for dy, line, color in enumerate_lines(lines, default_color):
window.addstr(y + dy, x, line, color)
if y + dy < height - 1:
window.addstr(y + dy, x, line, color)
return y + dy + 1