refactor(src/commands): Cleanup command printing and simplify GPU environment handling

Enhancements:
- Remove unnecessary multiline formatting in GPU, status, and temperature commands
- Consolidate zone type checks into a single condition
- Simplify environment variable tuple definitions
This commit is contained in:
sankalp committed 2026-05-29 16:38:24 +05:45
1 parent 3684c5b071
commit 34a57007d1
3 files changed
+11 -33

No files matched your search

+3 -12
View File
@@ -864,18 +864,9 @@ fn run_on_dgpu(command: &[String]) {
} }
let env_vars = vec![ let env_vars = vec![
( ("__NV_PRIME_RENDER_OFFLOAD", "1".to_string()),
"__NV_PRIME_RENDER_OFFLOAD", ("__GLX_VENDOR_LIBRARY_NAME", "nvidia".to_string()),
"1".to_string(), ("__VK_LAYER_NV_optimus", "NVIDIA_only".to_string()),
),
(
"__GLX_VENDOR_LIBRARY_NAME",
"nvidia".to_string(),
),
(
"__VK_LAYER_NV_optimus",
"NVIDIA_only".to_string(),
),
]; ];
let mut cmd = Command::new(&command[0]); let mut cmd = Command::new(&command[0]);
+1 -5
View File
@@ -208,11 +208,7 @@ pub fn execute() {
if let Some(line) = stdout.lines().next() { if let Some(line) = stdout.lines().next() {
let parts: Vec<&str> = line.split(", ").collect(); let parts: Vec<&str> = line.split(", ").collect();
if parts.len() >= 2 { if parts.len() >= 2 {
println!( println!("GPU: {} @ {}°C (NVIDIA)", parts[0].trim(), parts[1].trim());
"GPU: {} @ {}°C (NVIDIA)",
parts[0].trim(),
parts[1].trim()
);
} }
} }
} }
+7 -16
View File
@@ -43,10 +43,7 @@ pub fn execute() {
other => other, other => other,
}; };
println!( println!(" {} ({}): {:.1}°C", display_name, label_str, celsius);
" {} ({}): {:.1}°C",
display_name, label_str, celsius
);
found = true; found = true;
} }
@@ -71,11 +68,7 @@ pub fn execute() {
&& let Ok(temp_c) = temp.trim().parse::<f64>() && let Ok(temp_c) = temp.trim().parse::<f64>()
{ {
let info = if parts.len() >= 3 { let info = if parts.len() >= 3 {
format!( format!(" [{} @ {}]", parts[1].trim(), parts[2].trim())
" [{} @ {}]",
parts[1].trim(),
parts[2].trim()
)
} else { } else {
String::new() String::new()
}; };
@@ -102,18 +95,16 @@ pub fn execute() {
let type_path = entry.path().join("type"); let type_path = entry.path().join("type");
let temp_path = entry.path().join("temp"); let temp_path = entry.path().join("temp");
if let (Ok(type_content), Ok(temp_content)) = if let (Ok(type_content), Ok(temp_content)) = (
(fs::read_to_string(&type_path), fs::read_to_string(&temp_path)) fs::read_to_string(&type_path),
{ fs::read_to_string(&temp_path),
) {
let zone_type = type_content.trim(); let zone_type = type_content.trim();
let millideg: i64 = temp_content.trim().parse().unwrap_or(0); let millideg: i64 = temp_content.trim().parse().unwrap_or(0);
let celsius = millideg as f64 / 1000.0; let celsius = millideg as f64 / 1000.0;
// Skip if we already showed this from hwmon // Skip if we already showed this from hwmon
if zone_type == "x86_pkg_temp" if zone_type == "x86_pkg_temp" || zone_type == "k10temp" || zone_type == "acpitz" {
|| zone_type == "k10temp"
|| zone_type == "acpitz"
{
continue; continue;
} }