From: Christian Heller Date: Sun, 1 Jun 2025 11:02:48 +0000 (+0200) Subject: Improve command prompt error messaging. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/error?a=commitdiff_plain;h=8f3ee6649155d8bd74cd88c34757c69341c59de5;p=ircplom Improve command prompt error messaging. --- diff --git a/ircplom.py b/ircplom.py index ce447d7..e49a684 100755 --- a/ircplom.py +++ b/ircplom.py @@ -490,10 +490,11 @@ class TuiLoop(Loop): def _cmd__prompt_enter(self) -> None: if self._prompt: - success = False + alert: Optional[str] = None if len(self._prompt) > 1 and self._prompt[0] == '/': toks = self._prompt[1:].split(maxsplit=1) method_name = f'_cmd__{toks[0]}' + alert = f'{toks[0]} unknown' if hasattr(self, method_name)\ and method_name != stack()[0].function: method = getattr(self, method_name) @@ -501,8 +502,9 @@ class TuiLoop(Loop): n_args_max = len(params) n_args_min = len([p for p in params.values() if p.default == inspect_empty]) + alert = f'{toks[0]} needs {n_args_min} - {n_args_max} args' if len(toks) == 1 and not n_args_min: - success = method() + alert = method() elif len(toks) > 1 and params\ and n_args_min <= len(toks[1].split()): args = [] @@ -510,10 +512,11 @@ class TuiLoop(Loop): toks = toks[1].split(maxsplit=1) args += [toks[0]] n_args_max -= 1 - success = method(*args) - if not success: - self.broadcast('ALERT', - f'invalid prompt command: {self._prompt}') + alert = method(*args) + else: + alert = 'not prefixed by /' + if alert: + self.broadcast('ALERT', f'invalid prompt command: {alert}') self._prompt = '' self._draw_prompt() @@ -525,24 +528,21 @@ class TuiLoop(Loop): self._log.scroll_down() self._draw_log() - def _cmd__disconnect(self, quit_msg: str = 'ircplom says bye') -> bool: + def _cmd__disconnect(self, quit_msg: str = 'ircplom says bye') -> None: self.broadcast('SEND', IrcMessage('QUIT', [quit_msg])) - return True - def _cmd__quit(self) -> bool: + def _cmd__quit(self) -> None: self.broadcast('QUIT') - return True - def _cmd__buffer(self, buffer_idx_str: str) -> bool: + def _cmd__buffer(self, buffer_idx_str: str) -> Optional[str]: if not buffer_idx_str.isdigit(): - return False + return f'not-integer buffer_idx: {buffer_idx_str}' buffer_idx = int(buffer_idx_str) - if 0 <= buffer_idx < len(self._logs): - self._log_selected = buffer_idx - self._draw_log() - else: - self.broadcast('ALERT', 'invalid buffer idx') - return True + if buffer_idx < 0 or buffer_idx > len(self._logs): + return f'unavailable buffer idx: {buffer_idx}' + self._log_selected = buffer_idx + self._draw_log() + return None def _calc_and_draw_all(self) -> None: self._term.clear()