From 32d7dbc88ed8f27f4a1730c416f0a38a410bf0aa Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Mon, 22 Jun 2020 21:42:50 +0200 Subject: [PATCH] Add option to preserve newlines in match list --- src/cli.rs | 9 +++++++-- src/main.rs | 10 +++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 601b033..645d64d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -21,7 +21,7 @@ use serde::Serialize; use crate::config::ConfigSet; use crate::matcher::{Match, MatchContentType}; -pub fn list_matches(config_set: ConfigSet, onlytriggers: bool) { +pub fn list_matches(config_set: ConfigSet, onlytriggers: bool, preserve_newlines: bool) { let matches = filter_matches(config_set); for m in matches { @@ -31,7 +31,12 @@ pub fn list_matches(config_set: ConfigSet, onlytriggers: bool) { }else { match m.content { MatchContentType::Text(ref text) => { - println!("{} - {}", trigger, text.replace) + let replace = if preserve_newlines { + text.replace.to_owned() + }else{ + text.replace.replace("\n", " ") + }; + println!("{} - {}", trigger, replace) }, MatchContentType::Image(_) => { // Skip image matches for now diff --git a/src/main.rs b/src/main.rs index f7b3b18..3becc92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,6 +177,13 @@ fn main() { .required(false) .takes_value(false) ) + .arg(Arg::with_name("preservenewlines") + .short("n") + .long("preservenewlines") + .help("Preserve newlines when printing replacements") + .required(false) + .takes_value(false) + ) ) .subcommand(SubCommand::with_name("exec") .about("Triggers the expansion of the given match") @@ -1266,9 +1273,10 @@ fn match_main(config_set: ConfigSet, matches: &ArgMatches) { if let Some(matches) = matches.subcommand_matches("list") { let json = matches.is_present("json"); let onlytriggers = matches.is_present("onlytriggers"); + let preserve_newlines = matches.is_present("preservenewlines"); if !json { - crate::cli::list_matches(config_set, onlytriggers); + crate::cli::list_matches(config_set, onlytriggers, preserve_newlines); }else{ crate::cli::list_matches_as_json(config_set); }