Skip to content

Commit

Permalink
ansi_escape_senquences -> ansi_escape_sequences (#53)
Browse files Browse the repository at this point in the history
* ansi_escape_senquences -> ansi_escape_sequences

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Add backwards compatibility.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* And fix the alias so it gets imported as expected.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
clalancette authored Aug 27, 2019
1 parent 8ba7874 commit f05df24
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion osrf_pycommon/process_utils/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def execute_process(cmd, cwd=None, env=None, shell=False, emulate_tty=False):
If you want to ensure there is no color in the output from an executed
process, then use this function:
:py:func:`osrf_pycommon.terminal_color.remove_ansi_escape_senquences`
:py:func:`osrf_pycommon.terminal_color.remove_ansi_escape_sequences`
Exceptions can be raised by functions called by the implementation,
for example, :py:class:`subprocess.Popen` can raise an :py:exc:`OSError`
Expand Down
2 changes: 2 additions & 0 deletions osrf_pycommon/terminal_color/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"""

from .ansi_re import remove_ansi_escape_senquences
from .ansi_re import remove_ansi_escape_sequences
from .ansi_re import split_by_ansi_escape_sequence

from .impl import ansi
Expand All @@ -168,6 +169,7 @@
'print_ansi_color_win32',
'print_color',
'remove_ansi_escape_senquences',
'remove_ansi_escape_sequences',
'sanitize',
'split_by_ansi_escape_sequence',
'test_colors',
Expand Down
6 changes: 5 additions & 1 deletion osrf_pycommon/terminal_color/ansi_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ def split_by_ansi_escape_sequence(string, include_delimiters=False):
return _ansi_re.split(string)


def remove_ansi_escape_senquences(string):
def remove_ansi_escape_sequences(string):
"""
Removes any ansi escape sequences found in the given string and returns it.
"""
global _ansi_re
return _ansi_re.sub('', string)


# Backwards compatibility
remove_ansi_escape_senquences = remove_ansi_escape_sequences
8 changes: 4 additions & 4 deletions tests/unit/test_terminal_color/test_ansi_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def test_split_by_ansi_escape_sequence(self):
expected = ["", "red ", "bold red ", "normal ", "red bg"]
self.assertEqual(expected, split_ansi(self.test_str, False))

def test_remove_ansi_escape_senquences(self):
remove_ansi = ansi_re.remove_ansi_escape_senquences
def test_remove_ansi_escape_sequences(self):
remove_ansi = ansi_re.remove_ansi_escape_sequences
expected = "red bold red normal red bg"
self.assertEqual(expected, remove_ansi(self.test_str))

def test_remove_ansi_escape_senquences_false_positives(self):
remove_ansi = ansi_re.remove_ansi_escape_senquences
def test_remove_ansi_escape_sequences_false_positives(self):
remove_ansi = ansi_re.remove_ansi_escape_sequences
false_positive = "Should not match: \1xb[1234m \033[m \1xb[3Om"
self.assertEqual(false_positive, remove_ansi(false_positive))

0 comments on commit f05df24

Please sign in to comment.