Skip to content

Commit

Permalink
feat: strip_ascii_escape_sequence() and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
podhmo committed Jun 11, 2019
1 parent 58e445f commit a23bf47
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ available info (extensions and additional modules)

.. code-block::
[1mextensions are used by `-e`, additional modules are used by `-a`.[0m
extensions are used by `-e`, additional modules are used by `-a`.
{
"extensions": {
"jinja2.ext.i18n": "This extension adds gettext support to Jinja2.",
Expand Down
12 changes: 10 additions & 2 deletions kamidana/additionals/reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Reading from other resources (e.g. read_from_file, read_from_command)
"""
import re
import os.path
import subprocess
from kamidana import as_filter
Expand All @@ -21,7 +22,9 @@ def read_from_file(ctx, filename, *, relative_self=True):

@as_filter
@contextfilter
def read_from_command(ctx, cmd, *, shell=True, check=True, encoding="utf-8", relative_self=True):
def read_from_command(
ctx, cmd, *, shell=True, check=True, encoding="utf-8", relative_self=True
):
if relative_self:
script = "cd {}; {}".format(os.path.dirname(ctx.name) or ".", cmd)
else:
Expand All @@ -32,6 +35,11 @@ def read_from_command(ctx, cmd, *, shell=True, check=True, encoding="utf-8", rel
check=check,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True
text=True,
)
return p.stdout


@as_filter
def strip_ansi_escape_sequence(text, *, _rx=re.compile(r"\x1b\[\d+;?\d*m")):
return _rx.sub("", text)
2 changes: 1 addition & 1 deletion misc/readme.rst.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ available info (extensions and additional modules)

.. code-block::

{{"kamidana --list-info"|read_from_command|indent(2)}}
{{"kamidana --list-info"|read_from_command|indent(2)|strip_ansi_escape_sequence}}

0 comments on commit a23bf47

Please sign in to comment.