+use crate::setup::KeyboardMapping;
use proxmox_sys::linux::procfs;
+use std::{fs::OpenOptions, io::Write, process::Command};
pub fn has_min_requirements() -> Result<(), String> {
let meminfo = procfs::read_meminfo().map_err(|err| err.to_string())?;
Ok(())
}
+
+pub fn set_keyboard_layout(kmap: &KeyboardMapping) -> Result<(), String> {
+ Command::new("setxkbmap")
+ .args([&kmap.xkb_layout, &kmap.xkb_variant])
+ .output()
+ .map_err(|err| err.to_string())?;
+
+ let mut f = OpenOptions::new()
+ .write(true)
+ .truncate(true)
+ .open("/etc/default/keyboard")
+ .map_err(|err| err.to_string())?;
+
+ write!(
+ f,
+ r#"XKBLAYOUT="{}"
+XKBVARIANT="{}"
+BACKSPACE="guess"
+"#,
+ kmap.xkb_layout, kmap.xkb_variant
+ )
+ .map_err(|err| err.to_string())?;
+
+ Command::new("setupcon")
+ .output()
+ .map_err(|err| err.to_string())?;
+
+ Ok(())
+}
use crate::{
options::TimezoneOptions,
setup::{KeyboardMapping, LocaleInfo},
+ system, InstallerState,
};
use cursive::{
view::{Nameable, ViewWrapper},
- views::{NamedView, SelectView},
+ views::{Dialog, NamedView, SelectView},
Cursive,
};
SelectView::new()
.popup()
.with_all(kb_layouts)
- .selected(kb_layout_selected_pos),
+ .selected(kb_layout_selected_pos)
+ .on_submit(|siv, selected| {
+ if siv
+ .user_data::<InstallerState>()
+ .map(|state| state.in_test_mode)
+ // In doubt, don't override the layout
+ .unwrap_or(true)
+ {
+ return;
+ }
+
+ if let Err(err) = system::set_keyboard_layout(selected) {
+ siv.add_layer(Dialog::info(format!(
+ "Failed to apply keyboard layout: {err}"
+ )));
+ }
+ }),
);
Self { view }