-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluator.py
60 lines (48 loc) · 2.05 KB
/
evaluator.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
import kernel
import sys
import ekernel
import operator
from blessed import Terminal
from simpleeval import SimpleEval
term = Terminal()
def main():
if len(sys.argv) >= 2:
if sys.argv[1] >= "2.3.5":
# Initialize with splash screen
ekernel.splashScreen("ProcyonCLS Evaluator", "Version 2.3.5")
while True:
# Display interface
kernel.clrscr()
ekernel.printHeader("Evaluator")
print()
# Show help text
kernel.printInfo(("Type 'exit' to quit"))
print()
try:
# Get expression
expression = kernel.centered_input(term, "Expression ↓ ").strip()
if expression.lower() == 'exit':
kernel.printInfo(("Exiting Evaluator"))
break
if not expression:
kernel.printWarning(("Please enter an expression"))
continue
# Additional input validation
kernel.printSuccess((f"Result: {eval(expression)}"))
except ValueError as e:
kernel.printError((str(e)))
except Exception as e:
kernel.printError((f"Error: {str(e)}"))
print()
kernel.centered_input(term, "Press Enter to continue...")
else:
kernel.printError(("This version of evaluator is incompatible with current version of ProcyonCLS"))
else:
kernel.printError(("OS Scope Error"))
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
kernel.printWarning(("\nOperation cancelled by user"))
except Exception as e:
kernel.printError((f"An error occurred: {str(e)}"))