Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/menu
diff options
context:
space:
mode:
authorWu Xiaotian <yetist@gmail.com>2023-07-31 15:39:06 +0800
committerGitHub <noreply@github.com>2023-07-31 09:39:06 +0200
commitd878496a2fb9e3c7f48261f866cb285dfa987298 (patch)
tree945264d17e5caf012ca3406b7cdfbdf46ecd2e9e /archinstall/lib/menu
parent9cbb2b75940e3aad1a0236662c45437d70eac1af (diff)
Improve the Chinese, Japanese and Korean text menu layout (#1945)
Before this patch, menus in Korean language would not be aligned: ``` Archinstall 언어 Korean (71%) > Mirrors Locales Defined Disk configuration 부트로더 Systemd-boot 스왑 True ``` After apply this patch, menus in Korean language are aligned: ``` Archinstall 언어 Korean (71%) > Mirrors Locales Defined Disk configuration 부트로더 Systemd-boot 스왑 True ```
Diffstat (limited to 'archinstall/lib/menu')
-rw-r--r--archinstall/lib/menu/abstract_menu.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/archinstall/lib/menu/abstract_menu.py b/archinstall/lib/menu/abstract_menu.py
index eee99747..f12d2b73 100644
--- a/archinstall/lib/menu/abstract_menu.py
+++ b/archinstall/lib/menu/abstract_menu.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+import unicodedata
from typing import Callable, Any, List, Iterator, Tuple, Optional, Dict, TYPE_CHECKING
@@ -9,6 +10,22 @@ 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__(
@@ -128,7 +145,7 @@ class Selector:
if current:
padding += 5
- description = str(self._description).ljust(padding, ' ')
+ description = cjkljust(str(self._description), padding, ' ')
current = current
else:
description = self._description