Add rev command

This commit is contained in:
Austen Adler 2023-01-24 20:55:21 -05:00
parent b714576b08
commit caa3953f2c
2 changed files with 15 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#![feature(array_chunks)] #![feature(array_chunks)]
mod box_; mod box_;
mod rev;
mod errors; mod errors;
mod incr; mod incr;
mod invert; mod invert;
@ -69,6 +70,8 @@ enum Commands {
Decr(incr::Options), Decr(incr::Options),
#[clap(about = "Decrement selections")] #[clap(about = "Decrement selections")]
Incr(incr::Options), Incr(incr::Options),
#[clap(about = "Reverse selectinos")]
Rev(rev::Options)
} }
fn main() { fn main() {
@ -119,5 +122,6 @@ fn run() -> Result<String, KakError> {
Commands::Xlookup(o) => xlookup::xlookup(o), Commands::Xlookup(o) => xlookup::xlookup(o),
Commands::Incr(o) => incr::incr(o, true), Commands::Incr(o) => incr::incr(o, true),
Commands::Decr(o) => incr::incr(o, false), Commands::Decr(o) => incr::incr(o, false),
Commands::Rev(o) => rev::rev(o),
} }
} }

11
src/rev.rs Normal file
View File

@ -0,0 +1,11 @@
use kakplugin::{get_selections, set_selections, KakError};
#[derive(clap::StructOpt, Debug)]
pub struct Options;
pub fn rev(_options: &Options) -> Result<String, KakError> {
let selections = get_selections(None)?;
set_selections(selections.iter().rev())?;
Ok(format!("Reversed {} selections", selections.len()))
}