Skip to content

Commit

Permalink
use cjk alignment function to show menu
Browse files Browse the repository at this point in the history
  • Loading branch information
yetist committed Aug 15, 2023
1 parent db4450c commit 6fdb290
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions archinstall/lib/menu/abstract_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,12 @@

from .menu import Menu, MenuSelectionType
from ..output import error
from ..output import cjk_ljust
from ..translationhandler import TranslationHandler, Language

if TYPE_CHECKING:
_: Any

def count_cjk_chars(string):
"Count the total number of CJK characters contained in a string"
return sum(unicodedata.east_asian_width(c) in 'FW' for c in string)

def cjkljust(string, width, fillbyte=' '):
"""Support left alignment of Chinese, Japanese, Korean text
>>> cjkljust('Hello', 15, '*')
'Hello**********'
>>> cjkljust('你好', 15, '*')
'你好***********'
>>> cjkljust('안녕하세요', 15, '*')
'안녕하세요*****'
>>> cjkljust('こんにちは', 15, '*')
'こんにちは*****'
"""
return string.ljust(width - count_cjk_chars(string), fillbyte)

class Selector:
def __init__(
self,
Expand Down Expand Up @@ -145,7 +129,7 @@ def menu_text(self, padding: int = 0) -> str:

if current:
padding += 5
description = cjkljust(str(self._description), padding, ' ')
description = cjk_ljust(str(self._description), padding, ' ')
current = current
else:
description = self._description
Expand Down

0 comments on commit 6fdb290

Please sign in to comment.