1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-27 18:26:15 +01:00
github.com_openSUSE_osc/osc/output/widechar.py

23 lines
450 B
Python
Raw Normal View History

import unicodedata
def wc_width(text):
result = 0
for char in text:
if unicodedata.east_asian_width(char) in ("F", "W"):
result += 2
else:
result += 1
return result
def wc_ljust(text, width, fillchar=" "):
text_width = wc_width(text)
fill_width = wc_width(fillchar)
while text_width + fill_width <= width:
text += fillchar
text_width += fill_width
return text