From cc0e2ff7226c794c3f1e04964df2ebf156b8490c Mon Sep 17 00:00:00 2001 From: Roland Hieber <rohieb@rohieb.name> Date: Wed, 7 May 2014 02:49:13 +0200 Subject: [PATCH] python: make client.writeline() autoscroll as least surprise --- python/cat.py | 22 +++------------------- python/client.py | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/python/cat.py b/python/cat.py index 87a9933..29a19af 100644 --- a/python/cat.py +++ b/python/cat.py @@ -4,24 +4,8 @@ import sys import client # read lines from stdin and write them to the display. -# includes scrolling. -# FIXME: scrolling is slow. use a pixel buffer and blitting. -if __name__ == "__main__": - y = 0 - lines = [] +line = sys.stdin.readline() +while(line != ""): + client.writeline(line) line = sys.stdin.readline() - while(line != ""): - client.write(0, y, line) - lines.append(line) - if(y == client.NUM_SEG_Y): - lines.reverse() - lines.pop() - lines.reverse() - y = 0 - for l in lines: - client.write(0, y, l) - y += 1 - else: - y += 1 - line = sys.stdin.readline() diff --git a/python/client.py b/python/client.py index 58866d9..885cfe1 100644 --- a/python/client.py +++ b/python/client.py @@ -111,10 +111,21 @@ def write(x, y, string): if(x > NUM_SEG_X): return False -# write text at beginning of line and clear remaining horizontal space -def writeline(y, string): - write(0, y, string) - write(len(string), y, ' ' * (NUM_SEG_X-len(string))) +# write line to screen as if on a terminal, scroll up if neccessary +cur_line = -1 +def writeline(string): + global cur_line + cur_line += 1 + if(cur_line >= NUM_SEG_Y): + scrollline() + cur_line -= 1 + write(0, cur_line, string) + + # clear remaining row + clear_chars = (NUM_SEG_X-len(string)) + screenbuf_blit(len(string) * PWIDTH, cur_line * PHEIGHT, + clear_chars * PWIDTH, PHEIGHT, + [0] * clear_chars * PWIDTH * PHEIGHT) # scroll the content y lines up and clear last line def scrollline(y = 1): -- GitLab