You've already forked neo64fetch
mirror of
https://github.com/neoarz/neo64fetch.git
synced 2026-02-08 22:33:26 +01:00
fix: formatting for display and battery
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use std::process::Command;
|
||||
|
||||
pub fn get_battery_info() -> String {
|
||||
pub fn get_battery_info() -> (String, String) {
|
||||
let output = Command::new("ioreg")
|
||||
.args(["-l", "-w0", "-r", "-c", "AppleSmartBattery"])
|
||||
.output();
|
||||
|
||||
let stdout = match output {
|
||||
Ok(out) => String::from_utf8_lossy(&out.stdout).to_string(),
|
||||
Err(_) => return "<unknown>".to_string(),
|
||||
Err(_) => return ("".to_string(), "<unknown>".to_string()),
|
||||
};
|
||||
|
||||
let mut device_name = "Built-in".to_string();
|
||||
@@ -60,22 +60,21 @@ pub fn get_battery_info() -> String {
|
||||
if capacity >= 0 && capacity <= 100 {
|
||||
capacity as u32
|
||||
} else {
|
||||
return "<unknown>".to_string();
|
||||
return (format!("({})", device_name), "<unknown>".to_string());
|
||||
}
|
||||
} else {
|
||||
return "<unknown>".to_string();
|
||||
return (format!("({})", device_name), "<unknown>".to_string());
|
||||
};
|
||||
|
||||
let mut status = String::new();
|
||||
if external_connected {
|
||||
status.push_str("AC connected");
|
||||
let status = if external_connected {
|
||||
"AC connected"
|
||||
} else if is_charging {
|
||||
status.push_str("Charging");
|
||||
"Charging"
|
||||
} else {
|
||||
status.push_str("Discharging");
|
||||
}
|
||||
"Discharging"
|
||||
};
|
||||
|
||||
let mut result = format!("({}) {}", device_name, crate::output::colors::battery_percent(percentage));
|
||||
let mut result = crate::output::colors::battery_percent(percentage);
|
||||
|
||||
if !external_connected && !is_charging {
|
||||
if let Some(time_mins) = avg_time_to_empty {
|
||||
@@ -96,5 +95,6 @@ pub fn get_battery_info() -> String {
|
||||
|
||||
result.push_str(&format!(" [{}]", status));
|
||||
|
||||
result
|
||||
(format!("({})", device_name), result)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ use display_info::DisplayInfo;
|
||||
|
||||
pub fn get_display_info() -> String {
|
||||
let displays = DisplayInfo::all().unwrap_or_else(|_| vec![]);
|
||||
let display_count = displays.len();
|
||||
|
||||
if let Some(main) = displays.iter().find(|d| d.is_primary) {
|
||||
let p_width = (main.width as f32 * main.scale_factor) as u32;
|
||||
@@ -10,22 +11,24 @@ pub fn get_display_info() -> String {
|
||||
let diag_mm = ((main.width_mm as f32).powi(2) + (main.height_mm as f32).powi(2)).sqrt();
|
||||
let inches = (diag_mm / 25.4).round() as u32;
|
||||
|
||||
let name = if main.name.is_empty() {
|
||||
"Color LCD"
|
||||
} else {
|
||||
&main.name
|
||||
};
|
||||
|
||||
let tag = if main.is_primary {
|
||||
"[Built-in]"
|
||||
} else {
|
||||
"[External]"
|
||||
};
|
||||
|
||||
if display_count > 1 {
|
||||
let name = if main.name.is_empty() { "Color LCD" } else { &main.name };
|
||||
format!(
|
||||
"({}): {}x{} @ {}x in {}\", {} Hz {}",
|
||||
"({}) {}x{} @ {}x in {}\", {} Hz {}",
|
||||
name, p_width, p_height, main.scale_factor as u32, inches, main.frequency as u32, tag
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{}x{} @ {}x in {}\", {} Hz {}",
|
||||
p_width, p_height, main.scale_factor as u32, inches, main.frequency as u32, tag
|
||||
)
|
||||
}
|
||||
} else {
|
||||
"unknown".to_string()
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ struct Stats {
|
||||
swap: String,
|
||||
storage: String,
|
||||
ip: String,
|
||||
battery: String,
|
||||
battery: (String, String), // (device_name, info)
|
||||
locale: String,
|
||||
|
||||
// Extra fields
|
||||
@@ -108,7 +108,7 @@ fn main() {
|
||||
println!("{}", colors::info("Disk (/)", &stats.storage));
|
||||
// Don't wanna show print this lolol
|
||||
// println!("{}", colors::info("Local IP", &stats.ip));
|
||||
println!("{}", colors::info("Battery", &stats.battery));
|
||||
println!("{}", colors::info(&format!("Battery {}", stats.battery.0), &stats.battery.1));
|
||||
println!("{}", colors::info("Locale", &stats.locale));
|
||||
|
||||
// color blocks
|
||||
|
||||
Reference in New Issue
Block a user