Skip to content
This repository was archived by the owner on Jul 26, 2024. It is now read-only.

Commit d38d4e4

Browse files
committed
feat: Optimize writing to the fzf pipe
1 parent 6ff9216 commit d38d4e4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/fzf.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ impl Fzf {
3030
}
3131
}
3232

33-
pub fn write_to_stdin(&mut self, input: &[u8]) -> Result<()> {
34-
if let Err(why) = self.process.stdin.as_mut().unwrap().write_all(input) {
35-
panic!("couldn't write to fzf stdin: {}", why)
36-
}
33+
pub fn write_to_stdin(&mut self, input: &[PluginInfo]) -> Result<()> {
34+
let stdin = self.process.stdin.as_mut().unwrap();
35+
input.iter().for_each(|plugin| {
36+
writeln!(stdin, "{}", plugin.to_string()).unwrap();
37+
});
3738
Ok(())
3839
}
3940

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ async fn main() -> Result<()> {
2222
});
2323
let astro = Astrocommunity::new();
2424
let plugins = astro.get_plugins()?;
25+
dbg!(plugins.len());
2526
let mut fzf = fzf::Fzf::new()?;
2627
let fzf_string: String = plugins.iter().map(|plugin| plugin.to_string()).join("\n");
27-
fzf.write_to_stdin(fzf_string.as_bytes())?;
28+
fzf.write_to_stdin(&plugins)?;
2829
let selected_plugins = fzf.get_selected_plugins(&plugins)?;
2930
let mut import_statement = String::with_capacity(50 * selected_plugins.len());
3031
for item in selected_plugins.iter() {

0 commit comments

Comments
 (0)