diff --git a/wayshot/src/clap.rs b/wayshot/src/clap.rs index 37319334..db61cd9f 100644 --- a/wayshot/src/clap.rs +++ b/wayshot/src/clap.rs @@ -37,6 +37,13 @@ pub fn set_flags() -> Command { .action(ArgAction::SetTrue) .help("Output the image data to standard out"), ) + .arg( + arg!(--time_stamp) + .required(false) + .conflicts_with("file") + .action(ArgAction::SetTrue) + .help("Uses human readable time for image file name"), + ) .arg( arg!(-e --extension ) .required(false) diff --git a/wayshot/src/utils.rs b/wayshot/src/utils.rs index e24caf74..ac1b4bf2 100644 --- a/wayshot/src/utils.rs +++ b/wayshot/src/utils.rs @@ -80,7 +80,38 @@ pub fn get_default_file_name(extension: EncodingFormat) -> String { Ok(n) => n.as_secs().to_string(), Err(_) => { tracing::error!("SystemTime before UNIX EPOCH!"); - exit(1); + // didn't think this place needed to exit + String::from("") + } + }; + + time + "-wayshot." + extension.into() +} +fn get_hour_minute_from_unix_seconds(seconds: u64) -> String { + let total_minutes = seconds / 60; + + let mut current_hour = (((total_minutes / 60) % 24) + 5) % 24; + + let mut current_minute = (total_minutes % 60) + 30; + // println!("{}", current_minute); + if current_minute > 60 { + current_hour += 1; + } + current_minute = current_minute % 60; + if current_hour == 24 { + current_hour = 0; + } + + // println!("{}", total_minutes as f64 / 60.0); + + format!("{}:{}:{}", current_hour, current_minute, seconds % 60) +} +pub fn get_human_time_file_name(extension: EncodingFormat) -> String { + let time = match SystemTime::now().duration_since(UNIX_EPOCH) { + Ok(n) => get_hour_minute_from_unix_seconds(n.as_secs()), + Err(_) => { + tracing::error!("SystemTime before UNIX EPOCH!"); + String::from("") } }; diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index b4b3c01f..d8ea7478 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -58,18 +58,6 @@ fn main() -> Result<(), Box> { } else { EncodingFormat::Png }; - - let mut file_is_stdout: bool = false; - let mut file_path: Option = None; - - if args.get_flag("stdout") { - file_is_stdout = true; - } else if let Some(filepath) = args.get_one::("file") { - file_path = Some(filepath.trim().to_string()); - } else { - file_path = Some(utils::get_default_file_name(extension)); - } - let wayshot_conn = WayshotConnection::new()?; if args.get_flag("listoutputs") { @@ -116,6 +104,21 @@ fn main() -> Result<(), Box> { wayshot_conn.screenshot_all(cursor_overlay)? }; + let mut file_is_stdout: bool = false; + let mut file_path: Option = None; + + if args.get_flag("stdout") { + file_is_stdout = true; + } else if let Some(filepath) = args.get_one::("file") { + file_path = Some(filepath.trim().to_string()); + } else { + if args.get_flag("time_stamp") { + file_path = Some(utils::get_human_time_file_name(extension)); + } else { + file_path = Some(utils::get_default_file_name(extension)); + } + } + if file_is_stdout { let stdout = stdout(); let mut buffer = Cursor::new(Vec::new());