Add option to preserve newlines in match list
This commit is contained in:
parent
968ef578c1
commit
32d7dbc88e
|
@ -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
|
||||
|
|
10
src/main.rs
10
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user