Add invert by line option

This commit is contained in:
Austen Adler 2022-09-03 02:02:12 -04:00
parent e9775eb222
commit 94ad2dc4ef

View File

@ -7,6 +7,9 @@ use std::{fs, str::FromStr};
pub struct Options { pub struct Options {
#[clap(short, long, help = "Do not include newlines")] #[clap(short, long, help = "Do not include newlines")]
no_newline: bool, no_newline: bool,
#[clap(short, long, help = "Invert by line instead of by entire document")]
line: bool,
} }
pub fn invert(options: &Options) -> Result<String, KakError> { pub fn invert(options: &Options) -> Result<String, KakError> {
@ -22,12 +25,15 @@ pub fn invert(options: &Options) -> Result<String, KakError> {
let count_selections = split_selections_desc.len(); let count_selections = split_selections_desc.len();
let whole_document_selection_command = if options.no_newline { let whole_document_selection_command = match (options.line, options.no_newline) {
// Select everything and only keep non-newlines // Select everything and only keep non-newlines
"%s^[^\\n]+<ret>" (false, true) => "%s^[^\\n]+<ret>",
} else {
// Select everything and split // Select everything and split
"%<a-s>" (false, false) => "%<a-s>",
// Select entire line, then remove newline
(true, true) => "<a-x><a-s>s^[^\\n]+<ret>",
// Select entire line, including newline
(true, false) => "<a-x><a-s>",
}; };
let document_descs: Vec<SelectionDesc> = { let document_descs: Vec<SelectionDesc> = {