-
Notifications
You must be signed in to change notification settings - Fork 101
/
history.py
48 lines (34 loc) · 1.16 KB
/
history.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
history
~~~~~~~
A tiny example to show how pagination works.
:copyright: (c) 2011-2013 by Selectel, see AUTHORS for details.
:license: LGPL, see LICENSE for more details.
"""
import os
import random
import string
import sys
import pyte
from pyte import modes as mo
def print_screen(screen, text):
print(pyte.control.ESC + pyte.escape.RIS)
for idx, line in enumerate(screen.display, 1):
print("{0:2d} {1} ¶".format(idx, line))
input(os.linesep + os.linesep + text)
def random_string(n, alphabet=string.ascii_letters + " "):
return "".join(random.choice(alphabet) for _ in range(n))
if __name__ == "__main__":
# ``ratio=1`` means scroll the whole screen.
screen = pyte.HistoryScreen(80, 12, ratio=1)
screen.set_mode(mo.LNM)
stream = pyte.Stream(screen)
pages = 3
stream.feed(os.linesep.join(random_string(screen.columns)
for _ in range(screen.lines * pages)))
screen.prev_page()
print_screen(screen, "Hit ENTER to move up!")
screen.prev_page()
print_screen(screen, "Hit ENTER to move back down!")
screen.next_page()
print_screen(screen, "OK?")