Toot-Mastodon-CLI-TUI-clien.../toot/ui/utils.py

29 lines
807 B
Python
Raw Normal View History

2018-01-06 17:32:27 +01:00
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)
def enumerate_lines(generator, default_color):
for y, item in enumerate(generator):
if isinstance(item, tuple) and len(item) == 2:
yield y, item[0], item[1]
elif isinstance(item, str):
yield y, item, default_color
elif item is None:
yield y, "", default_color
else:
raise ValueError("Wrong yield in generator")
def draw_lines(window, lines, x, y, default_color):
for dy, line, color in enumerate_lines(lines, default_color):
window.addstr(y + dy, x, line, color)
return y + dy + 1