mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-07 05:44:35 +02:00
other: clean up some cfg usage (#1205)
* other: convert some cfg if * fix
This commit is contained in:
parent
24234263f0
commit
2e5d59f84d
@ -1012,9 +1012,11 @@ impl std::str::FromStr for BottomWidgetType {
|
|||||||
"temp" | "temperature" => Ok(BottomWidgetType::Temp),
|
"temp" | "temperature" => Ok(BottomWidgetType::Temp),
|
||||||
"disk" => Ok(BottomWidgetType::Disk),
|
"disk" => Ok(BottomWidgetType::Disk),
|
||||||
"empty" => Ok(BottomWidgetType::Empty),
|
"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!(
|
Err(BottomError::ConfigError(format!(
|
||||||
"\"{}\" is an invalid widget name.
|
"\"{}\" is an invalid widget name.
|
||||||
|
|
||||||
@ -1037,7 +1039,9 @@ Supported widget names:
|
|||||||
",
|
",
|
||||||
s
|
s
|
||||||
)))
|
)))
|
||||||
} else {
|
}
|
||||||
|
#[cfg(not(feature = "battery"))]
|
||||||
|
{
|
||||||
Err(BottomError::ConfigError(format!(
|
Err(BottomError::ConfigError(format!(
|
||||||
"\"{}\" is an invalid widget name.
|
"\"{}\" is an invalid widget name.
|
||||||
|
|
||||||
|
@ -247,6 +247,8 @@ impl Painter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if app_state.should_get_widget_bounds() {
|
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:
|
// 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
|
// - 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.
|
// 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].y,
|
||||||
button_layout[0].x + button_layout[0].width,
|
button_layout[0].x + button_layout[0].width,
|
||||||
button_layout[0].y,
|
button_layout[0].y,
|
||||||
if cfg!(target_os = "windows") { 1 } else { 15 },
|
SIGNAL,
|
||||||
),
|
),
|
||||||
// No
|
// No
|
||||||
(
|
(
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use concat_string::concat_string;
|
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
layout::{Constraint, Direction, Layout, Rect},
|
layout::{Constraint, Direction, Layout, Rect},
|
||||||
@ -201,16 +200,21 @@ impl Painter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// TODO: Maybe hide load avg if too long? Or maybe the CPU part.
|
// TODO: Maybe hide load avg if too long? Or maybe the CPU part.
|
||||||
let title = if cfg!(target_family = "unix") {
|
let title = {
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
{
|
||||||
let load_avg = app_state.converted_data.load_avg_data;
|
let load_avg = app_state.converted_data.load_avg_data;
|
||||||
let load_avg_str = format!(
|
let load_avg_str = format!(
|
||||||
"─ {:.2} {:.2} {:.2} ",
|
"─ {:.2} {:.2} {:.2} ",
|
||||||
load_avg[0], load_avg[1], load_avg[2]
|
load_avg[0], load_avg[1], load_avg[2]
|
||||||
);
|
);
|
||||||
|
|
||||||
concat_string!(" CPU ", load_avg_str).into()
|
concat_string::concat_string!(" CPU ", load_avg_str).into()
|
||||||
} else {
|
}
|
||||||
|
#[cfg(not(target_family = "unix"))]
|
||||||
|
{
|
||||||
" CPU ".into()
|
" CPU ".into()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let marker = if app_state.app_config_fields.use_dot {
|
let marker = if app_state.app_config_fields.use_dot {
|
||||||
|
@ -165,7 +165,6 @@ fn test_missing_default_widget_type() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(feature = "battery", ignore)]
|
#[cfg_attr(feature = "battery", ignore)]
|
||||||
fn test_battery_flag() {
|
fn test_battery_flag() {
|
||||||
if !cfg!(feature = "battery") {
|
|
||||||
btm_command()
|
btm_command()
|
||||||
.arg("--battery")
|
.arg("--battery")
|
||||||
.assert()
|
.assert()
|
||||||
@ -174,12 +173,10 @@ fn test_battery_flag() {
|
|||||||
"unexpected argument '--battery' found",
|
"unexpected argument '--battery' found",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(feature = "gpu", ignore)]
|
#[cfg_attr(feature = "gpu", ignore)]
|
||||||
fn test_gpu_flag() {
|
fn test_gpu_flag() {
|
||||||
if !cfg!(feature = "gpu") {
|
|
||||||
btm_command()
|
btm_command()
|
||||||
.arg("--enable_gpu_memory")
|
.arg("--enable_gpu_memory")
|
||||||
.assert()
|
.assert()
|
||||||
@ -188,4 +185,3 @@ fn test_gpu_flag() {
|
|||||||
"unexpected argument '--enable_gpu_memory' found",
|
"unexpected argument '--enable_gpu_memory' found",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user