Skip to content

Commit

Permalink
[docs]Introduce scdoc generation in rust build sys
Browse files Browse the repository at this point in the history
Signed-off-by: Shinyzenith <[email protected]>
  • Loading branch information
Shinyzenith committed Jul 28, 2022
1 parent 20342a5 commit 08a4754
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
*.gz
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
authors = ["\nShinyzenith <https://shinyzenith.xyz> ", " Cmeissl <https://github.com/cmeissl> ", " Victor Berger <https://github.com/vberger>"]
authors = ["Shinyzenith <https://shinyzenith.xyz>"]
description = "Screenshot tool for wlroots based compositors implementing the zwlr_screencopy_v1 protocol."
documentation = "https://docs.rs/crate/wayshot/latest"
edition = "2021"
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
24 changes: 5 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
</p>
</p>

# Usage:
# Some usage examples:

NOTE: Read `man 7 wayshot` for more examples.
NOTE: Read `man wayshot` for flag information.

Region Selection:

Expand All @@ -27,12 +30,6 @@ Fullscreen:
wayshot
```

Custom file path:

```bash
wayshot -f ../screenshot.png --extension jpg
```

Screenshot and copy to clipboard:

```bash
Expand All @@ -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)
Expand All @@ -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

Expand Down
23 changes: 23 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}
62 changes: 62 additions & 0 deletions docs/wayshot.1.scd
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>.
For more information about development, see <https://github.com/waycrate/wayshot>.
46 changes: 46 additions & 0 deletions docs/wayshot.7.scd
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>.
For more information about development, see <https://github.com/waycrate/wayshot>.
2 changes: 1 addition & 1 deletion src/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/wayshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn main() -> Result<(), Box<dyn Error>> {
};

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,
Expand Down

0 comments on commit 08a4754

Please sign in to comment.