diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-06-13 05:25:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 01:25:20 -0400 |
commit | 2e5d59f84d056f90c985d762cbc935b081e4bb1b (patch) | |
tree | 4364ddc1f5ac6d672f25705f204c4f5f89c19bfb /src | |
parent | 24234263f07becc1b4c43c65329a217f92defceb (diff) |
other: clean up some cfg usage (#1205)
* other: convert some cfg if
* fix
Diffstat (limited to 'src')
-rw-r--r-- | src/app/layout_manager.rs | 10 | ||||
-rw-r--r-- | src/canvas/dialogs/dd_dialog.rs | 4 | ||||
-rw-r--r-- | src/canvas/widgets/cpu_graph.rs | 24 |
3 files changed, 24 insertions, 14 deletions
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index 4e7d3b0e..94e7f877 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -1012,9 +1012,11 @@ impl std::str::FromStr for BottomWidgetType { "temp" | "temperature" => Ok(BottomWidgetType::Temp), "disk" => Ok(BottomWidgetType::Disk), "empty" => Ok(BottomWidgetType::Empty), - "battery" | "batt" if cfg!(feature = "battery") => Ok(BottomWidgetType::Battery), + #[cfg(feature = "battery")] + "battery" | "batt" => Ok(BottomWidgetType::Battery), _ => { - if cfg!(feature = "battery") { + #[cfg(feature = "battery")] + { Err(BottomError::ConfigError(format!( "\"{}\" is an invalid widget name. @@ -1037,7 +1039,9 @@ Supported widget names: ", s ))) - } else { + } + #[cfg(not(feature = "battery"))] + { Err(BottomError::ConfigError(format!( "\"{}\" is an invalid widget name. diff --git a/src/canvas/dialogs/dd_dialog.rs b/src/canvas/dialogs/dd_dialog.rs index e67faae7..35a0c067 100644 --- a/src/canvas/dialogs/dd_dialog.rs +++ b/src/canvas/dialogs/dd_dialog.rs @@ -247,6 +247,8 @@ impl Painter { ); if app_state.should_get_widget_bounds() { + const SIGNAL: usize = if cfg!(target_os = "windows") { 1 } else { 15 }; + // This is kinda weird, but the gist is: // - We have three sections; we put our mouse bounding box for the "yes" button at the very right edge // of the left section and 3 characters back. We then give it a buffer size of 1 on the x-coordinate. @@ -263,7 +265,7 @@ impl Painter { button_layout[0].y, button_layout[0].x + button_layout[0].width, button_layout[0].y, - if cfg!(target_os = "windows") { 1 } else { 15 }, + SIGNAL, ), // No ( diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs index 2110ec40..e6957ff6 100644 --- a/src/canvas/widgets/cpu_graph.rs +++ b/src/canvas/widgets/cpu_graph.rs @@ -1,6 +1,5 @@ use std::borrow::Cow; -use concat_string::concat_string; use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -201,16 +200,21 @@ impl Painter { ); // TODO: Maybe hide load avg if too long? Or maybe the CPU part. - let title = if cfg!(target_family = "unix") { - let load_avg = app_state.converted_data.load_avg_data; - let load_avg_str = format!( - "─ {:.2} {:.2} {:.2} ", - load_avg[0], load_avg[1], load_avg[2] - ); + let title = { + #[cfg(target_family = "unix")] + { + let load_avg = app_state.converted_data.load_avg_data; + let load_avg_str = format!( + "─ {:.2} {:.2} {:.2} ", + load_avg[0], load_avg[1], load_avg[2] + ); - concat_string!(" CPU ", load_avg_str).into() - } else { - " CPU ".into() + concat_string::concat_string!(" CPU ", load_avg_str).into() + } + #[cfg(not(target_family = "unix"))] + { + " CPU ".into() + } }; let marker = if app_state.app_config_fields.use_dot { |