mirror of
https://git.proxmox.com/git/pve-installer
synced 2025-06-14 15:18:30 +00:00
tui: use whole keyboard mapping in select view as value
Thus all its values can easily be used later on. Involves making `KeyboardMapping` partial-orderable, just use the human-readable name here (as that's what displayed to the user). Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
This commit is contained in:
parent
cae155237b
commit
86dac562e8
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::HashMap, fs::File, io::BufReader, path::Path};
|
use std::{cmp, collections::HashMap, fs::File, io::BufReader, path::Path};
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
@ -41,15 +41,21 @@ pub struct CountryInfo {
|
|||||||
pub kmap: String,
|
pub kmap: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize)]
|
#[derive(Clone, Deserialize, Eq, PartialEq, Ord)]
|
||||||
pub struct KeyboardMapping {
|
pub struct KeyboardMapping {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(rename = "kvm")]
|
#[serde(rename = "kvm")]
|
||||||
pub id: String,
|
pub id: String,
|
||||||
#[serde(rename = "x11")]
|
#[serde(rename = "x11")]
|
||||||
pub layout: String,
|
pub xkb_layout: String,
|
||||||
#[serde(rename = "x11var")]
|
#[serde(rename = "x11var")]
|
||||||
pub variant: String,
|
pub xkb_variant: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl cmp::PartialOrd for KeyboardMapping {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
||||||
|
self.name.partial_cmp(&other.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
use super::FormView;
|
use super::FormView;
|
||||||
use crate::{options::TimezoneOptions, setup::LocaleInfo};
|
use crate::{
|
||||||
|
options::TimezoneOptions,
|
||||||
|
setup::{KeyboardMapping, LocaleInfo},
|
||||||
|
};
|
||||||
use cursive::{
|
use cursive::{
|
||||||
view::{Nameable, ViewWrapper},
|
view::{Nameable, ViewWrapper},
|
||||||
views::{NamedView, SelectView},
|
views::{NamedView, SelectView},
|
||||||
@ -48,13 +51,13 @@ impl TimezoneOptionsView {
|
|||||||
.kmap
|
.kmap
|
||||||
.clone()
|
.clone()
|
||||||
.into_values()
|
.into_values()
|
||||||
.map(|l| (l.name, l.id))
|
.map(|l| (l.name.clone(), l))
|
||||||
.collect::<Vec<(String, String)>>();
|
.collect::<Vec<(String, KeyboardMapping)>>();
|
||||||
kb_layouts.sort();
|
kb_layouts.sort();
|
||||||
|
|
||||||
let kb_layout_selected_pos = kb_layouts
|
let kb_layout_selected_pos = kb_layouts
|
||||||
.iter()
|
.iter()
|
||||||
.position(|l| l.1 == options.kb_layout)
|
.position(|l| l.1.id == options.kb_layout)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let view = FormView::new()
|
let view = FormView::new()
|
||||||
@ -86,15 +89,15 @@ impl TimezoneOptionsView {
|
|||||||
.get_value::<NamedView<SelectView>, _>(1)
|
.get_value::<NamedView<SelectView>, _>(1)
|
||||||
.ok_or("failed to retrieve timezone")?;
|
.ok_or("failed to retrieve timezone")?;
|
||||||
|
|
||||||
let kb_layout = self
|
let kmap = self
|
||||||
.view
|
.view
|
||||||
.get_value::<SelectView, _>(2)
|
.get_value::<SelectView<KeyboardMapping>, _>(2)
|
||||||
.ok_or("failed to retrieve keyboard layout")?;
|
.ok_or("failed to retrieve keyboard layout")?;
|
||||||
|
|
||||||
Ok(TimezoneOptions {
|
Ok(TimezoneOptions {
|
||||||
country,
|
country,
|
||||||
timezone,
|
timezone,
|
||||||
kb_layout,
|
kb_layout: kmap.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user