-
Notifications
You must be signed in to change notification settings - Fork 185
/
test_termboxmodule.py
executable file
·129 lines (115 loc) · 3.08 KB
/
test_termboxmodule.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import termbox
import time
import sys
import random
#import psyco
#psyco.full()
spaceord = ord(u" ")
def print_line(t, msg, y, fg, bg):
w = t.width()
l = len(msg)
x = 0
for i in range(w):
c = spaceord
if i < l:
c = ord(msg[i])
t.change_cell(x+i, y, c, fg, bg)
class SelectBox(object):
def __init__(self, tb, choices, active=-1):
self.tb = tb
self.active = active
self.choices = choices
self.color_active = (termbox.BLACK, termbox.CYAN)
self.color_normal = (termbox.WHITE, termbox.BLACK)
def draw(self):
for i, c in enumerate(self.choices):
color = self.color_normal
if i == self.active:
color = self.color_active
print_line(self.tb, c, i, *color)
def validate_active(self):
if self.active < 0:
self.active = 0