Skip to content
Myr

Merge pull request #1299 from sekenned/7.x

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Update regular expression for strip_ansi to handle edge cases

authored by David Lord · committed by GitHub · parents bc6eb98, d3ed408 · Browse files · 3 files+41 added−26 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+41 added−26 removed

  • tests:+38 added−25 removed
  • other:+3 added−1 removed

3 files+41 added−26 removed

modified:click/_compat.py+1 added-1 removed
14 unmodified lines
15WIN = sys.platform.startswith('win') and not APP_ENGINE and not MSYS216DEFAULT_COLUMNS = 80171819_ansi_re = re.compile(r'\033\[((?:\d|;)*)([a-zA-Z])')19_ansi_re = re.compile(r"\033\[[;?0-9]*[a-zA-Z]")202122def get_filesystem_encoding():23 return sys.getfilesystemencoding() or sys.getdefaultencoding()
692 unmodified lines
modified:tests/test_utils.py+38 added-25 removed
48 unmodified lines
49 click.echo(u'hello', file=f)50 assert f.getvalue() == u'hello\n'515253def test_styling():54 examples = [55 ('x', dict(fg='black'), '\x1b[30mx\x1b[0m'),56 ('x', dict(fg='red'), '\x1b[31mx\x1b[0m'),57 ('x', dict(fg='green'), '\x1b[32mx\x1b[0m'),58 ('x', dict(fg='yellow'), '\x1b[33mx\x1b[0m'),59 ('x', dict(fg='blue'), '\x1b[34mx\x1b[0m'),60 ('x', dict(fg='magenta'), '\x1b[35mx\x1b[0m'),61 ('x', dict(fg='cyan'), '\x1b[36mx\x1b[0m'),62 ('x', dict(fg='white'), '\x1b[37mx\x1b[0m'),63 ('x', dict(bg='black'), '\x1b[40mx\x1b[0m'),64 ('x', dict(bg='red'), '\x1b[41mx\x1b[0m'),65 ('x', dict(bg='green'), '\x1b[42mx\x1b[0m'),66 ('x', dict(bg='yellow'), '\x1b[43mx\x1b[0m'),67 ('x', dict(bg='blue'), '\x1b[44mx\x1b[0m'),68 ('x', dict(bg='magenta'), '\x1b[45mx\x1b[0m'),69 ('x', dict(bg='cyan'), '\x1b[46mx\x1b[0m'),70 ('x', dict(bg='white'), '\x1b[47mx\x1b[0m'),71 ('foo bar', dict(blink=True), '\x1b[5mfoo bar\x1b[0m'),72 ('foo bar', dict(underline=True), '\x1b[4mfoo bar\x1b[0m'),73 ('foo bar', dict(bold=True), '\x1b[1mfoo bar\x1b[0m'),74 ('foo bar', dict(dim=True), '\x1b[2mfoo bar\x1b[0m'),53@pytest.mark.parametrize(54 ("styles", "ref"),55 [56 ({"fg": "black"}, "\x1b[30mx y\x1b[0m"),57 ({"fg": "red"}, "\x1b[31mx y\x1b[0m"),58 ({"fg": "green"}, "\x1b[32mx y\x1b[0m"),59 ({"fg": "yellow"}, "\x1b[33mx y\x1b[0m"),60 ({"fg": "blue"}, "\x1b[34mx y\x1b[0m"),61 ({"fg": "magenta"}, "\x1b[35mx y\x1b[0m"),62 ({"fg": "cyan"}, "\x1b[36mx y\x1b[0m"),63 ({"fg": "white"}, "\x1b[37mx y\x1b[0m"),64 ({"bg": "black"}, "\x1b[40mx y\x1b[0m"),65 ({"bg": "red"}, "\x1b[41mx y\x1b[0m"),66 ({"bg": "green"}, "\x1b[42mx y\x1b[0m"),67 ({"bg": "yellow"}, "\x1b[43mx y\x1b[0m"),68 ({"bg": "blue"}, "\x1b[44mx y\x1b[0m"),69 ({"bg": "magenta"}, "\x1b[45mx y\x1b[0m"),70 ({"bg": "cyan"}, "\x1b[46mx y\x1b[0m"),71 ({"bg": "white"}, "\x1b[47mx y\x1b[0m"),72 ({"blink": True}, "\x1b[5mx y\x1b[0m"),73 ({"underline": True}, "\x1b[4mx y\x1b[0m"),74 ({"bold": True}, "\x1b[1mx y\x1b[0m"),75 ({"dim": True}, "\x1b[2mx y\x1b[0m"),76 ],77)78def test_styling(styles, ref):79 assert click.style("x y", **styles) == ref80 assert click.unstyle(ref) == "x y"818283@pytest.mark.parametrize(84 ("text", "expect"),85 [86 ("\x1b[?25lx y\x1b[?25h", "x y"),87 ]76 for text, styles, ref in examples:77 assert click.style(text, **styles) == ref78 assert click.unstyle(ref) == text88)89def test_unstyle_other_ansi(text, expect):90 assert click.unstyle(text) == expect91929394def test_filename_formatting():95 assert click.format_filename(b'foo.txt') == 'foo.txt'96 assert click.format_filename(b'/x/foo.txt') == '/x/foo.txt'97 assert click.format_filename(u'/x/foo.txt') == '/x/foo.txt'
222 unmodified lines
modified:CHANGES.rst+2 added
7 unmodified lines
8- Fix PyPI package name, "click" is lowercase again.9- Fix link in ``unicode_literals`` error message. :pr:`1151`10- Add support for colored output on UNIX Jupyter notebooks.11 :issue:`1185`12- Operations that strip ANSI controls will strip the cursor hide/show13 sequences. :issue:`1216`14- Remove unused compat shim for ``bytes``. :pr:`1195`15- Expand testing around termui, especially getchar on Windows.16 :issue:`1116`17- Fix output on Windows Python 2.7 built with MSVC 14. :pr:`1342`
554 unmodified lines