Try to restore original console font with setfont -O
This commit is contained in:
parent
92c990d917
commit
960bc1bae6
|
|
@ -2,11 +2,14 @@ import builtins
|
||||||
import gettext
|
import gettext
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import override
|
from typing import override
|
||||||
|
|
||||||
|
from archinstall.lib.command import SysCommand
|
||||||
|
from archinstall.lib.exceptions import SysCallError
|
||||||
|
from archinstall.lib.output import debug
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Language:
|
class Language:
|
||||||
|
|
@ -35,6 +38,8 @@ class Language:
|
||||||
|
|
||||||
_DEFAULT_FONT = 'default8x16'
|
_DEFAULT_FONT = 'default8x16'
|
||||||
_ENV_FONT = os.environ.get('FONT')
|
_ENV_FONT = os.environ.get('FONT')
|
||||||
|
_FONT_BACKUP = Path('/tmp/archinstall_font_backup')
|
||||||
|
_CMAP_BACKUP = Path('/tmp/archinstall_cmap_backup')
|
||||||
|
|
||||||
|
|
||||||
def _set_console_font(font_name: str | None) -> None:
|
def _set_console_font(font_name: str | None) -> None:
|
||||||
|
|
@ -45,15 +50,36 @@ def _set_console_font(font_name: str | None) -> None:
|
||||||
target = font_name or _DEFAULT_FONT
|
target = font_name or _DEFAULT_FONT
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(['setfont', target], capture_output=True, check=False, timeout=10)
|
SysCommand(f'setfont {target}')
|
||||||
if result.returncode != 0 and target != _DEFAULT_FONT:
|
except SysCallError as err:
|
||||||
subprocess.run(['setfont', _DEFAULT_FONT], capture_output=True, check=False, timeout=10)
|
debug(f'Failed to set console font {target}: {err}')
|
||||||
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
|
|
||||||
if target != _DEFAULT_FONT:
|
if target != _DEFAULT_FONT:
|
||||||
try:
|
try:
|
||||||
subprocess.run(['setfont', _DEFAULT_FONT], capture_output=True, check=False, timeout=10)
|
SysCommand(f'setfont {_DEFAULT_FONT}')
|
||||||
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
|
except SysCallError as err:
|
||||||
pass
|
debug(f'Failed to set default console font: {err}')
|
||||||
|
|
||||||
|
|
||||||
|
def _save_console_font() -> None:
|
||||||
|
"""Save the current console font (with unicode map) and console map to backup files."""
|
||||||
|
try:
|
||||||
|
SysCommand(f'setfont -O {_FONT_BACKUP} -om {_CMAP_BACKUP}')
|
||||||
|
except SysCallError as err:
|
||||||
|
debug(f'Failed to save console font: {err}')
|
||||||
|
|
||||||
|
|
||||||
|
def _restore_console_font() -> None:
|
||||||
|
"""Restore console font (with unicode map) and console map from backup, falling back to default8x16."""
|
||||||
|
if _FONT_BACKUP.exists():
|
||||||
|
args = str(_FONT_BACKUP)
|
||||||
|
if _CMAP_BACKUP.exists():
|
||||||
|
args += f' -m {_CMAP_BACKUP}'
|
||||||
|
_set_console_font(args)
|
||||||
|
else:
|
||||||
|
_set_console_font(None)
|
||||||
|
|
||||||
|
_FONT_BACKUP.unlink(missing_ok=True)
|
||||||
|
_CMAP_BACKUP.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
|
||||||
class TranslationHandler:
|
class TranslationHandler:
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ from archinstall.lib.networking import ping
|
||||||
from archinstall.lib.output import debug, error, info, warn
|
from archinstall.lib.output import debug, error, info, warn
|
||||||
from archinstall.lib.packages.util import check_version_upgrade
|
from archinstall.lib.packages.util import check_version_upgrade
|
||||||
from archinstall.lib.pacman.pacman import Pacman
|
from archinstall.lib.pacman.pacman import Pacman
|
||||||
from archinstall.lib.translationhandler import _ENV_FONT, _set_console_font, tr
|
from archinstall.lib.translationhandler import _ENV_FONT, _restore_console_font, _save_console_font, _set_console_font, tr
|
||||||
from archinstall.lib.utils.util import running_from_iso
|
from archinstall.lib.utils.util import running_from_iso
|
||||||
from archinstall.tui.ui.components import tui
|
from archinstall.tui.ui.components import tui
|
||||||
|
|
||||||
|
|
@ -79,6 +79,8 @@ def run() -> int:
|
||||||
OR straight as a module: python -m archinstall
|
OR straight as a module: python -m archinstall
|
||||||
In any case we will be attempting to load the provided script to be run from the scripts/ folder
|
In any case we will be attempting to load the provided script to be run from the scripts/ folder
|
||||||
"""
|
"""
|
||||||
|
_save_console_font()
|
||||||
|
|
||||||
if _ENV_FONT:
|
if _ENV_FONT:
|
||||||
_set_console_font(_ENV_FONT)
|
_set_console_font(_ENV_FONT)
|
||||||
|
|
||||||
|
|
@ -162,7 +164,7 @@ def main() -> int:
|
||||||
_error_message(exc)
|
_error_message(exc)
|
||||||
rc = 1
|
rc = 1
|
||||||
|
|
||||||
_set_console_font(None)
|
_restore_console_font()
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue