From 2fc94ce2b74fee4a1fc72ea6de8dc55431eab561 Mon Sep 17 00:00:00 2001 From: Moridius Date: Thu, 10 Sep 2020 08:05:17 +0200 Subject: [PATCH] Added an option to press Enter after typing. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 13 ++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da9febd..ad3f007 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "blinddate" -version = "0.2.1" +version = "0.3.0" dependencies = [ "chrono", "enigo", diff --git a/Cargo.toml b/Cargo.toml index 9be887e..ec63f6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blinddate" -version = "0.2.1" +version = "0.3.0" authors = ["Moridius "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index 2dc96e2..bff78be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,7 @@ fn calc_date(command: &str, today: Date) -> Result, ()> { Err(()) } -fn type_date(date: Date, alt_tab: bool) { +fn type_date(date: Date, alt_tab: bool, enter: bool) { let date_str = format!("{}", date.format("%Y-%m-%d")); let mut enigo = Enigo::new(); if alt_tab { @@ -64,19 +64,26 @@ fn type_date(date: Date, alt_tab: bool) { enigo.key_up(Key::Alt); thread::sleep(time::Duration::from_millis(100)); } + for c in date_str.chars() { enigo.key_click(Key::Layout(c)); } - // enigo.key_click(Key::Return); + + if enter { + enigo.key_click(Key::Return); + } } fn main() { let mut command = String::new(); let mut alt_tab = false; + let mut enter = false; for arg in env::args().skip(1) { if arg == "--tab" { alt_tab = true; + } else if arg == "--enter" { + enter = true; } else { command = arg.to_lowercase(); break; @@ -84,7 +91,7 @@ fn main() { } if let Ok(date) = command_to_date(&command) { - type_date(date, alt_tab); + type_date(date, alt_tab, enter); } else { eprintln!("blinddate"); eprintln!("Calculates a date and types it. Use with a shell script to enter dates into files rapidly.");