mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 14:44:18 +00:00
other: clean up some cfg usage (#1205)
* other: convert some cfg if * fix
This commit is contained in:
parent
24234263f0
commit
2e5d59f84d
4 changed files with 38 additions and 32 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
(
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -165,27 +165,23 @@ fn test_missing_default_widget_type() {
|
|||
#[test]
|
||||
#[cfg_attr(feature = "battery", ignore)]
|
||||
fn test_battery_flag() {
|
||||
if !cfg!(feature = "battery") {
|
||||
btm_command()
|
||||
.arg("--battery")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"unexpected argument '--battery' found",
|
||||
));
|
||||
}
|
||||
btm_command()
|
||||
.arg("--battery")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"unexpected argument '--battery' found",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(feature = "gpu", ignore)]
|
||||
fn test_gpu_flag() {
|
||||
if !cfg!(feature = "gpu") {
|
||||
btm_command()
|
||||
.arg("--enable_gpu_memory")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"unexpected argument '--enable_gpu_memory' found",
|
||||
));
|
||||
}
|
||||
btm_command()
|
||||
.arg("--enable_gpu_memory")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"unexpected argument '--enable_gpu_memory' found",
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue