diff --git a/espanso/src/cli/modulo/mod.rs b/espanso/src/cli/modulo/mod.rs index 7954d50..ffdbb6e 100644 --- a/espanso/src/cli/modulo/mod.rs +++ b/espanso/src/cli/modulo/mod.rs @@ -24,6 +24,8 @@ mod form; #[cfg(feature = "modulo")] mod search; #[cfg(feature = "modulo")] +mod textview; +#[cfg(feature = "modulo")] mod troubleshoot; #[cfg(feature = "modulo")] mod welcome; @@ -57,6 +59,10 @@ fn modulo_main(args: CliModuleArgs) -> i32 { return welcome::welcome_main(matches, &paths, &icon_paths); } + if let Some(matches) = cli_args.subcommand_matches("textview") { + return textview::textview_main(matches, &icon_paths); + } + if cli_args.subcommand_matches("troubleshoot").is_some() { return troubleshoot::troubleshoot_main(&paths, &icon_paths); } diff --git a/espanso/src/cli/modulo/textview.rs b/espanso/src/cli/modulo/textview.rs new file mode 100644 index 0000000..229668a --- /dev/null +++ b/espanso/src/cli/modulo/textview.rs @@ -0,0 +1,51 @@ +/* + * This file is part of espanso. + * + * Copyright (C) 2019-2021 Federico Terzi + * + * espanso is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * espanso is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with espanso. If not, see . + */ + +use crate::icon::IconPaths; +use clap::ArgMatches; +use espanso_modulo::textview::TextViewOptions; + +pub fn textview_main(matches: &ArgMatches, icon_paths: &IconPaths) -> i32 { + let title = matches.value_of("title").unwrap_or("Espanso"); + + let input_file = matches + .value_of("input_file") + .expect("missing input, please specify the -i option"); + let data = if input_file == "-" { + use std::io::Read; + let mut buffer = String::new(); + std::io::stdin() + .read_to_string(&mut buffer) + .expect("unable to obtain input from stdin"); + buffer + } else { + std::fs::read_to_string(input_file).expect("unable to read input file") + }; + + espanso_modulo::textview::show(TextViewOptions { + window_icon_path: icon_paths + .wizard_icon + .as_ref() + .map(|path| path.to_string_lossy().to_string()), + title: title.to_string(), + content: data, + }); + + 0 +} diff --git a/espanso/src/main.rs b/espanso/src/main.rs index 58cf84f..97d42d9 100644 --- a/espanso/src/main.rs +++ b/espanso/src/main.rs @@ -292,6 +292,23 @@ For example, specifying 'email' is equivalent to 'match/email.yml'."#)) .help("Interpret the input data as JSON"), ), ) + .subcommand( + SubCommand::with_name("textview") + .about("Display a Text View") + .arg( + Arg::with_name("input_file") + .short("i") + .takes_value(true) + .help("Input file or - for stdin"), + ) + .arg( + Arg::with_name("title") + .long("title") + .required(true) + .takes_value(true) + .help("Window title to display"), + ), + ) .subcommand(SubCommand::with_name("troubleshoot").about("Display the troubleshooting GUI")) .subcommand( SubCommand::with_name("welcome")