From: Christian Heller Date: Wed, 6 Aug 2025 12:18:24 +0000 (+0200) Subject: Add /help command to print available commands. X-Git-Url: https://plomlompom.com/repos/booking/%7B%7B%20web_path%20%7D%7D/static/bar%20baz.html?a=commitdiff_plain;p=ircplom Add /help command to print available commands. --- diff --git a/ircplom/tui_base.py b/ircplom/tui_base.py index f789914..25152ca 100644 --- a/ircplom/tui_base.py +++ b/ircplom/tui_base.py @@ -471,6 +471,35 @@ class BaseTui(QueueMixin): if alert: self._log.alert(f'invalid prompt command: {alert}') + def cmd__help(self) -> None: + 'Print available commands.' + self._log.add('commands available in this window:') + cmds = {} + cmd_prefix = 'cmd__' + base = 'self' + for path in (base, f'{base}.window', f'{base}.window.prompt'): + for cmd_method_name in [attr_name for attr_name in dir(eval(path)) + if attr_name.startswith(cmd_prefix)]: + path_prefix = f'{path}.' + cmd_name = (path_prefix[len(base)+1:] + + cmd_method_name[len(cmd_prefix):]) + method = eval(f'{path_prefix}{cmd_method_name}') + args = [] + for key, param in signature(method).parameters.items(): + arg = key.upper() + if param.default != inspect_empty: + arg = f'[{arg}]' + args += [arg] + cmds[cmd_name] = args + to_log = [] + for cmd_name, args in cmds.items(): + for key, target in CMD_SHORTCUTS.items(): + if target == cmd_name: + cmd_name = key + to_log += [f'{cmd_name} {" ".join(args)}'] + for item in sorted(to_log): + self._log.add(f' /{item}') + def cmd__quit(self) -> None: 'Trigger program exit.' self._put(QuitEvent())