Skip to content

Commit d476536

Browse files
committed
commands/thread: Add option --strip_ansi to pipeto
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.
1 parent eb5ec07 commit d476536

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

alot/commands/thread.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ def apply(self, ui):
645645
'help': 'let the shell interpret the command'}),
646646
(['--notify_stdout'], {'action': 'store_true',
647647
'help': 'display cmd\'s stdout as notification'}),
648+
(['--strip_ansi'], {'action': 'store_true',
649+
'help': 'remove ANSI CSI escapes from the content'}),
648650
])
649651
class PipeCommand(Command):
650652

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

654656
def __init__(self, cmd, all=False, separately=False, background=False,
655657
shell=False, notify_stdout=False, format='raw',
656-
add_tags=False, noop_msg='no command specified',
658+
add_tags=False, strip_ansi=False, noop_msg='no command specified',
657659
confirm_msg='', done_msg=None, **kwargs):
658660
"""
659661
:param cmd: shellcommand to open
@@ -676,6 +678,8 @@ def __init__(self, cmd, all=False, separately=False, background=False,
676678
:type format: str
677679
:param add_tags: add 'Tags' header to the message
678680
:type add_tags: bool
681+
:param strip_ansi: remove ANSI CSI escapes from the content
682+
:type strip_ansi: bool
679683
:param noop_msg: error notification to show if `cmd` is empty
680684
:type noop_msg: str
681685
:param confirm_msg: confirmation question to ask (continues directly if
@@ -695,6 +699,7 @@ def __init__(self, cmd, all=False, separately=False, background=False,
695699
self.notify_stdout = notify_stdout
696700
self.output_format = format
697701
self.add_tags = add_tags
702+
self.strip_ansi = strip_ansi
698703
self.noop_msg = noop_msg
699704
self.confirm_msg = confirm_msg
700705
self.done_msg = done_msg
@@ -745,6 +750,9 @@ async def apply(self, ui):
745750
msgtext = '%s\n\n%s' % (headertext, bodytext)
746751
pipestrings.append(msgtext)
747752

753+
if self.strip_ansi:
754+
pipestrings = [ansi.remove_csi(s) for s in pipestrings]
755+
748756
if not self.separately:
749757
pipestrings = [separator.join(pipestrings)]
750758
if self.shell:

0 commit comments

Comments
 (0)