-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
46 lines (39 loc) · 926 Bytes
/
app.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
# app.py
# version 0.1
import os
import subprocess
import sys
import importlib
try:
import readchar
except ImportError:
print("Installing readchar module. You're welcome.")
importlib.import_module("pip").main(["install", "readchar"])
import readchar
def main():
os.system('clear')
last_command = ""
print("Welcome to the app • Greet • Exit • Restart\n\nEnter a command:")
actions = {
"g": lambda: print("Gangster"),
"r": lambda: (subprocess.run(["python3", "app.py"]), sys.exit())
}
while True:
command = readchar.readkey()
if isinstance(command, bytes):
command = str(command, "utf-8")
if command == "e":
os.system('clear')
sys.exit()
if command == "\x1b[A":
command = last_command
elif command != "KEY_UP":
if command in actions:
last_command = command
else:
continue
action = actions.get(command)
if action:
action()
if __name__ == "__main__":
main()