diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-11-20 17:34:05 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-11-20 17:34:05 +0100 |
commit | 4bc5abd14d2d98182b530a5a01a1686f206d30d7 (patch) | |
tree | 44261a834562a0f285a0e9963d24620e272b2065 | |
parent | abc24af1f25349bd6eac67a7b993c32df486825e (diff) |
commands/thread: auto-page copiousoutput mailcap handlers
-rw-r--r-- | alot/commands/thread.py | 18 | ||||
-rw-r--r-- | alot/utils/mailcap.py | 3 |
2 files changed, 17 insertions, 4 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 5b9d527b..fe84695b 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -11,6 +11,7 @@ from email.utils import getaddresses, parseaddr import logging import mailcap import os +import shutil import subprocess import tempfile @@ -945,15 +946,24 @@ class OpenAttachmentCommand(Command): ui.notify('No handler for: %s' % mimetype) return - # TODO: page copiousoutput # TODO: hook for processing the command - if h.needs_terminal: + pager = None + if h.copious_output: + # pipe the command's output to a pager + # TODO: allow configuring the pager from the config? + pager = os.getenv('PAGER', 'less') + if not shutil.which(pager): + pager = None + + if h.needs_terminal or pager: with ui.paused(), h: + cmd = ('( %s ) | %s' % (h.cmd, pager)) if pager else h.cmd + logging.debug('Displaying part %s on terminal: %s', - mimetype, h.cmd) + mimetype, cmd) try: - result = subprocess.run(h.cmd, shell = True, check = True, + result = subprocess.run(cmd, shell = True, check = True, input = h.stdin, stderr = subprocess.PIPE) except subprocess.CalledProcessError as e: logging.error('Calling mailcap handler "%s" failed with code %d: %s', diff --git a/alot/utils/mailcap.py b/alot/utils/mailcap.py index 9dccd7a0..f95a0a71 100644 --- a/alot/utils/mailcap.py +++ b/alot/utils/mailcap.py @@ -111,3 +111,6 @@ class MailcapHandler: @property def needs_terminal(self): return self._entry.get('needsterminal') is not None + @property + def copious_output(self): + return self._entry.get('copiousoutput') is not None |