From 94ad2dc4ef347fa6b7ed847d3d44bbd6e3ed1653 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sat, 3 Sep 2022 02:02:12 -0400 Subject: [PATCH] Add invert by line option --- src/invert.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/invert.rs b/src/invert.rs index 145e2f1..c9deada 100644 --- a/src/invert.rs +++ b/src/invert.rs @@ -7,6 +7,9 @@ use std::{fs, str::FromStr}; pub struct Options { #[clap(short, long, help = "Do not include newlines")] no_newline: bool, + + #[clap(short, long, help = "Invert by line instead of by entire document")] + line: bool, } pub fn invert(options: &Options) -> Result { @@ -22,12 +25,15 @@ pub fn invert(options: &Options) -> Result { 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 - "%s^[^\\n]+" - } else { + (false, true) => "%s^[^\\n]+", // Select everything and split - "%" + (false, false) => "%", + // Select entire line, then remove newline + (true, true) => "s^[^\\n]+", + // Select entire line, including newline + (true, false) => "", }; let document_descs: Vec = {