Skip to content

Commit

Permalink
Add hidden 'q' command, alias for exit
Browse files Browse the repository at this point in the history
In the tools menu, 'exit' previously returned you to the mod menu. This
has been revised. 'exit' will now close ammo completely, as will 'q',
regardless of which menu is active. To return to the mods menu from the
tools menu, use 'mods' command.
  • Loading branch information
cyberrumor committed Mar 30, 2024
1 parent 43b29c6 commit 6c8bef6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ammo/tool_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def install_download(index, download) -> None:

install_download(index, download)

def exit(self) -> None:
def mods(self) -> None:
"""
Return to the mod controller
"""
Expand Down
16 changes: 16 additions & 0 deletions ammo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Command:
args: list[Arg]
doc: str
instance: Union[Controller, None]
visible: bool


class UI:
Expand Down Expand Up @@ -149,6 +150,7 @@ def populate_commands(self):
args=[],
doc=str(self.help.__doc__).strip(),
instance=None,
visible=True,
)

# Default 'exit', may be overridden.
Expand All @@ -158,6 +160,17 @@ def populate_commands(self):
args=[],
doc=str(self.exit.__doc__).strip(),
instance=None,
visible=True,
)

# Make 'exit' available from 'q' too.
self.command["q"] = Command(
name="q",
func=self.exit,
args=[],
doc=str(self.exit.__doc__).strip(),
instance=None,
visible=False,
)

for name in dir(self.controller):
Expand Down Expand Up @@ -224,6 +237,7 @@ def populate_commands(self):
args=args,
doc=str(func.__doc__).strip(),
instance=self.controller,
visible=True,
)

def help(self):
Expand All @@ -235,6 +249,8 @@ def help(self):
column_doc = []

for name, command in sorted(self.command.items()):
if not command.visible:
continue
column_cmd.append(name)
column_arg.append(" ".join([arg.description for arg in command.args]))
column_doc.append(command.doc)
Expand Down

0 comments on commit 6c8bef6

Please sign in to comment.