diff options
author | Jonathan Slenders <jonathan@slenders.be> | 2017-05-01 12:12:19 +0200 |
---|---|---|
committer | Jonathan Slenders <jonathan@slenders.be> | 2017-05-01 12:12:23 +0200 |
commit | 5e296c52fa04e23ca68766b563213c06e62a06fd (patch) | |
tree | 0408cef4f8e4a1da5f203bf5801e1d42f8b0012f /tests | |
parent | e7036d50aa964910e9bc14ce4c7588b82fe8aac8 (diff) |
Support for \001 and \002 in ANSI string.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_formatted_text.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/test_formatted_text.py b/tests/test_formatted_text.py index f67ceee8..17fe42dd 100644 --- a/tests/test_formatted_text.py +++ b/tests/test_formatted_text.py @@ -1,5 +1,5 @@ from __future__ import unicode_literals -from prompt_toolkit.layout.formatted_text import HTML, to_formatted_text +from prompt_toolkit.layout.formatted_text import HTML, ANSI, to_formatted_text def test_basic_html(): @@ -33,3 +33,26 @@ def test_html_with_fg_bg(): ('fg:#ff0000 bg:ansired', 'hello '), ('class:world fg:ansiblue bg:ansired', 'world'), ] + + +def test_ansi_formatting(): + value = ANSI('\x1b[32mHe\x1b[45mllo') + + assert to_formatted_text(value) == [ + ('#ansidarkgreen', 'H'), + ('#ansidarkgreen', 'e'), + ('#ansidarkgreen bg:#ansipurple', 'l'), + ('#ansidarkgreen bg:#ansipurple', 'l'), + ('#ansidarkgreen bg:#ansipurple', 'o'), + ] + + # Zero width escapes. + value = ANSI('ab\001cd\002ef') + + assert to_formatted_text(value) == [ + ('', 'a'), + ('', 'b'), + ('[ZeroWidthEscape]', 'cd'), + ('', 'e'), + ('', 'f'), + ] |