Skip to content

Commit

Permalink
Small fixes (#47)
Browse files Browse the repository at this point in the history
* add space after the Enter prompt

* add clean exit on ctrl+d
  • Loading branch information
duran55 authored Mar 12, 2024
1 parent abbf0b8 commit f82510c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ammo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ def help(self):
+ "\n"
)
print(out)
input("[Enter]")
try:
input("[Enter] ")
except EOFError:
print()
sys.exit(0)

def exit(self):
"""
Expand Down Expand Up @@ -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]
Expand All @@ -338,15 +346,15 @@ 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 = []
expected_args = deepcopy(command.args)
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:
Expand All @@ -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:
Expand All @@ -379,4 +387,4 @@ def repl(self):

except Warning as warning:
print(f"\n{warning}")
input("[Enter]")
input("[Enter] ")

0 comments on commit f82510c

Please sign in to comment.