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

Commit

Permalink
feat: Optimize writing to the fzf pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzaaft committed Jul 18, 2023
1 parent 6ff9216 commit d38d4e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/fzf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ impl Fzf {
}
}

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

Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ async fn main() -> Result<()> {
});
let astro = Astrocommunity::new();
let plugins = astro.get_plugins()?;
dbg!(plugins.len());
let mut fzf = fzf::Fzf::new()?;
let fzf_string: String = plugins.iter().map(|plugin| plugin.to_string()).join("\n");
fzf.write_to_stdin(fzf_string.as_bytes())?;
fzf.write_to_stdin(&plugins)?;
let selected_plugins = fzf.get_selected_plugins(&plugins)?;
let mut import_statement = String::with_capacity(50 * selected_plugins.len());
for item in selected_plugins.iter() {
Expand Down

0 comments on commit d38d4e4

Please sign in to comment.