index : gmss.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-12-19 19:59:27.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2023-12-19 21:19:08.0 +00:00:00
commit
0823ae2a16c42434ee2e9401049dd3fb52eb7d1e [patch]
tree
832544acace6e336c9465fa67f02b732e90e1117
parent
23847da33baa0ed61eadce25a90199c751ddb0a3
download
0823ae2a16c42434ee2e9401049dd3fb52eb7d1e.tar.gz

feat: add filename formatting



Diff

 Cargo.toml  | 1 +
 src/main.rs | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml
index 40ad268..6b8b219 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,4 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = "0.4.31"
screenshots = "0.8.6"
diff --git a/src/main.rs b/src/main.rs
index 3479e0a..28d5875 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
use chrono::{DateTime, Local, Utc};
use screenshots::{image::ImageBuffer, Screen};

fn main() {
@@ -39,7 +40,12 @@ fn capture_all() {
        });

    if !img.is_empty() {
        match img.save("target/capture.png") {
        let filename: DateTime<Local> = Utc::now().with_timezone(&Local);

        match img.save(format!(
            "target/{}.png",
            filename.format("%Y-%m-%d_%H-%M-%S")
        )) {
            Ok(_) => println!("screenshot saved successfully!"),
            Err(err) => println!("there was an error saving the image: {:?}", err),
        }