From 03e190067b096e8dbb46407e8a114b1e993358f3 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Thu, 21 Jan 2021 19:00:27 +0100 Subject: [PATCH] Minor changes --- src/client.rs | 5 +++-- src/util.rs | 15 +++++++++------ src/window.rs | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/client.rs b/src/client.rs index ac3f0b0..c23ec5e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -15,8 +15,9 @@ fn get_window_props() -> Result, serde_json:: pub fn switch_window() { let root_node = get_tree(); let mut windows = window::get_windows(&root_node); - if let Ok(win_props) = get_window_props() { - window::sort_windows(&mut windows, win_props); + match get_window_props() { + Ok(win_props) => window::sort_windows(&mut windows, win_props), + Err(e) => eprintln!("Got no win_props: {:?}", e), } if let Some(window) = util::select_window(&windows) { diff --git a/src/util.rs b/src/util.rs index 8ed9d7e..7d7867d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -40,8 +40,11 @@ where TS: std::fmt::Display + Sized, { let mut map: std::collections::HashMap = std::collections::HashMap::new(); + let mut strs: Vec = vec![]; for c in choices { - map.insert(format!("{}", c), c); + let s = format!("{}", c); + strs.push(String::from(s.as_str())); + map.insert(s, c); } let mut wofi = proc::Command::new("wofi") @@ -58,11 +61,11 @@ where { let stdin = wofi.stdin.as_mut().expect("Failed to open wofi stdin"); - for c in choices { - stdin - .write_all(format!("{}\n", c).as_bytes()) - .expect("Failed to write to wofi stdin"); - } + let wofi_input = strs.join("\n"); + println!("Wofi input:\n{}", wofi_input); + stdin + .write_all(wofi_input.as_bytes()) + .expect("Failed to write to wofi stdin"); } let output = wofi.wait_with_output().expect("Failed to read stdout"); diff --git a/src/window.rs b/src/window.rs index f58700c..06125db 100644 --- a/src/window.rs +++ b/src/window.rs @@ -65,9 +65,9 @@ pub fn sort_windows(windows: &mut Vec, win_props: HashMap