-
Notifications
You must be signed in to change notification settings - Fork 0
/
mineshell.py
74 lines (61 loc) · 1.93 KB
/
mineshell.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
#! /usr/bin/python
import os, sys
import readline
import shlex
import signal
from minesweeper import __version__, config, main
fps = os.environ.get("MINESWEEPER_FORCE_FPS")
print("\033[95mWelcome! Run \033[96mminesweeper\033[95m to start the game. "
"Run \033[96mminesweeper --help\033[95m for a list of available options. Have fun ^_^\033[0m\n")
if fps is not None:
try:
fps = int(fps)
print(f"\033[38;5;244mTo reduce server stress, your frame rate is limited to {fps} fps. "
f"You can download the game at https://minesweeper.mia1024.io/ to enjoy uncapped performance. "
f"If you like the game, please consider giving this project a star on GitHub.\033[0m")
except (ValueError, TypeError):
pass
sys.stdout.flush()
def exit_handle(signum, frame):
print()
sys.exit(0)
signal.signal(signal.SIGINT, exit_handle)
signal.signal(signal.SIGHUP, exit_handle)
signal.signal(signal.SIGTERM, exit_handle)
def completer(i, s):
if readline.get_line_buffer().startswith("minesweeper "):
return None
if not i:
if s == 0:
return "minesweeper "
if s == 1:
return "exit"
elif s == 0:
return "minesweeper "
return None
readline.set_completer(completer)
readline.add_history("minesweeper")
readline.parse_and_bind("tab: complete")
readline.set_completer_delims(" ")
while True:
try:
args = shlex.split(input("$ "))
except EOFError:
print()
sys.exit(0)
if not args:
continue
if args[0] == "exit":
sys.exit(0)
elif args[0] != "minesweeper":
print(f"mineshell {__version__}: {args[0]}: command not found. Have you tried minesweeper?")
continue
else:
try:
config.init_config(config.parser.parse_args(args[1:]))
except SystemExit:
continue
try:
main.run()
except SystemExit:
pass