Skip to content

Instantly share code, notes, and snippets.

@Akendo
Created February 26, 2021 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akendo/aeaeb3957663d134472a76f1fb8d277a to your computer and use it in GitHub Desktop.
Save Akendo/aeaeb3957663d134472a76f1fb8d277a to your computer and use it in GitHub Desktop.
extern crate datetime;
use std::env::args;
use std::{thread, time};
use std::process::Command;
use datetime::{LocalDate, Month, DatePiece};
const MINUTE: u64= 60;
fn main() {
let args: Vec<String> = args().collect();
if (args.len() == 2)
{
let name = &args[0];
let time_to_sleep_arg = &args[1].clone();
// This create some odd situation. you'll be hit with a Result<T,E> document.
// not quite sure how to handle this. Seems like a struct with the std::String:Result
// The main question is, how to get this right?
// With Beni:
// unwrap() would be possible
// The error is i use collect and trigger some nosense.
let time_to_sleep_arg2 = &args[1];
println!("Going to sleep for: {} seconds at .", time_to_sleep_arg);
let time_to_sleep :u64 = match time_to_sleep_arg.trim().parse() {
Ok(v) => v,
Err(_) => {panic!("Sorry we need to have number only")},
};
let mut remaining_time = time_to_sleep;
let mut time_as_minutes = 0;
while (remaining_time >= MINUTE){
remaining_time = remaining_time - MINUTE;
time_as_minutes = time_as_minutes + 1;
}
println!("More than 1 Minute!");
println!("Going to sleep for {} Minutes!", time_as_minutes);
let mut minutes_remaining = 0;
while(minutes_remaining != time_as_minutes)
{
minutes_remaining = minutes_remaining + 1;
let second = time::Duration::from_secs(60);
thread::sleep(second);
println!("Going to sleep for {} more Minutes", time_as_minutes - minutes_remaining );
}
// sleep the remaining time
let remaining_second = time::Duration::from_secs(remaining_time);
thread::sleep(remaining_second);
Command::new("/usr/bin/notify-send")
.args(&["-u", "normal", "-t", "15000", "StopClock", "Times up!"])
.output();
// https://doc.rust-lang.org/std/process/struct.Command.html
Command::new("/usr/bin/mplayer")
.args(&["-volume","50", "/home/akendo/Downloads/end.mp3"])
.output();
}
else
{
println!("Please add only one argument!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment