"""Call external commands.""" import curses import logging import re import subprocess import tempfile from bebop.page import Page def _pre_exec(): curses.nocbreak() curses.echo() curses.curs_set(1) def _post_exec(): curses.mousemask(curses.ALL_MOUSE_EVENTS) curses.curs_set(0) curses.noecho() curses.cbreak() def open_external_program(command): """Call command as a subprocess, suspending curses rendering. The caller has to refresh whatever windows it manages after calling this method or garbage may be left on the screen. Returns: True if no exception occured. """ _pre_exec() result = True try: subprocess.run(command) except OSError as exc: logging.error(f"Failed to run '{command}': {exc}") result = False _post_exec() return result SUB_URL_RE = re.compile(r"(?