Skip to content

Commit 34a5700

Browse files
committed
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
1 parent 3684c5b commit 34a5700

3 files changed

Lines changed: 11 additions & 33 deletions

File tree

src/commands/gpu.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -864,18 +864,9 @@ fn run_on_dgpu(command: &[String]) {
864864
}
865865

866866
let env_vars = vec![
867-
(
868-
"__NV_PRIME_RENDER_OFFLOAD",
869-
"1".to_string(),
870-
),
871-
(
872-
"__GLX_VENDOR_LIBRARY_NAME",
873-
"nvidia".to_string(),
874-
),
875-
(
876-
"__VK_LAYER_NV_optimus",
877-
"NVIDIA_only".to_string(),
878-
),
867+
("__NV_PRIME_RENDER_OFFLOAD", "1".to_string()),
868+
("__GLX_VENDOR_LIBRARY_NAME", "nvidia".to_string()),
869+
("__VK_LAYER_NV_optimus", "NVIDIA_only".to_string()),
879870
];
880871

881872
let mut cmd = Command::new(&command[0]);

src/commands/status.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ pub fn execute() {
208208
if let Some(line) = stdout.lines().next() {
209209
let parts: Vec<&str> = line.split(", ").collect();
210210
if parts.len() >= 2 {
211-
println!(
212-
"GPU: {} @ {}°C (NVIDIA)",
213-
parts[0].trim(),
214-
parts[1].trim()
215-
);
211+
println!("GPU: {} @ {}°C (NVIDIA)", parts[0].trim(), parts[1].trim());
216212
}
217213
}
218214
}

src/commands/temperature.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ pub fn execute() {
4343
other => other,
4444
};
4545

46-
println!(
47-
" {} ({}): {:.1}°C",
48-
display_name, label_str, celsius
49-
);
46+
println!(" {} ({}): {:.1}°C", display_name, label_str, celsius);
5047
found = true;
5148
}
5249

@@ -71,11 +68,7 @@ pub fn execute() {
7168
&& let Ok(temp_c) = temp.trim().parse::<f64>()
7269
{
7370
let info = if parts.len() >= 3 {
74-
format!(
75-
" [{} @ {}]",
76-
parts[1].trim(),
77-
parts[2].trim()
78-
)
71+
format!(" [{} @ {}]", parts[1].trim(), parts[2].trim())
7972
} else {
8073
String::new()
8174
};
@@ -102,18 +95,16 @@ pub fn execute() {
10295
let type_path = entry.path().join("type");
10396
let temp_path = entry.path().join("temp");
10497

105-
if let (Ok(type_content), Ok(temp_content)) =
106-
(fs::read_to_string(&type_path), fs::read_to_string(&temp_path))
107-
{
98+
if let (Ok(type_content), Ok(temp_content)) = (
99+
fs::read_to_string(&type_path),
100+
fs::read_to_string(&temp_path),
101+
) {
108102
let zone_type = type_content.trim();
109103
let millideg: i64 = temp_content.trim().parse().unwrap_or(0);
110104
let celsius = millideg as f64 / 1000.0;
111105

112106
// Skip if we already showed this from hwmon
113-
if zone_type == "x86_pkg_temp"
114-
|| zone_type == "k10temp"
115-
|| zone_type == "acpitz"
116-
{
107+
if zone_type == "x86_pkg_temp" || zone_type == "k10temp" || zone_type == "acpitz" {
117108
continue;
118109
}
119110

0 commit comments

Comments
 (0)