-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurses-test.py
More file actions
56 lines (43 loc) · 1.43 KB
/
curses-test.py
File metadata and controls
56 lines (43 loc) · 1.43 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
#!/usr/bin/env python3
#Created by PepeBigotes
def try_input(msg) -> str:
try: x = input(msg)
except KeyboardInterrupt: print("\nKeyboardInterrupt"); exit()
return x
import os
try:
try: import curses
except ImportError:
print("[!] Module 'curses' is not installed")
try_input(" Press ENTER to install it (or CTRL+C to exit)")
os.system('pip3 install windows-curses')
try: import curses
except ImportError: print("\n[!] Curses couldn't be installed"); exit(1)
try_input("\n Curses installed, press ENTER to continue")
except KeyboardInterrupt: print("\nKeyboardInterrupt"); exit()
import curses
from curses import wrapper
from time import sleep
def do_exit(code = 0):
# Escape getch() idk how
curses.endwin()
exit(code)
def main(stdscr):
curses.cbreak()
curses.noecho()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
GRN_BLK = curses.color_pair(1)
TERM = curses.termname().decode()
while True:
height,width = stdscr.getmaxyx()
lines_cols = f"{height}x{width}"
char = curses.keyname(stdscr.getch()).decode()
if char == "^X": do_exit()
stdscr.clear()
stdscr.addstr(0,0, f"{TERM} {lines_cols}")
stdscr.addstr(2,0, char)
stdscr.addstr(11,10, "hello world!", curses.A_UNDERLINE)
stdscr.addstr(12,10, "hello world!", GRN_BLK)
stdscr.refresh()
try: wrapper(main)
except KeyboardInterrupt: do_exit()