Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands/thread: Add option --strip_ansi to pipeto #1619

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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