Write updated selections to fifo

This commit is contained in:
Austen Adler 2022-01-23 22:47:09 -05:00
parent 731c97117f
commit 971a7b9ca6
2 changed files with 12 additions and 4 deletions

View File

@ -47,7 +47,8 @@ define-command sort-selections -params 0.. %{
# TODO: Send additional parameters # TODO: Send additional parameters
rust-selection-sort -R "$regex" $args -- "$@" > "$kak_command_fifo" rust-selection-sort -R "$regex" -f "$kak_command_fifo" -- "$@"
} }
exec R exec R
} }

View File

@ -3,6 +3,8 @@
use alphanumeric_sort::compare_str; use alphanumeric_sort::compare_str;
use clap::Parser; use clap::Parser;
use regex::Regex; use regex::Regex;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
struct KakMessage(String, Option<String>); struct KakMessage(String, Option<String>);
@ -91,7 +93,12 @@ fn run() -> Result<(), KakMessage> {
} }
}); });
print!("reg '\"'"); let mut f = OpenOptions::new()
.write(true)
.append(true)
.open(&options.fifo_name)?;
write!(f, "reg '\"'")?;
let iter: Box<dyn Iterator<Item = _>> = if options.reverse { let iter: Box<dyn Iterator<Item = _>> = if options.reverse {
Box::new(zipped.iter().rev()) Box::new(zipped.iter().rev())
@ -101,9 +108,9 @@ fn run() -> Result<(), KakMessage> {
for i in iter { for i in iter {
let new_selection = i.0.replace('\'', "''"); let new_selection = i.0.replace('\'', "''");
print!(" '{}'", new_selection); write!(f, " '{}'", new_selection)?;
} }
print!(" ;"); write!(f, " ;")?;
Ok(()) Ok(())
} }