-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·82 lines (71 loc) · 2.52 KB
/
main.py
File metadata and controls
executable file
·82 lines (71 loc) · 2.52 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
74
75
76
77
78
79
80
81
82
#!/usr/bin/python3
import curses
import random
import argparse
import os
def main():
parser = argparse.ArgumentParser(description="Hacker typer to impress your friends! Press ESC at any moment to "
"exit the program.")
parser.add_argument("-t", "--test", action="store_true", help="Testing mode, uses a shorter file and a shorter"
"window.")
parser.add_argument("-s", "--speed", help="Typing speed, i.e. number of characters per key"
"stroke.", required=False, default=4, type=int)
args = parser.parse_args()
root = os.path.dirname(os.path.realpath(__file__))
if args.test:
input_file = root + "/test"
else:
input_file = root + "/in" + str(random.randint(1, 8))
text_file = open(input_file)
try:
speed = args.speed
default_screen = curses.initscr()
curses.start_color()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
default_screen.clear()
max_xy = default_screen.getmaxyx()
y_dim = max_xy[0]
if args.test and y_dim > 10:
y_dim = 10
x_dim = max_xy[1]
pad = curses.newpad(y_dim, x_dim)
pad.attrset(curses.color_pair(1))
pad.refresh(0, 0, 0, 0, y_dim - 1, x_dim - 1)
if not args.test:
text_file.seek(random.randrange(30000))
exit_program = False
pos = 0
while True:
key = pad.getch()
if key == 27:
exit_program = True
break
out_of_chars = False
for i in range(speed):
char = text_file.read(1)
if not char:
out_of_chars = True
break
try:
pad.addstr(char)
except curses.error:
pos += 1
pad.resize(y_dim + pos, x_dim)
pad.addstr(char)
pad.refresh(pos, 0, 0, 0, y_dim - 1, x_dim - 1)
if out_of_chars:
break
if not exit_program:
pad.erase()
default_screen.refresh()
pad.resize(3, 8)
pad.addstr(1, 0, " HACKED ")
pad.border()
pad.refresh(0, 0, 0, 0, 2, 7)
while pad.getch() != 27:
i = 0
finally:
text_file.close()
curses.endwin()
if __name__ == "__main__":
main()