From 20cf365eb99a463ec621b3e02053f1e4278aec7f Mon Sep 17 00:00:00 2001 From: rachancheet Date: Sun, 3 Mar 2024 00:06:05 +0530 Subject: [PATCH 1/5] feat: accounting for directories in file path --- wayshot/src/cli.rs | 2 +- wayshot/src/wayshot.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wayshot/src/cli.rs b/wayshot/src/cli.rs index 418ac8d8..72a9eaf1 100644 --- a/wayshot/src/cli.rs +++ b/wayshot/src/cli.rs @@ -11,7 +11,7 @@ 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". + ///Provide a custom file path ( encoding format is inferred from the file extension ). If path provided is directory then the output image is saved to provided path with default naming scheme. Default path is ./ , `-` indicates writing to terminal (stdout). #[arg(value_name = "OUTPUT")] pub file: Option, diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index 37152a79..4e8f8290 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -53,11 +53,16 @@ fn main() -> Result<()> { } let file = match cli.file { - Some(pathbuf) => { + Some(mut pathbuf) => { if pathbuf.to_string_lossy() == "-" { None } else { - Some(pathbuf) + if pathbuf.is_dir() { + pathbuf.push(utils::get_default_file_name(requested_encoding)); + Some(pathbuf) + } else { + Some(pathbuf) + } } } None => Some(utils::get_default_file_name(requested_encoding)), From 3ce4ff3d2b630d7672829c4124cb1d3c36a34987 Mon Sep 17 00:00:00 2001 From: rachancheet <55895940+rachancheet@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:37:10 +0530 Subject: [PATCH 2/5] Update wayshot.rs --- wayshot/src/wayshot.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index 4e8f8290..9b3926e9 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -59,10 +59,8 @@ fn main() -> Result<()> { } else { if pathbuf.is_dir() { pathbuf.push(utils::get_default_file_name(requested_encoding)); - Some(pathbuf) - } else { - Some(pathbuf) - } + } + Some(pathbuf) } } None => Some(utils::get_default_file_name(requested_encoding)), From 52a273a4fed3940bde289911934f9a2ca44ebde2 Mon Sep 17 00:00:00 2001 From: rachancheet Date: Tue, 5 Mar 2024 05:17:24 +0530 Subject: [PATCH 3/5] fixed format --- wayshot/src/wayshot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index 9b3926e9..4f097109 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -59,7 +59,7 @@ fn main() -> Result<()> { } else { if pathbuf.is_dir() { pathbuf.push(utils::get_default_file_name(requested_encoding)); - } + } Some(pathbuf) } } From fe9d1701063029655769231fbdf83006c7b0a127 Mon Sep 17 00:00:00 2001 From: rachancheet Date: Sat, 23 Mar 2024 22:12:19 +0530 Subject: [PATCH 4/5] refactor --- Cargo.lock | 39 +++++++++++++++++++++++++++++++++++++++ wayshot/src/wayshot.rs | 19 ++++--------------- 2 files changed, 43 insertions(+), 15 deletions(-) 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/wayshot.rs b/wayshot/src/wayshot.rs index 7c62fe59..e3abb529 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -56,20 +56,6 @@ fn main() -> Result<()> { } } - let file = match cli.file { - Some(mut pathbuf) => { - if pathbuf.to_string_lossy() == "-" { - None - } else { - if pathbuf.is_dir() { - pathbuf.push(utils::get_default_file_name(requested_encoding)); - } - Some(pathbuf) - } - } - None => Some(utils::get_default_file_name(requested_encoding)), - }; - let wayshot_conn = WayshotConnection::new()?; if cli.list_outputs { @@ -120,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) } } From 9ae737288fe48601d7b1d19075a683da31eaaa94 Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Sat, 23 Mar 2024 22:57:52 +0530 Subject: [PATCH 5/5] docs(wayshot): Improve CLI documentation Signed-off-by: Shinyzenith --- wayshot/src/cli.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wayshot/src/cli.rs b/wayshot/src/cli.rs index eb776912..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 { - ///Provide a custom file path ( encoding format is inferred from the file extension ). If path provided is directory then the output image is saved to provided path with default naming scheme. Default path is ./ , `-` indicates writing to terminal (stdout). - #[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