Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added --human-time flag #92

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions wayshot/src/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <FILE_EXTENSION>)
.required(false)
Expand Down
33 changes: 32 additions & 1 deletion wayshot/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
}
};

Expand Down
27 changes: 15 additions & 12 deletions wayshot/src/wayshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ fn main() -> Result<(), Box<dyn Error>> {
} else {
EncodingFormat::Png
};

let mut file_is_stdout: bool = false;
let mut file_path: Option<String> = None;

if args.get_flag("stdout") {
file_is_stdout = true;
} else if let Some(filepath) = args.get_one::<String>("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") {
Expand Down Expand Up @@ -116,6 +104,21 @@ fn main() -> Result<(), Box<dyn Error>> {
wayshot_conn.screenshot_all(cursor_overlay)?
};

let mut file_is_stdout: bool = false;
let mut file_path: Option<String> = None;

if args.get_flag("stdout") {
file_is_stdout = true;
} else if let Some(filepath) = args.get_one::<String>("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());
Expand Down
Loading