mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-27 02:16:12 +01:00
23 lines
450 B
Python
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
|