-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathttyExample.py
More file actions
73 lines (60 loc) · 1.5 KB
/
Copy pathttyExample.py
File metadata and controls
73 lines (60 loc) · 1.5 KB
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
def getpass(prompt = "Password: "):
import termios, sys
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~termios.ECHO # lflags
try:
termios.tcsetattr(fd, termios.TCSADRAIN, new)
passwd = raw_input(prompt)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
return passwd
import sys, curses
class gb(object):
boxrows = int(sys.argv[1])
boxcols = boxrows
scrn = None
row = None
col = None
def draw(ch):
if gb.row == gb.boxrows-1:
'''if last row, change colors'''
gb.scrn.addch(gb.row,gb.col,ch,curses.color_pair(1))
else:
gb.scrn.addch(gb.row,gb.col,ch)
gb.scrn.refresh()
gb.row += 1
#if at bottom, goto top, next col
if gb.row == gb.boxrows:
gb.row = 0
gb.col += 1
if gb.col == gb.boxcols:
'''if cols == max, overwrite'''
gb.col = 0
def restorescreen():
curses.nocbreak()
curses.echo()
curses.endwin()
def main():
gb.scrn = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
gb.scrn.clear()
gb.row = 0
gb.col = 0
gb.scrn.refresh()
while True:
c = gb.scrn.getch()
c = chr(c)
if c == 'q':
break
draw(c)
restorescreen()
if __name__ == '__main__':
try:
main()
except:
restorescreen()