From 4bc5abd14d2d98182b530a5a01a1686f206d30d7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Nov 2021 17:34:05 +0100 Subject: commands/thread: auto-page copiousoutput mailcap handlers --- alot/commands/thread.py | 18 ++++++++++++++---- 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 -- cgit v1.2.3