index : gmss.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-12-21 21:46:11.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2023-12-21 21:46:11.0 +00:00:00
commit
91880a10e978e17aab7059c08ecb81c7ca08a324 [patch]
tree
4ebfc5dd359bd7eeb6dcfbbcd8796cfd75f85c5e
parent
6bcc9795963e04dc25112a818c47d7b3e39f3755
download
91880a10e978e17aab7059c08ecb81c7ca08a324.tar.gz

refactor: simplify cli args



Diff

 src/cli.rs  | 10 +++-------
 src/main.rs |  9 +++++----
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/cli.rs b/src/cli.rs
index 75d895d..ef10bf1 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -2,14 +2,10 @@ use clap::Parser;

#[derive(Parser, Debug)]
pub struct Args {
    /// The format to use for timestamps
    #[arg(long, default_value = "screenshot-%Y-%m-%d_%H-%M-%S.png")]
    pub filename_format: Option<String>,

    /// The output directory to write the file to.
    /// The output directory or file to write the file to.
    ///
    /// If a filename is specified instead of a directory, this will be used
    /// for the output filename in place of `filename_format`.
    /// If a if a directory is specified, a filename will be generated based on
    /// the current date and time.
    #[arg(short, long)]
    pub out: String,
}
diff --git a/src/main.rs b/src/main.rs
index 5155e22..0c14fd5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,11 +11,11 @@ mod imaging;
fn main() {
    let args = cli::Args::parse();

    capture_all_displays(args.out, args.filename_format.unwrap_or_default());
    capture_all_displays(args.out);
}

/// Captures a screenshot of all active displays and writes the resulting image to disk.
fn capture_all_displays(out_dir: String, filename_format: String) {
fn capture_all_displays(filename: String) {
    let captures: Vec<_> = graphics::Display::get_displays()
        .iter()
        .filter_map(|screen| screen.capture().ok())
@@ -25,10 +25,11 @@ fn capture_all_displays(out_dir: String, filename_format: String) {

    if !img.is_empty() {
        let timestamp: DateTime<Local> = Utc::now().with_timezone(&Local);
        const FILENAME_FORMAT: &str = "screenshot-%Y-%m-%d_%H-%M-%S.png";

        let mut path = PathBuf::from(out_dir);
        let mut path = PathBuf::from(timestamp.format(&filename).to_string());
        if path.is_dir() {
            path = path.join(timestamp.format(&filename_format).to_string());
            path = path.join(timestamp.format(FILENAME_FORMAT).to_string());
        }

        match img.save(generate_filename(&path)) {