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