mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-11-03 07:26:35 +00:00
perf: simplify first letter capitalization
This commit is contained in:
parent
577012ff51
commit
83e02d6fb5
1 changed files with 8 additions and 15 deletions
|
|
@ -1,21 +1,13 @@
|
|||
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 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(""));
|
||||
let mut display_backend = display_backend_result.unwrap_or_default();
|
||||
if let Some(c) = display_backend.as_mut_str().get_mut(0..1) {
|
||||
c.make_ascii_uppercase();
|
||||
}
|
||||
|
||||
// Trim "none+" from the start of desktop_env if present
|
||||
// Use "Unknown" if desktop_env is empty or has an error
|
||||
|
|
@ -26,10 +18,11 @@ pub fn get_desktop_info() -> String {
|
|||
|
||||
// Handle the case where display_backend might be empty after capitalization
|
||||
let display_backend = if display_backend.is_empty() {
|
||||
"Unknown".to_string()
|
||||
"Unknown"
|
||||
} else {
|
||||
display_backend
|
||||
};
|
||||
&display_backend
|
||||
}
|
||||
.to_string();
|
||||
|
||||
format!("{desktop_env} ({display_backend})")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue