fixed multiline clipboard entries

This commit is contained in:
WanderingPenwing 2024-08-01 21:29:58 +02:00
parent 081881d729
commit 6c70ee5825
2 changed files with 15 additions and 4 deletions

View file

@ -54,8 +54,14 @@ impl History {
}
async fn select_entry(&self) -> Result<String, Box<dyn std::error::Error>> {
let input_data = self.entries.join("\n");
let mut formated_data : Vec<String> = 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")
@ -67,12 +73,16 @@ 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::<usize>().unwrap_or(0);
Ok(self.entries[index].clone())
}
}

1
susuwatari.project Normal file
View file

@ -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":[]}]}