fixed multiline clipboard entries
This commit is contained in:
parent
081881d729
commit
6c70ee5825
18
src/main.rs
18
src/main.rs
|
@ -54,8 +54,14 @@ impl History {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn select_entry(&self) -> Result<String, Box<dyn std::error::Error>> {
|
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
|
// Prepare the command
|
||||||
let mut cmd = Command::new("sh")
|
let mut cmd = Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
|
@ -66,13 +72,17 @@ impl History {
|
||||||
|
|
||||||
let stdin = cmd.stdin.as_mut().ok_or("Failed to open stdin")?;
|
let stdin = cmd.stdin.as_mut().ok_or("Failed to open stdin")?;
|
||||||
stdin.write_all(input_data.as_bytes()).await?;
|
stdin.write_all(input_data.as_bytes()).await?;
|
||||||
|
|
||||||
println!("awaiting");
|
|
||||||
|
|
||||||
// Await the command to complete
|
// Await the command to complete
|
||||||
let output = cmd.wait_with_output().await?;
|
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
1
susuwatari.project
Normal 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":[]}]}
|
Loading…
Reference in a new issue