summaryrefslogtreecommitdiff
path: root/alot/commands/thread.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/commands/thread.py')
-rw-r--r--alot/commands/thread.py18
1 files changed, 14 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',