Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions outputformat/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def linetitle(txt, style="-", color=False, cmap="cool", bold=False, return_str=F
outputstring = ""

txt = str(txt)
txt_size = len(txt)
txt_size = ouf.tools.real_string_length(txt)
style = str(style)

# bl = bottom left
Expand Down Expand Up @@ -114,7 +114,7 @@ def boxtitle(txt, style="-", return_str=False, color=False, cmap="cool", bold=Fa
"""

txt = str(txt)
txt_size = len(txt)
txt_size = ouf.tools.real_string_length(txt)
style = str(style)

if style in ["line", "-"]:
Expand Down
13 changes: 13 additions & 0 deletions outputformat/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from outputformat import emoji
import colorsys
from random import random
from re import sub


def prepare_data(input_data, precision):
Expand Down Expand Up @@ -203,3 +204,15 @@ def parse_color(color, cmap):
color = (random(), default_saturation, 1)

return color

def real_string_length(txt):
"""Compute the length of the strings without the ANSI escape sequences

Returns
-------
int
real length of the string txt

"""
pattern = "\x1b\[[;\d]*m"
return len(sub(pattern,"",txt))