Skip to content

Commit 2334e36

Browse files
committed
Move font state from module singleton into TranslationHandler
1 parent 7a53618 commit 2334e36

2 files changed

Lines changed: 20 additions & 27 deletions

File tree

archinstall/lib/translationhandler.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ def json(self) -> str:
4141
_ENV_FONT = os.environ.get('FONT')
4242

4343

44-
class _FontState:
45-
def __init__(self) -> None:
46-
self.font_backup: Path | None = None
47-
self.cmap_backup: Path | None = None
48-
self.using_env_font: bool = False
49-
50-
51-
_font_state = _FontState()
52-
53-
5444
def _set_console_font(font_name: str | None) -> bool:
5545
"""
5646
Set the console font via setfont.
@@ -75,37 +65,40 @@ def _save_console_font() -> None:
7565
cmap_fd, cmap_path = tempfile.mkstemp(prefix='archinstall_cmap_')
7666
os.close(font_fd)
7767
os.close(cmap_fd)
78-
_font_state.font_backup = Path(font_path)
79-
_font_state.cmap_backup = Path(cmap_path)
80-
SysCommand(f'setfont -O {_font_state.font_backup} -om {_font_state.cmap_backup}')
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}')
8171
except SysCallError as err:
8272
debug(f'Failed to save console font: {err}')
83-
_font_state.font_backup = None
84-
_font_state.cmap_backup = None
73+
translation_handler._font_backup = None
74+
translation_handler._cmap_backup = None
8575

8676

8777
def _restore_console_font() -> None:
8878
"""Restore console font (with unicode map) and console map from backup."""
89-
if _font_state.font_backup is None or not _font_state.font_backup.exists():
79+
if translation_handler._font_backup is None or not translation_handler._font_backup.exists():
9080
return
9181

92-
args = str(_font_state.font_backup)
93-
if _font_state.cmap_backup is not None and _font_state.cmap_backup.exists():
94-
args += f' -m {_font_state.cmap_backup}'
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}'
9585
_set_console_font(args)
9686

97-
_font_state.font_backup.unlink(missing_ok=True)
98-
_font_state.font_backup = None
99-
if _font_state.cmap_backup is not None:
100-
_font_state.cmap_backup.unlink(missing_ok=True)
101-
_font_state.cmap_backup = None
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
10292

10393

10494
class TranslationHandler:
10595
def __init__(self) -> None:
10696
self._base_pot = 'base.pot'
10797
self._languages = 'languages.json'
10898
self._active_language: Language | None = None
99+
self._font_backup: Path | None = None
100+
self._cmap_backup: Path | None = None
101+
self._using_env_font: bool = False
109102

110103
self._total_messages = self._get_total_active_messages()
111104
self._translated_languages = self._get_translations()
@@ -213,7 +206,7 @@ def activate(self, language: Language, set_font: bool = True) -> None:
213206
language.translation.install()
214207
self._active_language = language
215208

216-
if set_font and not _font_state.using_env_font:
209+
if set_font and not self._using_env_font:
217210
_set_console_font(language.console_font)
218211

219212
def _get_locales_dir(self) -> Path:

archinstall/tui/ui/components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ def on_mount(self) -> None:
12561256

12571257
if th._ENV_FONT:
12581258
if th._set_console_font(th._ENV_FONT):
1259-
th._font_state.using_env_font = True
1259+
th.translation_handler._using_env_font = True
12601260
else:
12611261
debug(f'FONT={th._ENV_FONT} could not be set, using language font mapping')
12621262
if th.translation_handler.active_font:
@@ -1298,7 +1298,7 @@ def run(self, main: InstanceRunnable[ValueT] | Callable[[], Awaitable[ValueT]])
12981298
TApp.app = _AppInstance(main)
12991299
result: ValueT | Exception | None = TApp.app.run()
13001300

1301-
if th._ENV_FONT and not th._font_state.using_env_font:
1301+
if th._ENV_FONT and not th.translation_handler._using_env_font:
13021302
info(f'FONT={th._ENV_FONT} could not be set, using language font mapping')
13031303

13041304
if isinstance(result, Exception):

0 commit comments

Comments
 (0)