diff --git a/deck/pager.py b/deck/pager.py index 0aa5c3f..48ceb56 100644 --- a/deck/pager.py +++ b/deck/pager.py @@ -27,17 +27,20 @@ def reflow(text): out = [] for line in text.split('\n'): line = line.rstrip() - while len(line) > 0: - out.append(line[0:REAL_TERM_COLS]) - line = line[REAL_TERM_COLS:] + if len(line) == 0: # also handle effectively empty lines + out.append('') + else: + while len(line) > 0: + out.append(line[0:REAL_TERM_COLS]) + line = line[REAL_TERM_COLS:] return out def print_paged(text): """Reflow and print the text in a paginated manner""" lines = reflow(text) - ll = len(lines) - for i in range(0, ll, REAL_TERM_ROWS): - chunk = lines[i:i + REAL_TERM_ROWS] + while True: + chunk = lines[0:REAL_TERM_ROWS] for line in chunk: print(line) - if i + REAL_TERM_ROWS < ll: - input(CONT_MSG) + lines = lines[REAL_TERM_ROWS:] + if len(lines) > 0: input(CONT_MSG) + else: break