1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-14 16:26:13 +01:00
github.com_openSUSE_osc/osc/output/widechar.py

23 lines
450 B
Python

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