From 6c70ee58253079e36c07da5865c58bdc1442128d Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Thu, 1 Aug 2024 21:29:58 +0200 Subject: [PATCH] fixed multiline clipboard entries --- src/main.rs | 18 ++++++++++++++---- susuwatari.project | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 susuwatari.project diff --git a/src/main.rs b/src/main.rs index 0974e18..5755964 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,8 +54,14 @@ impl History { } async fn select_entry(&self) -> Result> { - let input_data = self.entries.join("\n"); + + + let mut formated_data : Vec = vec![]; + for (index, entry) in self.entries.iter().enumerate() { + formated_data.push(format!("{}- {}",index, entry.split('\n').next().unwrap_or("err"))); + } + let input_data = formated_data.join("\n"); // Prepare the command let mut cmd = Command::new("sh") .arg("-c") @@ -66,13 +72,17 @@ impl History { let stdin = cmd.stdin.as_mut().ok_or("Failed to open stdin")?; stdin.write_all(input_data.as_bytes()).await?; - - println!("awaiting"); // Await the command to complete let output = cmd.wait_with_output().await?; - Ok(String::from_utf8(output.stdout)?) + let result = String::from_utf8(output.stdout)?; + + let index_str = result.split('-').next().unwrap_or("0"); + + let index = index_str.parse::().unwrap_or(0); + + Ok(self.entries[index].clone()) } } diff --git a/susuwatari.project b/susuwatari.project new file mode 100644 index 0000000..045eec5 --- /dev/null +++ b/susuwatari.project @@ -0,0 +1 @@ +{"categories":[{"name":"todo","content":[{"name":"handle multiline input","description":"instead of showing every line in dmenu\nshow the first line with a number\n\nfetch the number from the output \nuse the number to get the entry and put it in the clipboard","id":1}]},{"name":"+","content":[]}]} \ No newline at end of file