[New-bugs-announce] [issue24574] ANSI escape sequences breaking string justification

Krzysztof Słychań report at bugs.python.org
Mon Jul 6 11:21:39 CEST 2015


New submission from Krzysztof Słychań:

Strings containing ANSI escape sequences are not justified if the length including escape sequences exceeds the field width.

Testcase:
Let's make a string with escape sequences - bold, for example:
>>> string = '\033[01m' + 'bold' + '\033[0m'

String length will be larger than the length of a displayed string
(should be 4, is 13). Looks like '\03' is counted as escape sequence,
but '3[01m' and '3[0m' are not, and count into the string length.
>>> len(string)
13

Try to print justified string - should be centered between '|' signs
>>> print('|' + string.center(10) + '|')
|bold|
Does not work at all...

If field length is larger than len(string), justification works
>>> print('|' + string.center(30) + '|')
|        bold         |

----------
components: Interpreter Core
messages: 246351
nosy: Krzysztof Słychań
priority: normal
severity: normal
status: open
title: ANSI escape sequences breaking string justification
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24574>
_______________________________________


More information about the New-bugs-announce mailing list