-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.py
More file actions
99 lines (69 loc) · 2.44 KB
/
shell.py
File metadata and controls
99 lines (69 loc) · 2.44 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from parser import Parser
SHELL_VERSION = (0, 1, 0)
def print_version():
major_ver, minor_ver, patch_ver = SHELL_VERSION
print(
f"""
=====================================
QUICKINFO SHELL v{major_ver}.{minor_ver}.{patch_ver}
=====================================
""")
def print_help():
print(
"""
========
HELP
========
==================================================================
This shell allows you to learn the formatting of data or to test
different inputs quickly.
Enter '-' to start edit mode, and enter key value pairs separated
by a ':' the same way as formatted in files. Enter another '-' to
close the document. Use -{command name} to run a command, or do
'-list' to list all commands.
==================================================================
""")
def print_command_list():
for command in commands:
print(command)
commands = {
'version': print_version,
'help': print_help,
'list': print_command_list,
}
def main():
print_version()
print_help()
prompt_timeout = 5
while True:
user = input("<qkif>> ")
if user == "-exit":
break
line_buffer = "-"
if user == '-':
while True:
edit_input = input("EDIT> ")
if edit_input == '-':
line_buffer += '\n-'
break
line_buffer += '\n' + edit_input
print(line_buffer)
result = Parser(line_buffer).parse()
print(result)
elif '-' in user:
try:
command_string = user.strip('-').strip(' ')
if command_string in commands:
commands[command_string]()
else:
print("Command not found.")
except Exception as e:
print("An error occurred while trying to run a command.")
else:
if prompt_timeout - 1 >= 0:
prompt_timeout -= 1
if prompt_timeout == 0:
print("Enter '-help' for more information.")
prompt_timeout = 5
if __name__ == "__main__":
main()