Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
v0.2: better formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
blandinw committed Aug 5, 2018
1 parent 04dc46e commit 2760222
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,7 @@ fn nsdict_get<T: From<FromId>>(dict: id, key: &str) -> T {
}

fn human_time(minutes: i64) -> String {
let mut x = minutes;

let mins = x % 60;
if x < 60 {
return format!("{}m", mins);
}

x /= 60;
let hours = x % 24;
if x < 24 {
return format!("{}h{}m", hours, mins);
}

x /= 24;
format!("{}d{}h{}m", x, hours, mins)
return format!("{}:{:02}", minutes / 60, minutes % 60);
}

fn generate_title() -> String {
Expand All @@ -119,30 +105,30 @@ fn generate_title() -> String {
let current_pct = 100. * current_cap as f64 / max_cap as f64;

#[allow(non_upper_case_globals)]
match state.as_ref() {
match state.as_ref() {
kIOPSBatteryPowerValue => {
let mins = nsdict_get::<i32>(nsdict, kIOPSTimeToEmptyKey);
if mins == kIOPSTimeRemainingUnknown as i32 {
format!("{}%", current_pct)
} else {
format!(
"{} ({}%)",
human_time(mins as i64),
current_pct
)
}
format!(
"\u{2193} {}({}%)",
if mins == 0 || mins == kIOPSTimeRemainingUnknown as i32 {
String::from("")
} else {
format!("{} ", human_time(mins as i64))
},
current_pct
)
}
kIOPSACPowerValue => {
let mins = nsdict_get::<i32>(nsdict, kIOPSTimeToFullChargeKey);
if mins == kIOPSTimeRemainingUnknown as i32 {
format!("{}%", current_pct)
} else {
format!(
"{} ({}%%)",
human_time(mins as i64),
current_pct
)
}
format!(
"\u{2191} {}({}%)",
if mins == 0 || mins == kIOPSTimeRemainingUnknown as i32 {
String::from("")
} else {
format!("{} ", human_time(mins as i64))
},
current_pct
)
}
&_ => {
String::from("\u{1F914}")
Expand Down

0 comments on commit 2760222

Please sign in to comment.