Is it possible to get width of a string as it appears on the terminal?
Assuming the terminal supports ansi-escpace sequences, this
s = u"\u001b[31m" +"foo" + u"\u001b[0m"
print(len(s))
print(s)
will print
12
foo
with the second line in red. Given only the already concatenated s
, is there an easy way to get the width of it (3
in this case)?
Also \t
is counted as 1
character, but thats easier to account for.