noether/py/noether.py

35 lines
916 B
Python
Raw Normal View History

2025-06-16 20:47:52 +10:00
from noether.cli.style import *
from noether.cli.prompt import *
from noether.lib.structs import Result
class Noether(Prompt):
DEFAULT_PROMPT = style('~>> ', Color.BLUE)
def __init__(self) -> None:
super().__init__()
def _parse(self, command: str) -> int:
2025-06-11 11:11:35 +10:00
try:
2025-06-16 20:47:52 +10:00
return Result.succeed(int(command))
2025-06-11 11:11:35 +10:00
except ValueError:
2025-06-16 20:47:52 +10:00
return Result.fail('Not an integer.')
2025-06-11 12:43:49 +10:00
2025-06-16 20:47:52 +10:00
def _exec(self, command: int) -> None:
print(style(f'OMG {command}', Color.CYAN))
2025-06-11 12:43:49 +10:00
2025-06-16 20:47:52 +10:00
def main():
try:
noether = Noether()
while True:
noether.prompt()
except (KeyboardInterrupt, EOFError):
err = style('Exit Requested...', Effect.ITALICS)
print('\n', style('[!]', Color.RED), err)
2025-06-11 11:11:35 +10:00
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, EOFError):
2025-06-16 20:47:52 +10:00
# handles premature SIGINT/EOF
pass