code / btui

Lines2.2K C1.2K Python549 Markdown219 make156 Lua49
(49 lines)
1 #!/usr/bin/env python3
2 #
3 # This file contains a simple test program for demonstrating some basic Python
4 # BTUI usage.
5 #
6 import btui
8 with btui.open() as bt:
9 key = None
10 x, y = 1, 1
11 while key != 'q' and key != 'Ctrl-c':
12 if key == '?':
13 with bt.disabled():
14 input("Press enter to continue.")
15 elif key == 'Ctrl-z':
16 bt.suspend()
18 bt.clear()
20 with bt.fg(.8, .95, .2):
21 bt.outline_box(x, y, 30, 1)
22 bt.move(x, y)
23 bt.write(f"Pressed: {key}")
25 title = "Python BTUI Demo"
26 w = len(title)
27 center = (bt.width - w) // 2
28 with bt.attributes("fg_blue", "bg_normal"):
29 bt.draw_shadow(center - 2, 0, w + 4, 3)
30 with bt.attributes("bg_blue", "fg_black"):
31 bt.fill_box(center - 2, 0, w + 4, 3)
32 bt.move(center, 1)
33 bt.write(title)
35 with bt.attributes("bold"):
36 bt.move(0, bt.height-1)
37 bt.write("Press 'q' to quit")
39 with bt.attributes("faint"):
40 s = f"Size: ({bt.width}x{bt.height})"
41 bt.move(bt.width-len(s), bt.height-1)
42 bt.write(s)
44 key, mx, my = bt.getkey()
45 if mx:
46 x, y = mx, my
48 if key == 'Ctrl-c':
49 raise KeyboardInterrupt