@@ -41,56 +41,6 @@ def json(self) -> str:
4141_ENV_FONT = os .environ .get ('FONT' )
4242
4343
44- def _set_console_font (font_name : str | None ) -> bool :
45- """
46- Set the console font via setfont.
47- If font_name is None, sets default8x16.
48- On failure, keeps the current font unchanged.
49- Returns True on success, False on failure.
50- """
51- target = font_name or _DEFAULT_FONT
52-
53- try :
54- SysCommand (f'setfont { target } ' )
55- return True
56- except SysCallError as err :
57- debug (f'Failed to set console font { target } : { err } ' )
58- return False
59-
60-
61- def save_console_font () -> None :
62- """Save the current console font (with unicode map) and console map to temp files."""
63- try :
64- font_fd , font_path = tempfile .mkstemp (prefix = 'archinstall_font_' )
65- cmap_fd , cmap_path = tempfile .mkstemp (prefix = 'archinstall_cmap_' )
66- os .close (font_fd )
67- os .close (cmap_fd )
68- translation_handler ._font_backup = Path (font_path )
69- translation_handler ._cmap_backup = Path (cmap_path )
70- SysCommand (f'setfont -O { translation_handler ._font_backup } -om { translation_handler ._cmap_backup } ' )
71- except SysCallError as err :
72- debug (f'Failed to save console font: { err } ' )
73- translation_handler ._font_backup = None
74- translation_handler ._cmap_backup = None
75-
76-
77- def restore_console_font () -> None :
78- """Restore console font (with unicode map) and console map from backup."""
79- if translation_handler ._font_backup is None or not translation_handler ._font_backup .exists ():
80- return
81-
82- args = str (translation_handler ._font_backup )
83- if translation_handler ._cmap_backup is not None and translation_handler ._cmap_backup .exists ():
84- args += f' -m { translation_handler ._cmap_backup } '
85- _set_console_font (args )
86-
87- translation_handler ._font_backup .unlink (missing_ok = True )
88- translation_handler ._font_backup = None
89- if translation_handler ._cmap_backup is not None :
90- translation_handler ._cmap_backup .unlink (missing_ok = True )
91- translation_handler ._cmap_backup = None
92-
93-
9444class TranslationHandler :
9545 def __init__ (self ) -> None :
9646 self ._base_pot = 'base.pot'
@@ -113,6 +63,57 @@ def active_font(self) -> str | None:
11363 return self ._active_language .console_font
11464 return None
11565
66+ def _set_font (self , font_name : str | None ) -> bool :
67+ """Set the console font via setfont. Only runs on ISO. Returns True on success."""
68+ from archinstall .lib .utils .util import running_from_iso
69+
70+ if not running_from_iso ():
71+ return False
72+
73+ target = font_name or _DEFAULT_FONT
74+ try :
75+ SysCommand (f'setfont { target } ' )
76+ return True
77+ except SysCallError as err :
78+ debug (f'Failed to set console font { target } : { err } ' )
79+ return False
80+
81+ def save_console_font (self ) -> None :
82+ """Save the current console font (with unicode map) and console map to temp files."""
83+ from archinstall .lib .utils .util import running_from_iso
84+
85+ if not running_from_iso ():
86+ return
87+
88+ try :
89+ font_fd , font_path = tempfile .mkstemp (prefix = 'archinstall_font_' )
90+ cmap_fd , cmap_path = tempfile .mkstemp (prefix = 'archinstall_cmap_' )
91+ os .close (font_fd )
92+ os .close (cmap_fd )
93+ self ._font_backup = Path (font_path )
94+ self ._cmap_backup = Path (cmap_path )
95+ SysCommand (f'setfont -O { self ._font_backup } -om { self ._cmap_backup } ' )
96+ except SysCallError as err :
97+ debug (f'Failed to save console font: { err } ' )
98+ self ._font_backup = None
99+ self ._cmap_backup = None
100+
101+ def restore_console_font (self ) -> None :
102+ """Restore console font (with unicode map) and console map from backup."""
103+ if self ._font_backup is None or not self ._font_backup .exists ():
104+ return
105+
106+ args = str (self ._font_backup )
107+ if self ._cmap_backup is not None and self ._cmap_backup .exists ():
108+ args += f' -m { self ._cmap_backup } '
109+ self ._set_font (args )
110+
111+ self ._font_backup .unlink (missing_ok = True )
112+ self ._font_backup = None
113+ if self ._cmap_backup is not None :
114+ self ._cmap_backup .unlink (missing_ok = True )
115+ self ._cmap_backup = None
116+
116117 def _get_translations (self ) -> list [Language ]:
117118 """
118119 Load all translated languages and return a list of such
@@ -207,7 +208,7 @@ def activate(self, language: Language, set_font: bool = True) -> None:
207208 self ._active_language = language
208209
209210 if set_font and not self ._using_env_font :
210- _set_console_font (language .console_font )
211+ self . _set_font (language .console_font )
211212
212213 def apply_console_font (self ) -> None :
213214 """Apply console font from FONT env var or active language mapping.
@@ -217,16 +218,16 @@ def apply_console_font(self) -> None:
217218 If FONT is not set, use active language font.
218219 """
219220 if _ENV_FONT :
220- if _set_console_font (_ENV_FONT ):
221+ if self . _set_font (_ENV_FONT ):
221222 self ._using_env_font = True
222223 debug (f'Console font set from FONT env var: { _ENV_FONT } ' )
223224 else :
224225 debug (f'FONT={ _ENV_FONT } could not be set, falling back to language font mapping' )
225226 if self .active_font :
226- _set_console_font (self .active_font )
227+ self . _set_font (self .active_font )
227228 debug (f'Console font set from language mapping: { self .active_font } ' )
228229 elif self .active_font :
229- _set_console_font (self .active_font )
230+ self . _set_font (self .active_font )
230231 debug (f'Console font set from language mapping: { self .active_font } ' )
231232
232233 def _get_locales_dir (self ) -> Path :
0 commit comments