diff --git a/wayshot/src/cli.rs b/wayshot/src/cli.rs index 83b7f3d4..26977b36 100644 --- a/wayshot/src/cli.rs +++ b/wayshot/src/cli.rs @@ -1,22 +1,35 @@ use std::path::PathBuf; -use clap::{Parser, arg, builder::TypedValueParser}; - +use clap::{ + Parser, arg, + builder::{ + Styles, TypedValueParser, + styling::{AnsiColor, Effects}, + }, +}; use eyre::WrapErr; use crate::utils::EncodingFormat; +fn get_styles() -> Styles { + Styles::styled() + .header(AnsiColor::Yellow.on_default() | Effects::BOLD) + .usage(AnsiColor::Green.on_default() | Effects::BOLD) + .literal(AnsiColor::Blue.on_default() | Effects::BOLD) + .placeholder(AnsiColor::Green.on_default()) +} + #[derive(Parser)] -#[command(version, about)] +#[command(version, about, styles=get_styles())] pub struct Cli { - /// Custom output path can be of the following types: - /// 1. Directory (Default naming scheme is used for the image output). + /// Custom screenshot file path can be of the following types: + /// 1. Directory (Default naming scheme is used for the screenshot file). /// 2. Path (Encoding is automatically inferred from the extension). /// 3. `-` (Indicates writing to terminal [stdout]). - #[arg(value_name = "OUTPUT", verbatim_doc_comment)] + #[arg(value_name = "FILE", verbatim_doc_comment)] pub file: Option, - /// Copy image to clipboard. Can be used simultaneously with [OUTPUT] or stdout. + /// Copy image to clipboard. Can be used simultaneously with [FILE]. /// Wayshot persists in the background offering the image till the clipboard is overwritten. #[arg(long, verbatim_doc_comment)] pub clipboard: bool, @@ -33,13 +46,13 @@ pub struct Cli { #[arg(short, long)] pub cursor: bool, - /// Set image encoder, by default uses the file extension from the OUTPUT + /// Set image encoder, by default uses the file extension from the FILE /// positional argument. Otherwise defaults to png. - #[arg(long, verbatim_doc_comment, visible_aliases = ["extension", "format", "output-format"], value_name = "FILE_EXTENSION")] + #[arg(long, verbatim_doc_comment, visible_aliases = ["extension", "format", "file-format"], value_name = "FILE_EXTENSION")] pub encoding: Option, /// List all valid outputs - #[arg(short, long, alias = "listoutputs")] + #[arg(short, long, alias = "list-outputs")] pub list_outputs: bool, /// Choose a particular output/display to screenshot @@ -47,6 +60,6 @@ pub struct Cli { pub output: Option, /// Present a fuzzy selector for output/display selection - #[arg(long, alias = "chooseoutput", conflicts_with_all = ["slurp", "output"])] + #[arg(long, alias = "choose-output", conflicts_with_all = ["slurp", "output"])] pub choose_output: bool, } diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index 6cf22b6b..ca20364b 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -1,5 +1,5 @@ use std::{ - io::{BufWriter, Cursor, Write, stdout}, + io::{self, BufWriter, Cursor, Write}, process::Command, }; @@ -36,7 +36,7 @@ fn main() -> Result<()> { let cli = cli::Cli::parse(); tracing_subscriber::fmt() .with_max_level(cli.log_level) - .with_writer(std::io::stderr) + .with_writer(io::stderr) .init(); let input_encoding = cli @@ -58,11 +58,17 @@ fn main() -> Result<()> { let wayshot_conn = WayshotConnection::new()?; + let stdout = io::stdout(); + let mut writer = BufWriter::new(stdout.lock()); + if cli.list_outputs { let valid_outputs = wayshot_conn.get_all_outputs(); for output in valid_outputs { - tracing::info!("{:#?}", output.name); + writeln!(writer, "{}", output.name)?; } + + writer.flush()?; + return Ok(()); } @@ -132,8 +138,6 @@ fn main() -> Result<()> { } else if stdout_print { let mut buffer = Cursor::new(Vec::new()); image_buffer.write_to(&mut buffer, requested_encoding.into())?; - let stdout = stdout(); - let mut writer = BufWriter::new(stdout.lock()); writer.write_all(buffer.get_ref())?; image_buf = Some(buffer); }