]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: use whole keyboard mapping in select view as value
authorChristoph Heiss <c.heiss@proxmox.com>
Thu, 15 Jun 2023 09:49:55 +0000 (11:49 +0200)
committerChristoph Heiss <c.heiss@proxmox.com>
Thu, 15 Jun 2023 09:49:55 +0000 (11:49 +0200)
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>
proxmox-tui-installer/src/setup.rs
proxmox-tui-installer/src/views/timezone.rs

index 3b3f2f9f4a43258482a308b94bad8f6bb079250d..4efd776ae8e04fd50621ae6586b7fda8335bc775 100644 (file)
@@ -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};
 
@@ -41,15 +41,21 @@ pub struct CountryInfo {
     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)]
index 875ebe2ef228f1e6086072733195bd873f6423c7..39043490d4a46d636b258bda8dd59551e6d64e98 100644 (file)
@@ -1,5 +1,8 @@
 use super::FormView;
-use crate::{options::TimezoneOptions, setup::LocaleInfo};
+use crate::{
+    options::TimezoneOptions,
+    setup::{KeyboardMapping, LocaleInfo},
+};
 use cursive::{
     view::{Nameable, ViewWrapper},
     views::{NamedView, SelectView},
@@ -48,13 +51,13 @@ impl TimezoneOptionsView {
             .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()
@@ -86,15 +89,15 @@ impl TimezoneOptionsView {
             .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,
         })
     }