-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.py
70 lines (58 loc) · 2.33 KB
/
shell.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
import pathlib
version = '1.1.0'
print(f'''
x----------------------------------------------------------------------------------------------------------------------x
🍉 CodeMelon 🍉
🐚 Shell Release {version} 🐚
x----------------------------------------------------------------------------------------------------------------------x
Type '_license_', '_about_', '_syntax_' or '_test_' For more info.
Type 'exit()' to exit Shell.
''')
import codemelon
while True:
try:
text = input('🍉> ')
if text.lower().strip() == 'exit()':
break
elif text.lower().strip() == '_syntax_':
try:
print(open(f"{pathlib.Path(__file__).parent.resolve()}\\assets\\_syntax_.txt", "r").read())
except:
print("ERROR: Could not locate CodeMelon file _syntax_.txt")
elif text.lower().strip() == '_license_':
try:
print(open(f"{pathlib.Path(__file__).parent.resolve()}\\assets\\_license_.txt", "r").read())
except:
print("ERROR: Could not locate CodeMelon file _license_.txt")
elif text.strip().lower() == '_test_':
print(str(open(f"{pathlib.Path(__file__).parent.resolve()}\\assets\\test.mln", "r").read()))
print("\n\nOUTPUT:\n")
runpath = f"{pathlib.Path(__file__).parent.resolve()}/assets/test.mln".replace("\\", "/")
res, err = codemelon.run("test.mln", f"run(\"{runpath}\")")
if err:
print(err.as_string())
elif res:
if len(res.elements) == 1:
print(repr(res.elements[0]))
else:
print(res)
else:
pass
elif text.strip().lower() == '_about_':
print(open(f"{pathlib.Path(__file__).parent.resolve()}\\assets\\_about_.txt", "r").read())
elif text.strip() == '':
continue
else:
result, error = codemelon.run('<stdin>', text)
if error:
print(error.as_string())
elif result:
if len(result.elements) == 1:
print(repr(result.elements[0]))
else:
print(result)
else:
pass
except EOFError:
print("Goodbye")
break