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