From 08a47542fcab2abc6b664c242597c348c3113c5d Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Fri, 29 Jul 2022 01:44:37 +0530 Subject: [PATCH] [docs]Introduce scdoc generation in rust build sys Signed-off-by: Shinyzenith --- .gitignore | 1 + Cargo.toml | 2 +- Makefile | 5 ++++ README.md | 24 ++++-------------- build.rs | 23 +++++++++++++++++ docs/wayshot.1.scd | 62 ++++++++++++++++++++++++++++++++++++++++++++++ docs/wayshot.7.scd | 46 ++++++++++++++++++++++++++++++++++ src/clap.rs | 2 +- src/wayshot.rs | 2 +- 9 files changed, 145 insertions(+), 22 deletions(-) create mode 100644 build.rs create mode 100644 docs/wayshot.1.scd create mode 100644 docs/wayshot.7.scd diff --git a/.gitignore b/.gitignore index eb5a316c..d6b8e722 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target +*.gz diff --git a/Cargo.toml b/Cargo.toml index 12ffd837..4da69c50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -authors = ["\nShinyzenith ", " Cmeissl ", " Victor Berger "] +authors = ["Shinyzenith "] description = "Screenshot tool for wlroots based compositors implementing the zwlr_screencopy_v1 protocol." documentation = "https://docs.rs/crate/wayshot/latest" edition = "2021" diff --git a/Makefile b/Makefile index 47b25a49..6238945e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ BINARY := wayshot BUILDFLAGS := --release TARGET_DIR := /usr/bin SOURCE_DIR := ./target/release +MAN1_DIR := /usr/share/man/man1 +MAN7_DIR := /usr/share/man/man7 all: build @@ -15,9 +17,12 @@ install: @mkdir -p $(TARGET_DIR) @cp $(SOURCE_DIR)/$(BINARY) $(TARGET_DIR) @chmod +x $(TARGET_DIR)/$(BINARY) + @cp ./docs/*.1.gz $(MAN1_DIR) + @cp ./docs/*.7.gz $(MAN7_DIR) uninstall: @rm $(TARGET_DIR)/$(BINARY) + @rm /usr/share/man/**/wayshot.* check: @cargo fmt diff --git a/README.md b/README.md index 660b2a68..3ecb54e5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,10 @@

-# Usage: +# Some usage examples: + +NOTE: Read `man 7 wayshot` for more examples. +NOTE: Read `man wayshot` for flag information. Region Selection: @@ -27,12 +30,6 @@ Fullscreen: wayshot ``` -Custom file path: - -```bash -wayshot -f ../screenshot.png --extension jpg -``` - Screenshot and copy to clipboard: ```bash @@ -45,18 +42,6 @@ Pick a hex color code, using ImageMagick: wayshot -s "$(slurp -p -f '%x %y %w %h')" --stdout | convert - -format '%[pixel:p{0,0}]' txt:-|egrep "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})" -o ``` -Pick a hex color code without using ImageMagick: - -```bash -wayshot -s "$(slurp -p -f '%x %y %w %h')" --stdout -e ppm | tail -c 3 | od -An -tuC | xargs printf '#%02X%02X%02X\n' -``` - -Pick a color, using ImageMagick: - -```bash -wayshot -s "$(slurp -p -f '%x %y %w %h')" --stdout | convert - -format '%[pixel:p{0,0}]' txt:- -``` - # Known bugs: Multi monitor systems break on `--slurp` usage. This is quite the tricky bug and will need some refactoring which we're currently working on. (https://github.com/waycrate/wayshot/issues/7) @@ -69,6 +54,7 @@ Multi monitor systems break on `--slurp` usage. This is quite the tricky bug and ## Compile time dependencies: +- scdoc (If present, man-pages will be generated.) - rustup - make diff --git a/build.rs b/build.rs new file mode 100644 index 00000000..75238269 --- /dev/null +++ b/build.rs @@ -0,0 +1,23 @@ +use std::{fs::read_dir, process::Command}; + +fn main() { + let mut man_pages: Vec<(String, String)> = Vec::new(); + for path in read_dir("./docs").unwrap() { + let path = path.unwrap(); + if path.file_type().unwrap().is_dir() { + continue; + } + + if let Some(file_name) = path.path().to_str() { + let man_page_name = file_name.replace(".scd", ".gz"); + man_pages.push((file_name.to_string(), man_page_name)); + } + } + + for man_page in man_pages { + _ = Command::new("sh") + .arg("-c") + .arg(format!("scdoc <{}>{}", man_page.0, man_page.1)) + .spawn(); + } +} diff --git a/docs/wayshot.1.scd b/docs/wayshot.1.scd new file mode 100644 index 00000000..88eef23d --- /dev/null +++ b/docs/wayshot.1.scd @@ -0,0 +1,62 @@ +wayshot(1) "github.com/waycrate/wayshot" "General Commands Manual" + +# NAME + +Wayshot - Screenshot tool for compositors implementing zwlr_screencopy_v1 such as sway and river + +# SYNOPSIS + +*wayshot* [_options_] + +# OPTIONS + +*-h*, *--help* + Print help message and quit. + +*-V*, *--version* + Print version information. + +*-d*, *--debug* + Enable debug mode. + +*-c*, *--cursor* + Enable cursor visibility in screenshots. + +*-e*, *--extension* + Set the image encoder. + Valid arguments: + - jpeg + - jpg + - png (Default encoder) + - ppm + +*-f*, *--file* + Set a custom file path. The default path is `./{current_unix_timestamp}-wayshot.{encoder}` + eg: 1659034753-wayshot.png + +*-l*, *--listoutputs* + List all valid output names. This flag is generally used in combination with *-o* flag. + +*-o*, *--output* + Choose a particular display (wl_output) to screenshot. + +*-s*, *--slurp* + Choose a portion of your display to screenshot using the slurp program. + https://github.com/emersion/slurp + +*--stdout* + Emit image data to stdout. The following flag is helpful to pipe image data + to other programs. + +# KNOWN BUGS + +Feel free to send patches for the following: +- *--slurp* flag does not work as intended on multi monitor systems. After multiple attempts at fixing this I have failed time and again. + +# SEE ALSO + - wayshot(7) + +# AUTHORS + +Maintained by Shinyzenith . +For more information about development, see . diff --git a/docs/wayshot.7.scd b/docs/wayshot.7.scd new file mode 100644 index 00000000..6ac3f114 --- /dev/null +++ b/docs/wayshot.7.scd @@ -0,0 +1,46 @@ +wayshot(7) "github.com/waycrate/wayshot" "Miscellaneous Information Manual" + +# NAME + +Wayshot - Screenshot tool for compositors implementing zwlr_screencopy_v1 such as sway and river + +# SYNOPSIS + +*wayshot* [_options_] + +# REGION SELECTION +wayshot -s "$(slurp -f '%x %y %w %h')" + +# FULLSCREEN + +wayshot + +# CUSTOM FILE PATH AND EXTENSION + +wayshot -f ../screenshot.png --extension ppm + +# SCREENSHOT AND COPY TO CLIPBOARD + +wayshot --stdout -e jpeg | wl-copy + +# SCREENSHOT A PARTICULAR DISPLAY + +wayshot -l # Pick any output name from the following. We use eDP-1 for this example. +wayshot -o eDP-1 + +# PICK A HEX COLOR CODE, USING IMAGEMAGICk + +wayshot -s "$(slurp -p -f '%x %y %w %h')" --stdout | convert - -format '%[pixel:p{0,0}]' txt:-|egrep "#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})" -o + +# PICK A HEX COLOR CODE WITHOUT USING IMAGEMAGICK + +wayshot -s "$(slurp -p -f '%x %y %w %h')" --stdout -e ppm | tail -c 3 | od -An -tuC | xargs printf '#%02X%02X%02X\n' + +# PICK A COLOR, USING IMAGEMAGICK + +wayshot -s "$(slurp -p -f '%x %y %w %h')" --stdout | convert - -format '%[pixel:p{0,0}]' txt:- + +# AUTHORS + +Maintained by Shinyzenith . +For more information about development, see . diff --git a/src/clap.rs b/src/clap.rs index 52147b04..397ec281 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -4,7 +4,7 @@ pub fn set_flags() -> Command<'static> { let app = Command::new("wayshot") .version(env!("CARGO_PKG_VERSION")) .author(env!("CARGO_PKG_AUTHORS")) - .about("Simple screenshot tool for wlroots based compositors") + .about("Screenshot tool for compositors implementing zwlr_screencopy_v1.") .arg( arg!(-d - -debug) .required(false) diff --git a/src/wayshot.rs b/src/wayshot.rs index 77cf6cd6..5ce07817 100644 --- a/src/wayshot.rs +++ b/src/wayshot.rs @@ -111,7 +111,7 @@ fn main() -> Result<(), Box> { }; let extension = if args.is_present("extension") { - let ext = args.value_of("extension").unwrap().trim(); + let ext: &str = &args.value_of("extension").unwrap().trim().to_lowercase(); match ext { "jpeg" | "jpg" => backend::EncodingFormat::Jpg, "png" => backend::EncodingFormat::Png,