diff --git a/Cargo.lock b/Cargo.lock index bc317536..04fcbd3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,6 +112,10 @@ name = "cc" version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +dependencies = [ + "jobserver", + "libc", +] [[package]] name = "cfg-if" @@ -337,6 +341,12 @@ dependencies = [ "thread_local", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "hashbrown" version = "0.14.3" @@ -394,6 +404,7 @@ dependencies = [ "num-traits", "png", "qoi", + "webp", ] [[package]] @@ -412,6 +423,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "jobserver" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.3.1" @@ -463,6 +483,16 @@ dependencies = [ "wayland-protocols-wlr", ] +[[package]] +name = "libwebp-sys" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829b6b604f31ed6d2bccbac841fe0788de93dbd87e4eb1ba2c4adfe8c012a838" +dependencies = [ + "cc", + "glob", +] + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -995,6 +1025,15 @@ dependencies = [ "wl-clipboard-rs", ] +[[package]] +name = "webp" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bb5d8e7814e92297b0e1c773ce43d290bef6c17452dafd9fc49e5edb5beba71" +dependencies = [ + "libwebp-sys", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/wayshot/src/cli.rs b/wayshot/src/cli.rs index c0508e9e..7a5dc1f6 100644 --- a/wayshot/src/cli.rs +++ b/wayshot/src/cli.rs @@ -11,12 +11,16 @@ use clap::builder::TypedValueParser; #[derive(Parser)] #[command(version, about)] pub struct Cli { - /// Where to save the screenshot, "-" for stdout. Defaults to "$UNIX_TIMESTAMP-wayshot.$EXTENSION" unless --clipboard is present. - #[arg(value_name = "OUTPUT")] + /// Custom output path can be of the following types: + /// 1. Directory (Default naming scheme is used for the image output). + /// 2. Path (Encoding is automatically inferred from the extension). + /// 3. `-` (Indicates writing to terminal [stdout]). + #[arg(value_name = "OUTPUT", verbatim_doc_comment)] pub file: Option, - /// Copy image to clipboard along with [OUTPUT] or stdout. Wayshot persists in the background to offer the image till the clipboard is overwritten. - #[arg(long)] + /// Copy image to clipboard along with [OUTPUT] or stdout. + /// Wayshot persists in the background to offer the image till the clipboard is overwritten. + #[arg(long, verbatim_doc_comment)] pub clipboard: bool, /// Log level to be used for printing to stderr @@ -33,7 +37,7 @@ pub struct Cli { /// Set image encoder, by default uses the file extension from the OUTPUT /// positional argument. Otherwise defaults to png. - #[arg(long, visible_aliases = ["extension", "format", "output-format"], value_name = "FILE_EXTENSION")] + #[arg(long, verbatim_doc_comment, visible_aliases = ["extension", "format", "output-format"], value_name = "FILE_EXTENSION")] pub encoding: Option, /// List all valid outputs diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index a1c8ac0d..e3abb529 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -106,11 +106,14 @@ fn main() -> Result<()> { let mut stdout_print = false; let file = match cli.file { - Some(pathbuf) => { + Some(mut pathbuf) => { if pathbuf.to_string_lossy() == "-" { stdout_print = true; None } else { + if pathbuf.is_dir() { + pathbuf.push(utils::get_default_file_name(requested_encoding)); + } Some(pathbuf) } }