From 261d122822d3c93bd8edfcd7d87bc070b5b8ac35 Mon Sep 17 00:00:00 2001 From: Enrico Pirani Date: Thu, 14 May 2026 00:38:59 +0200 Subject: [PATCH] Fix crashes when config file is missing general/keymap sections - Fallback to English Wikipedia when no default wiki is configured - Fallback to empty keymap when no keymap section exists - Use local manpage for :help and show error on command failure --- wikicurses/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wikicurses/main.py b/wikicurses/main.py index 74d6b0c..820c06b 100644 --- a/wikicurses/main.py +++ b/wikicurses/main.py @@ -14,7 +14,9 @@ def executeCommand(cmd): try: - subprocess.call(cmd) + ret = subprocess.call(cmd) + if ret != 0: + ex.notify("Error: command '" + cmd[0] + "' exited with code " + str(ret)) except FileNotFoundError: ex.notify("Error: command '" + cmd[0] + "' not found.") loop.screen.clear() # Completely redraw screen after external command @@ -259,7 +261,7 @@ def keypress(self, size, key): maxcol, maxrow = size ex.notify('') # Clear any notification - cmdmap = settings.conf['keymap'] + cmdmap = settings.conf['keymap'] if 'keymap' in settings.conf else {} if key == ':': ex.enterexmode() if key == '/': @@ -443,7 +445,7 @@ def openWiki(name): wiki = name return if not name: - name = settings.conf['general']['default'] + name = settings.conf.get('general', 'default', fallback='https://en.wikipedia.org/w/api.php') if name in settings.conf: wiki = Wiki.fromName(name) else: @@ -516,7 +518,11 @@ def processCmd(cmd, *args): elif cmd == 'edit': edit(page.title) elif cmd == 'help': - executeCommand(['man', 'wikicurses']) + manpage = os.path.dirname(os.path.abspath(__file__)) + '/../wikicurses.1' + if os.path.exists(manpage): + executeCommand(['man', manpage]) + else: + executeCommand(['man', 'wikicurses']) elif cmd == 'back': if current > 0: current -= 1