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.
This commit is contained in:
Softer 2026-04-27 02:30:20 +03:00 committed by GitHub
parent 9e05260df5
commit 210329ed80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 59 additions and 7 deletions

View File

@ -1982,12 +1982,10 @@ class Installer:
def set_vconsole(self, locale_config: LocaleConfiguration) -> None: def set_vconsole(self, locale_config: LocaleConfiguration) -> None:
# use the already set kb layout # use the already set kb layout
kb_vconsole: str = locale_config.kb_layout kb_vconsole: str = locale_config.kb_layout
# this is the default used in ISO other option for hdpi screens TER16x32 font_vconsole = locale_config.console_font
# can be checked using
# zgrep "CONFIG_FONT" /proc/config.gz
# https://wiki.archlinux.org/title/Linux_console#Fonts
font_vconsole = 'default8x16' if font_vconsole.startswith('ter-'):
self.pacman.strap(['terminus-font'])
# Ensure /etc exists # Ensure /etc exists
vconsole_dir: Path = self.target / 'etc' vconsole_dir: Path = self.target / 'etc'

View File

@ -1,6 +1,6 @@
from typing import override from typing import override
from archinstall.lib.locale.utils import list_keyboard_languages, list_locales, set_kb_layout from archinstall.lib.locale.utils import list_console_fonts, list_keyboard_languages, list_locales, set_kb_layout
from archinstall.lib.menu.abstract_menu import AbstractSubMenu from archinstall.lib.menu.abstract_menu import AbstractSubMenu
from archinstall.lib.menu.helpers import Selection from archinstall.lib.menu.helpers import Selection
from archinstall.lib.models.locale import LocaleConfiguration from archinstall.lib.models.locale import LocaleConfiguration
@ -47,6 +47,13 @@ class LocaleMenu(AbstractSubMenu[LocaleConfiguration]):
preview_action=lambda item: item.get_value(), preview_action=lambda item: item.get_value(),
key='sys_enc', key='sys_enc',
), ),
MenuItem(
text=tr('Console font'),
action=select_console_font,
value=self._locale_conf.console_font,
preview_action=lambda item: item.get_value(),
key='console_font',
),
] ]
@override @override
@ -140,3 +147,25 @@ async def select_kb_layout(preset: str | None = None) -> str | None:
return preset return preset
case _: case _:
raise ValueError('Unhandled return type') raise ValueError('Unhandled return type')
async def select_console_font(preset: str | None = None) -> str | None:
fonts = list_console_fonts()
items = [MenuItem(f, value=f) for f in fonts]
group = MenuItemGroup(items, sort_items=False)
group.set_focus_by_value(preset)
result = await Selection[str](
header=tr('Console font'),
group=group,
enable_filter=True,
).show()
match result.type_:
case ResultType.Selection:
return result.get_value()
case ResultType.Skip:
return preset
case _:
raise ValueError('Unhandled return type')

View File

@ -1,3 +1,6 @@
from functools import lru_cache
from pathlib import Path
from archinstall.lib.command import SysCommand from archinstall.lib.command import SysCommand
from archinstall.lib.exceptions import ServiceException, SysCallError from archinstall.lib.exceptions import ServiceException, SysCallError
from archinstall.lib.output import error from archinstall.lib.output import error
@ -26,6 +29,13 @@ def list_locales() -> list[str]:
return locales return locales
@lru_cache
def list_console_fonts() -> list[str]:
directory = Path('/usr/share/kbd/consolefonts')
fonts = {path.name.split('.')[0] for path in directory.glob('*.gz')}
return sorted(fonts)
def list_x11_keyboard_languages() -> list[str]: def list_x11_keyboard_languages() -> list[str]:
return ( return (
SysCommand( SysCommand(

View File

@ -10,6 +10,11 @@ class LocaleConfiguration:
kb_layout: str kb_layout: str
sys_lang: str sys_lang: str
sys_enc: str sys_enc: str
# this is the default used in ISO other option for hdpi screens TER16x32
# can be checked using
# zgrep "CONFIG_FONT" /proc/config.gz
# https://wiki.archlinux.org/title/Linux_console#Font
console_font: str = 'default8x16'
@classmethod @classmethod
def default(cls) -> Self: def default(cls) -> Self:
@ -23,12 +28,14 @@ class LocaleConfiguration:
'kb_layout': self.kb_layout, 'kb_layout': self.kb_layout,
'sys_lang': self.sys_lang, 'sys_lang': self.sys_lang,
'sys_enc': self.sys_enc, 'sys_enc': self.sys_enc,
'console_font': self.console_font,
} }
def preview(self) -> str: def preview(self) -> str:
output = '{}: {}\n'.format(tr('Keyboard layout'), self.kb_layout) output = '{}: {}\n'.format(tr('Keyboard layout'), self.kb_layout)
output += '{}: {}\n'.format(tr('Locale language'), self.sys_lang) output += '{}: {}\n'.format(tr('Locale language'), self.sys_lang)
output += '{}: {}'.format(tr('Locale encoding'), self.sys_enc) output += '{}: {}\n'.format(tr('Locale encoding'), self.sys_enc)
output += '{}: {}'.format(tr('Console font'), self.console_font)
return output return output
def _load_config(self, args: dict[str, str]) -> None: def _load_config(self, args: dict[str, str]) -> None:
@ -38,6 +45,8 @@ class LocaleConfiguration:
self.sys_enc = args['sys_enc'] self.sys_enc = args['sys_enc']
if 'kb_layout' in args: if 'kb_layout' in args:
self.kb_layout = args['kb_layout'] self.kb_layout = args['kb_layout']
if 'console_font' in args:
self.console_font = args['console_font']
@classmethod @classmethod
def parse_arg(cls, args: dict[str, Any]) -> Self: def parse_arg(cls, args: dict[str, Any]) -> Self:

View File

@ -252,6 +252,9 @@ msgstr ""
msgid "Locale encoding" msgid "Locale encoding"
msgstr "" msgstr ""
msgid "Console font"
msgstr ""
msgid "Drive(s)" msgid "Drive(s)"
msgstr "" msgstr ""

View File

@ -256,6 +256,9 @@ msgstr "Мова локалізації"
msgid "Locale encoding" msgid "Locale encoding"
msgstr "Кодування локалізації" msgstr "Кодування локалізації"
msgid "Console font"
msgstr "Шрифт консолі"
msgid "Drive(s)" msgid "Drive(s)"
msgstr "Диск(и)" msgstr "Диск(и)"