From f82510c687804b8e5c4942cdd6f804fc712982d2 Mon Sep 17 00:00:00 2001 From: duran55 <137329248+duran55@users.noreply.github.com> Date: Tue, 12 Mar 2024 03:08:10 +0200 Subject: [PATCH] Small fixes (#47) * add space after the Enter prompt * add clean exit on ctrl+d --- ammo/ui.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ammo/ui.py b/ammo/ui.py index d3fc62f..f7f1e7b 100755 --- a/ammo/ui.py +++ b/ammo/ui.py @@ -257,7 +257,11 @@ def help(self): + "\n" ) print(out) - input("[Enter]") + try: + input("[Enter] ") + except EOFError: + print() + sys.exit(0) def exit(self): """ @@ -315,9 +319,13 @@ def repl(self): os.system("clear") print(self.controller) - if not (stdin := input(f"{self.controller._prompt()}")): - continue - + try: + if not (stdin := input(f"{self.controller._prompt()}")): + continue + except EOFError: + print() + sys.exit(0) + cmds = stdin.split() args = [] if len(cmds) <= 1 else cmds[1:] func = cmds[0] @@ -338,7 +346,7 @@ def repl(self): print( f"{func} expected at least {len(command.args)} arg(s) but received {len(args)}" ) - input("[Enter]") + input("[Enter] ") continue prepared_args = [] @@ -346,7 +354,7 @@ def repl(self): expected_arg = None if len(expected_args) == 0 else expected_args.pop(0) if expected_arg is None and len(args) > 0: print(f"{func} expected no args but received {len(args)} arg(s).") - input("[Enter]") + input("[Enter] ") continue try: @@ -361,7 +369,7 @@ def repl(self): except (ValueError, KeyError) as e: print(f"arg was unexpected type: {e}") - input("[Enter]") + input("[Enter] ") continue if command.instance is not None: @@ -379,4 +387,4 @@ def repl(self): except Warning as warning: print(f"\n{warning}") - input("[Enter]") + input("[Enter] ")