-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This "improves" (and that is subjective) the design of the CLI. I am aiming to get some feedback on what people think of the new design: ``` Screenshot tool for wlroots based compositors implementing the zwlr_screencopy_v1 protocol. Usage: wayshot [OPTIONS] [OUTPUT] Arguments: [OUTPUT] Where to save the screenshot, "-" for stdout. Defaults to "$UNIX_TIMESTAMP-wayshot.$EXTENSION" Options: --log-level <LOG_LEVEL> Log level to be used for printing to stderr [default: info] [possible values: trace, debug, info, warn, error] -s, --slurp <SLURP_ARGS> Arguments to call slurp with for selecting a region -c, --cursor Enable cursor in screenshots --encoding <FILE_EXTENSION> Set image encoder, if output file contains an extension, that will be used instead [default: png] [aliases: extension, format, output-format] Possible values: - jpg: JPG/JPEG encoder - png: PNG encoder - ppm: PPM encoder - qoi: Qut encoder -l, --list-outputs List all valid outputs -o, --output <OUTPUT> Choose a particular output/display to screenshot --choose-output Present a fuzzy selector for output/display selection -h, --help Print help (see a summary with '-h') -V, --version Print version ``` The main changes are: 1. `--debug` is now `--log-level` because this makes it easy to select more specifically what log level to use. I considered using `-v`, `-vv`... to increase verbosity but the `clap-verbosity-crate` uses `log` and not `tracing`. We could use it somewhat, but we'd pull in `log` (which seems fine) and we'd need to map from `log`'s Level to `tracing`'s Level enums (they use inverse ordering). 2. `--stdout` and `--file` has been made an optional positional argument. This because it's what other CLIs often do and I wasn't sure what to call the option otherwise because `--output` and `-O`/`-o` is often what others use but we use it here to refer to displays/monitors/Wayland outputs. This avoids that confusion hopefully and I've also clarified this in the documentation. * Additionally if a path is given, its extension will always be used. So you cannot save `jpg` to `foo.png`. Perhaps this behaviour can be changed, though I don't see a reason to support this weird edge case? When is someone saving `png` to `jpg`? 3. `--extension` is `--encoding` with aliases like `extension`. Again, let me know what you think.
- Loading branch information
1 parent
c866e52
commit 3dc85cb
Showing
4 changed files
with
88 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,8 @@ target | |
*.gz | ||
*.out | ||
.direnv | ||
*.jpg | ||
*.jpeg | ||
*.png | ||
*.ppm | ||
*.qoi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,44 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::arg; | ||
|
||
use clap::Parser; | ||
|
||
use crate::utils::EncodingFormat; | ||
use clap::builder::TypedValueParser; | ||
|
||
#[derive(Parser)] | ||
#[command(version, about)] | ||
pub struct Cli { | ||
/// Enable debug mode | ||
#[arg(short, long, action = clap::ArgAction::SetTrue)] | ||
pub debug: bool, | ||
/// Where to save the screenshot, "-" for stdout. Defaults to "$UNIX_TIMESTAMP-wayshot.$EXTENSION". | ||
#[arg(value_name = "OUTPUT")] | ||
pub file: Option<PathBuf>, | ||
|
||
/// Log level to be used for printing to stderr | ||
#[arg(long, default_value = "info", value_parser = clap::builder::PossibleValuesParser::new(["trace", "debug", "info", "warn", "error"]).map(|s| -> tracing::Level{ s.parse().unwrap()}))] | ||
pub log_level: tracing::Level, | ||
|
||
/// Arguments to call slurp with for selecting a region | ||
#[arg(short, long, value_name = "SLURP_ARGS")] | ||
pub slurp: Option<String>, | ||
|
||
/// Mention a custom file path | ||
#[arg(short, long, conflicts_with = "stdout", value_name = "FILE_PATH")] | ||
pub file: Option<String>, | ||
|
||
/// Output the image data to standard out | ||
#[arg(long, conflicts_with = "file", action = clap::ArgAction::SetTrue)] | ||
pub stdout: bool, | ||
|
||
/// Enable cursor in screenshots | ||
#[arg(short, long, action = clap::ArgAction::SetTrue)] | ||
#[arg(short, long)] | ||
pub cursor: bool, | ||
|
||
/// Set image encoder (Png is default) | ||
#[arg(short, long, value_name = "FILE_EXTENSION")] | ||
pub extension: Option<String>, | ||
/// Set image encoder, if output file contains an extension, that will be used instead. | ||
#[arg(long, visible_aliases = ["extension", "format", "output-format"], value_name = "FILE_EXTENSION", default_value = "png")] | ||
pub encoding: EncodingFormat, | ||
|
||
/// List all valid outputs | ||
#[arg(short, long, alias = "listoutputs", action = clap::ArgAction::SetTrue)] | ||
#[arg(short, long, alias = "listoutputs")] | ||
pub list_outputs: bool, | ||
|
||
/// Choose a particular display to screenshot | ||
/// Choose a particular output/display to screenshot | ||
#[arg(short, long, conflicts_with = "slurp")] | ||
pub output: Option<String>, | ||
|
||
/// Present a fuzzy selector for outputs | ||
#[arg(long, alias = "chooseoutput", conflicts_with_all = ["slurp", "output"], action = clap::ArgAction::SetTrue)] | ||
/// Present a fuzzy selector for output/display selection | ||
#[arg(long, alias = "chooseoutput", conflicts_with_all = ["slurp", "output"])] | ||
pub choose_output: bool, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters