Add abillity to reverse

This commit is contained in:
Austen Adler 2022-01-23 22:23:13 -05:00
parent 4b44d72765
commit af8724d5eb
2 changed files with 12 additions and 3 deletions

View File

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

View File

@ -12,12 +12,14 @@ struct Options {
#[clap(short = 'S', long)]
// TODO: Can we invert a boolean? This name is terrible
no_skip_whitespace: bool,
#[clap(short, long, required = true)]
#[clap(short = 'R', long, required = true)]
regex: String,
#[clap(multiple_occurrences = true, required = true)]
selections: Vec<String>,
#[clap(short, long)]
lexicographic_sort: bool,
#[clap(short, long)]
reverse: bool,
}
fn main() {
@ -91,7 +93,14 @@ fn run() -> Result<(), KakMessage> {
});
print!("reg '\"'");
for i in &zipped {
let iter: Box<dyn Iterator<Item = _>> = if options.reverse {
Box::new(zipped.iter().rev())
} else {
Box::new(zipped.iter())
};
for i in iter {
let new_selection = i.0.replace('\'', "''");
print!(" '{}'", new_selection);
}