From 86dac562e824fc024d6d8ee02672275756e4d8e4 Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Thu, 15 Jun 2023 11:49:55 +0200 Subject: [PATCH] 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 --- proxmox-tui-installer/src/setup.rs | 14 ++++++++++---- proxmox-tui-installer/src/views/timezone.rs | 17 ++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs index 3b3f2f9..4efd776 100644 --- a/proxmox-tui-installer/src/setup.rs +++ b/proxmox-tui-installer/src/setup.rs @@ -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 { + self.name.partial_cmp(&other.name) + } } #[derive(Clone, Deserialize)] diff --git a/proxmox-tui-installer/src/views/timezone.rs b/proxmox-tui-installer/src/views/timezone.rs index 875ebe2..3904349 100644 --- a/proxmox-tui-installer/src/views/timezone.rs +++ b/proxmox-tui-installer/src/views/timezone.rs @@ -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::>(); + .map(|l| (l.name.clone(), l)) + .collect::>(); 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::, _>(1) .ok_or("failed to retrieve timezone")?; - let kb_layout = self + let kmap = self .view - .get_value::(2) + .get_value::, _>(2) .ok_or("failed to retrieve keyboard layout")?; Ok(TimezoneOptions { country, timezone, - kb_layout, + kb_layout: kmap.id, }) }