Skip to content

Commit 210329e

Browse files
authored
Add console font selection to Locales menu (#4469)
* Add console font selection to Locales menu Add a 4th menu item "Console font" to the Locales configuration, allowing users to select a console font for the target system. The selected font is written to /etc/vconsole.conf. If a terminus font (ter-*) is selected, the terminus-font package is automatically installed on the target system. * Switch list_console_fonts to pathlib and add @lru_cache Address svartkanin's review on #4469. Replace os.listdir + chained removesuffix with Path.glob('*.gz') + split('.')[0], and cache the result via lru_cache - the kbd consolefonts directory is static at runtime so re-scanning on every menu reopen was wasted I/O.
1 parent 9e05260 commit 210329e

6 files changed

Lines changed: 59 additions & 7 deletions

File tree

archinstall/lib/installer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,12 +1982,10 @@ def chown(self, owner: str, path: str, options: list[str] | None = None) -> bool
19821982
def set_vconsole(self, locale_config: LocaleConfiguration) -> None:
19831983
# use the already set kb layout
19841984
kb_vconsole: str = locale_config.kb_layout
1985-
# this is the default used in ISO other option for hdpi screens TER16x32
1986-
# can be checked using
1987-
# zgrep "CONFIG_FONT" /proc/config.gz
1988-
# https://wiki.archlinux.org/title/Linux_console#Fonts
1985+
font_vconsole = locale_config.console_font
19891986

1990-
font_vconsole = 'default8x16'
1987+
if font_vconsole.startswith('ter-'):
1988+
self.pacman.strap(['terminus-font'])
19911989

19921990
# Ensure /etc exists
19931991
vconsole_dir: Path = self.target / 'etc'

archinstall/lib/locale/locale_menu.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import override
22

3-
from archinstall.lib.locale.utils import list_keyboard_languages, list_locales, set_kb_layout
3+
from archinstall.lib.locale.utils import list_console_fonts, list_keyboard_languages, list_locales, set_kb_layout
44
from archinstall.lib.menu.abstract_menu import AbstractSubMenu
55
from archinstall.lib.menu.helpers import Selection
66
from archinstall.lib.models.locale import LocaleConfiguration
@@ -47,6 +47,13 @@ def _define_menu_options(self) -> list[MenuItem]:
4747
preview_action=lambda item: item.get_value(),
4848
key='sys_enc',
4949
),
50+
MenuItem(
51+
text=tr('Console font'),
52+
action=select_console_font,
53+
value=self._locale_conf.console_font,
54+
preview_action=lambda item: item.get_value(),
55+
key='console_font',
56+
),
5057
]
5158

5259
@override
@@ -140,3 +147,25 @@ async def select_kb_layout(preset: str | None = None) -> str | None:
140147
return preset
141148
case _:
142149
raise ValueError('Unhandled return type')
150+
151+
152+
async def select_console_font(preset: str | None = None) -> str | None:
153+
fonts = list_console_fonts()
154+
155+
items = [MenuItem(f, value=f) for f in fonts]
156+
group = MenuItemGroup(items, sort_items=False)
157+
group.set_focus_by_value(preset)
158+
159+
result = await Selection[str](
160+
header=tr('Console font'),
161+
group=group,
162+
enable_filter=True,
163+
).show()
164+
165+
match result.type_:
166+
case ResultType.Selection:
167+
return result.get_value()
168+
case ResultType.Skip:
169+
return preset
170+
case _:
171+
raise ValueError('Unhandled return type')

archinstall/lib/locale/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from functools import lru_cache
2+
from pathlib import Path
3+
14
from archinstall.lib.command import SysCommand
25
from archinstall.lib.exceptions import ServiceException, SysCallError
36
from archinstall.lib.output import error
@@ -26,6 +29,13 @@ def list_locales() -> list[str]:
2629
return locales
2730

2831

32+
@lru_cache
33+
def list_console_fonts() -> list[str]:
34+
directory = Path('/usr/share/kbd/consolefonts')
35+
fonts = {path.name.split('.')[0] for path in directory.glob('*.gz')}
36+
return sorted(fonts)
37+
38+
2939
def list_x11_keyboard_languages() -> list[str]:
3040
return (
3141
SysCommand(

archinstall/lib/models/locale.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ class LocaleConfiguration:
1010
kb_layout: str
1111
sys_lang: str
1212
sys_enc: str
13+
# this is the default used in ISO other option for hdpi screens TER16x32
14+
# can be checked using
15+
# zgrep "CONFIG_FONT" /proc/config.gz
16+
# https://wiki.archlinux.org/title/Linux_console#Font
17+
console_font: str = 'default8x16'
1318

1419
@classmethod
1520
def default(cls) -> Self:
@@ -23,12 +28,14 @@ def json(self) -> dict[str, str]:
2328
'kb_layout': self.kb_layout,
2429
'sys_lang': self.sys_lang,
2530
'sys_enc': self.sys_enc,
31+
'console_font': self.console_font,
2632
}
2733

2834
def preview(self) -> str:
2935
output = '{}: {}\n'.format(tr('Keyboard layout'), self.kb_layout)
3036
output += '{}: {}\n'.format(tr('Locale language'), self.sys_lang)
31-
output += '{}: {}'.format(tr('Locale encoding'), self.sys_enc)
37+
output += '{}: {}\n'.format(tr('Locale encoding'), self.sys_enc)
38+
output += '{}: {}'.format(tr('Console font'), self.console_font)
3239
return output
3340

3441
def _load_config(self, args: dict[str, str]) -> None:
@@ -38,6 +45,8 @@ def _load_config(self, args: dict[str, str]) -> None:
3845
self.sys_enc = args['sys_enc']
3946
if 'kb_layout' in args:
4047
self.kb_layout = args['kb_layout']
48+
if 'console_font' in args:
49+
self.console_font = args['console_font']
4150

4251
@classmethod
4352
def parse_arg(cls, args: dict[str, Any]) -> Self:

archinstall/locales/base.pot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ msgstr ""
252252
msgid "Locale encoding"
253253
msgstr ""
254254

255+
msgid "Console font"
256+
msgstr ""
257+
255258
msgid "Drive(s)"
256259
msgstr ""
257260

archinstall/locales/uk/LC_MESSAGES/base.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ msgstr "Мова локалізації"
256256
msgid "Locale encoding"
257257
msgstr "Кодування локалізації"
258258

259+
msgid "Console font"
260+
msgstr "Шрифт консолі"
261+
259262
msgid "Drive(s)"
260263
msgstr "Диск(и)"
261264

0 commit comments

Comments
 (0)