-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};
pub kmap: String,
}
-#[derive(Clone, Deserialize)]
+#[derive(Clone, Deserialize, Eq, PartialEq, Ord)]
pub struct KeyboardMapping {
pub name: String,
#[serde(rename = "kvm")]
pub id: String,
#[serde(rename = "x11")]
- pub layout: String,
+ pub xkb_layout: String,
#[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)]
use super::FormView;
-use crate::{options::TimezoneOptions, setup::LocaleInfo};
+use crate::{
+ options::TimezoneOptions,
+ setup::{KeyboardMapping, LocaleInfo},
+};
use cursive::{
view::{Nameable, ViewWrapper},
views::{NamedView, SelectView},
.kmap
.clone()
.into_values()
- .map(|l| (l.name, l.id))
- .collect::<Vec<(String, String)>>();
+ .map(|l| (l.name.clone(), l))
+ .collect::<Vec<(String, KeyboardMapping)>>();
kb_layouts.sort();
let kb_layout_selected_pos = kb_layouts
.iter()
- .position(|l| l.1 == options.kb_layout)
+ .position(|l| l.1.id == options.kb_layout)
.unwrap_or_default();
let view = FormView::new()
.get_value::<NamedView<SelectView>, _>(1)
.ok_or("failed to retrieve timezone")?;
- let kb_layout = self
+ let kmap = self
.view
- .get_value::<SelectView, _>(2)
+ .get_value::<SelectView<KeyboardMapping>, _>(2)
.ok_or("failed to retrieve keyboard layout")?;
Ok(TimezoneOptions {
country,
timezone,
- kb_layout,
+ kb_layout: kmap.id,
})
}