Skip to content

Commit

Permalink
commands/thread: Add option --strip_ansi to pipeto
Browse files Browse the repository at this point in the history
If someone has a mailcap entry that colors the mail content, it is
possible that she would want to get the content without the CSI escapes
when piping it an external command.

Ideally, there should be a way to have the content untouched by the
mailcap filter so we could use it when it makes sense. However, let's
use ansi.remove_csi() for the time being.
  • Loading branch information
guludo committed May 9, 2023
1 parent eb5ec07 commit d476536
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ def apply(self, ui):
'help': 'let the shell interpret the command'}),
(['--notify_stdout'], {'action': 'store_true',
'help': 'display cmd\'s stdout as notification'}),
(['--strip_ansi'], {'action': 'store_true',
'help': 'remove ANSI CSI escapes from the content'}),
])
class PipeCommand(Command):

Expand All @@ -653,7 +655,7 @@ class PipeCommand(Command):

def __init__(self, cmd, all=False, separately=False, background=False,
shell=False, notify_stdout=False, format='raw',
add_tags=False, noop_msg='no command specified',
add_tags=False, strip_ansi=False, noop_msg='no command specified',
confirm_msg='', done_msg=None, **kwargs):
"""
:param cmd: shellcommand to open
Expand All @@ -676,6 +678,8 @@ def __init__(self, cmd, all=False, separately=False, background=False,
:type format: str
:param add_tags: add 'Tags' header to the message
:type add_tags: bool
:param strip_ansi: remove ANSI CSI escapes from the content
:type strip_ansi: bool
:param noop_msg: error notification to show if `cmd` is empty
:type noop_msg: str
:param confirm_msg: confirmation question to ask (continues directly if
Expand All @@ -695,6 +699,7 @@ def __init__(self, cmd, all=False, separately=False, background=False,
self.notify_stdout = notify_stdout
self.output_format = format
self.add_tags = add_tags
self.strip_ansi = strip_ansi
self.noop_msg = noop_msg
self.confirm_msg = confirm_msg
self.done_msg = done_msg
Expand Down Expand Up @@ -745,6 +750,9 @@ async def apply(self, ui):
msgtext = '%s\n\n%s' % (headertext, bodytext)
pipestrings.append(msgtext)

if self.strip_ansi:
pipestrings = [ansi.remove_csi(s) for s in pipestrings]

if not self.separately:
pipestrings = [separator.join(pipestrings)]
if self.shell:
Expand Down

0 comments on commit d476536

Please sign in to comment.