-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
72 lines (50 loc) · 1.53 KB
/
test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import curses
import time
def main(stdscr):
# Clear screen
stdscr.clear()
# Enable scrolling
stdscr.scrollok(True)
for i in range(100):
# Add string to stdscr
stdscr.addstr(f"New line {i}\n")
# Refresh the screen
stdscr.refresh()
# Sleep for a while
time.sleep(0.1)
# Wait for user input before closing
stdscr.getch()
curses.wrapper(main)
# -------------------
def stdscr(stdscr, header, values):
stdscr.clear()
stdscr.addstr(0, 0, header)
stdscr.refresh()
# Enable scrolling
stdscr.scrollok(True)
for scr_row, value in enumerate(values, start=1):
# If the window is full, scroll it up
if scr_row >= stdscr.getmaxyx()[0]:
stdscr.scroll()
scr_row -= 1
stdscr.addstr(scr_row, 0, f"{value}\n")
stdscr.refresh()
curses.wrapper(stdscr, header, values)
# -----------
header = "*** Sticky Header ***"
def main(stdscr):
stdscr.clear()
stdscr.addstr(0, 0, header) # Initial header
stdscr.refresh()
while True:
new_output = get_new_data() # Replace with your data generation logic
stdscr.addstr("\n" * 2) # Push previous content down
stdscr.addstr(0, 0, header) # Reprint header
stdscr.addstr(1, 0, new_output)
stdscr.refresh()
time.sleep(0.5) # Adjust delay as needed
def get_new_data():
# Simulating new data for this example
import random
return f"Random Value: {random.randint(1,100)}"
curses.wrapper(main)