mirror of
https://github.com/NotAShelf/microfetch.git
synced 2024-11-01 14:51:14 +00:00
capitalize first letter of session type
wayland -> Wayland, x11 -> X11
This commit is contained in:
parent
6cad15c330
commit
b792d41fcc
2 changed files with 30 additions and 12 deletions
|
@ -1,17 +1,35 @@
|
||||||
pub fn get_desktop_info() -> String {
|
pub fn get_desktop_info() -> String {
|
||||||
|
fn capitalize_first_letter(s: &str) -> String {
|
||||||
|
if s.is_empty() {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut chars = s.chars();
|
||||||
|
let first_char = chars.next().unwrap().to_uppercase().to_string();
|
||||||
|
let rest: String = chars.collect();
|
||||||
|
first_char + &rest
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the environment variables and handle Result types
|
||||||
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");
|
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");
|
||||||
let display_backend = std::env::var("XDG_SESSION_TYPE");
|
let display_backend_result = std::env::var("XDG_SESSION_TYPE");
|
||||||
|
|
||||||
|
// Capitalize the first letter of the display backend value
|
||||||
|
let display_backend = capitalize_first_letter(display_backend_result.as_deref().unwrap_or(""));
|
||||||
|
|
||||||
// Trim "none+" from the start of desktop_env if present
|
// Trim "none+" from the start of desktop_env if present
|
||||||
// XXX: This is a workaround for NixOS modules that set XDG_CURRENT_DESKTOP to "none+foo"
|
// Use "Unknown" if desktop_env is empty or has an error
|
||||||
// instead of just "foo"
|
let desktop_env = match desktop_env {
|
||||||
// Use "Unknown" if desktop_env or display_backend is empty
|
Err(_) => "Unknown".to_string(),
|
||||||
let desktop_env = match desktop_env.as_ref() {
|
Ok(s) => s.trim_start_matches("none+").to_string(),
|
||||||
Err(_) => "Unknown",
|
|
||||||
Ok(s) => s.trim_start_matches("none+"),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let display_backend = display_backend.unwrap_or(String::from("Unknown"));
|
// Handle the case where display_backend might be empty after capitalization
|
||||||
|
let display_backend = if display_backend.is_empty() {
|
||||||
|
"Unknown".to_string()
|
||||||
|
} else {
|
||||||
|
display_backend
|
||||||
|
};
|
||||||
|
|
||||||
format!("{desktop_env} ({display_backend})")
|
format!("{desktop_env} ({display_backend})")
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn main() -> Result<(), Report> {
|
||||||
kernel_version: get_system_info()?,
|
kernel_version: get_system_info()?,
|
||||||
shell: get_shell(),
|
shell: get_shell(),
|
||||||
uptime: get_current()?,
|
uptime: get_current()?,
|
||||||
window_manager: get_desktop_info(),
|
desktop: get_desktop_info(),
|
||||||
memory_usage: get_memory_usage(sysinfo()?),
|
memory_usage: get_memory_usage(sysinfo()?),
|
||||||
storage: get_root_disk_usage()?,
|
storage: get_root_disk_usage()?,
|
||||||
colors: print_dots(),
|
colors: print_dots(),
|
||||||
|
@ -43,7 +43,7 @@ struct Fields {
|
||||||
kernel_version: String,
|
kernel_version: String,
|
||||||
shell: String,
|
shell: String,
|
||||||
uptime: String,
|
uptime: String,
|
||||||
window_manager: String,
|
desktop: String,
|
||||||
memory_usage: String,
|
memory_usage: String,
|
||||||
storage: String,
|
storage: String,
|
||||||
colors: String,
|
colors: String,
|
||||||
|
@ -56,7 +56,7 @@ fn print_system_info(fields: &Fields) {
|
||||||
kernel_version,
|
kernel_version,
|
||||||
shell,
|
shell,
|
||||||
uptime,
|
uptime,
|
||||||
window_manager,
|
desktop,
|
||||||
memory_usage,
|
memory_usage,
|
||||||
storage,
|
storage,
|
||||||
colors,
|
colors,
|
||||||
|
@ -69,7 +69,7 @@ fn print_system_info(fields: &Fields) {
|
||||||
{CYAN} ▀▀▀▀▀▀▀▀▀▀▀▘{BLUE}▝██ {CYAN}▟█▖ {CYAN} {BLUE}Kernel{RESET} {kernel_version}
|
{CYAN} ▀▀▀▀▀▀▀▀▀▀▀▘{BLUE}▝██ {CYAN}▟█▖ {CYAN} {BLUE}Kernel{RESET} {kernel_version}
|
||||||
{BLUE} ▟█▛ {BLUE}▝█▘{CYAN}▟█▛ {CYAN} {BLUE}Shell{RESET} {shell}
|
{BLUE} ▟█▛ {BLUE}▝█▘{CYAN}▟█▛ {CYAN} {BLUE}Shell{RESET} {shell}
|
||||||
{BLUE}▟█████▛ {CYAN}▟█████▛ {CYAN} {BLUE}Uptime{RESET} {uptime}
|
{BLUE}▟█████▛ {CYAN}▟█████▛ {CYAN} {BLUE}Uptime{RESET} {uptime}
|
||||||
{BLUE} ▟█▛{CYAN}▗█▖ {CYAN}▟█▛ {CYAN} {BLUE}WM{RESET} {window_manager}
|
{BLUE} ▟█▛{CYAN}▗█▖ {CYAN}▟█▛ {CYAN} {BLUE}Desktop{RESET} {desktop}
|
||||||
{BLUE} ▝█▛ {CYAN}██▖{BLUE}▗▄▄▄▄▄▄▄▄▄▄▄ {CYAN} {BLUE}Memory{RESET} {memory_usage}
|
{BLUE} ▝█▛ {CYAN}██▖{BLUE}▗▄▄▄▄▄▄▄▄▄▄▄ {CYAN} {BLUE}Memory{RESET} {memory_usage}
|
||||||
{BLUE} ▝ {CYAN}▟█▜█▖{BLUE}▀▀▀▀▀██▛▀▀▘ {CYAN} {BLUE}Storage (/){RESET} {storage}
|
{BLUE} ▝ {CYAN}▟█▜█▖{BLUE}▀▀▀▀▀██▛▀▀▘ {CYAN} {BLUE}Storage (/){RESET} {storage}
|
||||||
{CYAN} ▟█▘ ▜█▖ {BLUE}▝█▛ {CYAN} {BLUE}Colors{RESET} {colors}");
|
{CYAN} ▟█▘ ▜█▖ {BLUE}▝█▛ {CYAN} {BLUE}Colors{RESET} {colors}");
|
||||||
|
|
Loading…
Reference in a new issue