Compare commits
No commits in common. "2fc94ce2b74fee4a1fc72ea6de8dc55431eab561" and "c608fd2668ab5a4ca373af2b2479c3b46393af8f" have entirely different histories.
2fc94ce2b7
...
c608fd2668
|
@ -14,7 +14,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
|||
|
||||
[[package]]
|
||||
name = "blinddate"
|
||||
version = "0.3.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"enigo",
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
[package]
|
||||
name = "blinddate"
|
||||
version = "0.3.0"
|
||||
version = "0.2.0"
|
||||
authors = ["Moridius <moridius-github@posteo.hu>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4"
|
||||
enigo = "0.0"
|
||||
chrono = "0.4.9"
|
||||
enigo = "0.0.13"
|
||||
|
|
44
src/main.rs
44
src/main.rs
|
@ -13,18 +13,18 @@ fn command_to_date(command: &str) -> Result<Date<Local>, ()> {
|
|||
}
|
||||
|
||||
fn calc_date(command: &str, today: Date<Local>) -> Result<Date<Local>, ()> {
|
||||
let offset = if command == "today" {
|
||||
Ok(0)
|
||||
let wday = today.weekday().num_days_from_monday() as i64;
|
||||
if command == "today" {
|
||||
return Ok(today);
|
||||
} else if command == "tomorrow" {
|
||||
Ok(1)
|
||||
return Ok(today + Duration::days(1));
|
||||
} else if command == "yesterday" {
|
||||
Ok(-1)
|
||||
return Ok(today - Duration::days(1));
|
||||
} else if command == "daybeforeyesterday" {
|
||||
Ok(-2)
|
||||
return Ok(today - Duration::days(2));
|
||||
} else if command == "dayaftertomorrow" {
|
||||
Ok(2)
|
||||
return Ok(today + Duration::days(2));
|
||||
} else if command.starts_with("next") || command.starts_with("last") {
|
||||
let wday = today.weekday().num_days_from_monday() as i64;
|
||||
let target = match &command[4..] {
|
||||
"monday" => Ok(0),
|
||||
"tuesday" => Ok(1),
|
||||
|
@ -38,24 +38,17 @@ fn calc_date(command: &str, today: Date<Local>) -> Result<Date<Local>, ()> {
|
|||
|
||||
if let Ok(target) = target {
|
||||
if command.starts_with("next") {
|
||||
Ok((target - wday + 7 - 1) % 7 + 1)
|
||||
} else {
|
||||
Ok(-((wday - target + 7 - 1) % 7 + 1))
|
||||
let offset = (target - wday + 7 - 1) % 7 + 1;
|
||||
return Ok(today + Duration::days(offset));
|
||||
}
|
||||
} else {
|
||||
Err(())
|
||||
let offset = (wday - target + 7 - 1) % 7 + 1;
|
||||
return Ok(today - Duration::days(offset));
|
||||
}
|
||||
} else {
|
||||
return Err(());
|
||||
};
|
||||
|
||||
if let Ok(offset) = offset {
|
||||
return Ok(today + Duration::days(offset));
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
|
||||
fn type_date(date: Date<Local>, alt_tab: bool, enter: bool) {
|
||||
fn type_date(date: Date<Local>, alt_tab: bool) {
|
||||
let date_str = format!("{}", date.format("%Y-%m-%d"));
|
||||
let mut enigo = Enigo::new();
|
||||
if alt_tab {
|
||||
|
@ -64,26 +57,19 @@ fn type_date(date: Date<Local>, alt_tab: bool, enter: 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));
|
||||
}
|
||||
|
||||
if enter {
|
||||
enigo.key_click(Key::Return);
|
||||
}
|
||||
// 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) {
|
||||
for arg in env::args() {
|
||||
if arg == "--tab" {
|
||||
alt_tab = true;
|
||||
} else if arg == "--enter" {
|
||||
enter = true;
|
||||
} else {
|
||||
command = arg.to_lowercase();
|
||||
break;
|
||||
|
@ -91,7 +77,7 @@ fn main() {
|
|||
}
|
||||
|
||||
if let Ok(date) = command_to_date(&command) {
|
||||
type_date(date, alt_tab, enter);
|
||||
type_date(date, alt_tab);
|
||||
} else {
|
||||
eprintln!("blinddate");
|
||||
eprintln!("Calculates a date and types it. Use with a shell script to enter dates into files rapidly.");
|
||||
|
|
Loading…
Reference in New Issue