| |
- char_len(ansi_text)
- Count the number of visible characters.
>>> char_len("[0;30;40mX[0m")
1
>>> char_len("[0;30;40mXY[0m")
2
>>> char_len("[0;30;40mX[0mY")
2
>>> char_len("hello")
5
>>> char_len("")
0
- char_slice(ansi_text, start, length)
- Slices a string with respect to ansi code sequences
Acts as if the ansi codes aren't there, slices the text from the
given start point to the given length and adds the codes back in.
>>> test_string = "abcde[30mfoo[31mbar[0mnormal"
>>> split_ansi_from_text(test_string)
['abcde', '\x1b[30m', 'foo', '\x1b[31m', 'bar', '\x1b[0m', 'normal']
>>> char_slice(test_string, 1, 3)
'bcd'
>>> char_slice(test_string, 5, 6)
'\x1b[30mfoo\x1b[31mbar'
>>> char_slice(test_string, 0, 8)
'abcde\x1b[30mfoo'
>>> char_slice(test_string, 4, 4)
'e\x1b[30mfoo'
>>> char_slice(test_string, 11, 100)
'\x1b[0mnormal'
>>> char_slice(test_string, 9, 100)
'\x1b[31mar\x1b[0mnormal'
>>> char_slice(test_string, 9, 4)
'\x1b[31mar\x1b[0mno'
- split_ansi_from_text(ansi_text)
- text_with_fg_bg_attr(ansi_text)
- # For information on the ANSI codes see
# githttp://en.wikipedia.org/wiki/ANSI_escape_code
|