Skip to content

Commit

Permalink
Use the current layout instead of the us layout (#2495)
Browse files Browse the repository at this point in the history
* use the current layout instead of the us layout

* fix linting erros and add exception handling for SysCommand
  • Loading branch information
ngn13 authored May 15, 2024
1 parent bab06e4 commit 39d096b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions archinstall/lib/locale/locale_menu.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from typing import Dict, Any, TYPE_CHECKING, Optional

from .utils import list_keyboard_languages, list_locales, set_kb_layout
from .utils import list_keyboard_languages, list_locales, set_kb_layout, get_kb_layout
from ..menu import Selector, AbstractSubMenu, MenuSelectionType, Menu

if TYPE_CHECKING:
Expand All @@ -16,7 +16,10 @@ class LocaleConfiguration:

@staticmethod
def default() -> 'LocaleConfiguration':
return LocaleConfiguration('us', 'en_US', 'UTF-8')
layout = get_kb_layout()
if layout == "":
return LocaleConfiguration('us', 'en_US', 'UTF-8')
return LocaleConfiguration(layout, 'en_US', 'UTF-8')

def json(self) -> Dict[str, str]:
return {
Expand Down
24 changes: 24 additions & 0 deletions archinstall/lib/locale/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ def verify_x11_keyboard_layout(layout :str) -> bool:
return False


def get_kb_layout() -> str:
try:
lines = SysCommand(
"localectl --no-pager status",
environment_vars={'SYSTEMD_COLORS': '0'}
).decode().splitlines()
except:
return ""

vcline = ""
for line in lines:
if "VC Keymap: " in line:
vcline = line

if vcline == "":
return ""

layout = vcline.split(": ")[1]
if not verify_keyboard_layout(layout):
return ""

return layout


def set_kb_layout(locale :str) -> bool:
if len(locale.strip()):
if not verify_keyboard_layout(locale):
Expand Down

0 comments on commit 39d096b

Please sign in to comment.