diff --git a/CHANGELOG.md b/CHANGELOG.md index 58a88759..7b3248be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#1276](https://github.com/ClementTsang/bottom/pull/1276): Add GPU process info. - [#1353](https://github.com/ClementTsang/bottom/pull/1353): Support selecting the average CPU graph as a default. - [#1430](https://github.com/ClementTsang/bottom/pull/1430): Support controlling the graph legend position for memory and network graph widgets. +- [#1512](https://github.com/ClementTsang/bottom/pull/1512): Support bold text styling options. ### Changes diff --git a/src/options/config/style/utils.rs b/src/options/config/style/utils.rs index c4cadc41..bb5d283c 100644 --- a/src/options/config/style/utils.rs +++ b/src/options/config/style/utils.rs @@ -148,7 +148,7 @@ macro_rules! set_style { })? ); } - TextStyleConfig::TextStyle {color, bg_color, bold: _} => { + TextStyleConfig::TextStyle {color, bg_color, bold} => { if let Some(fg) = &color { $palette_field = $palette_field.fg( crate::options::config::style::utils::str_to_colour(&fg.0) @@ -180,6 +180,14 @@ macro_rules! set_style { })? ); } + + if let Some(bold) = &bold { + if *bold { + $palette_field = $palette_field.add_modifier(tui::style::Modifier::BOLD); + } else { + $palette_field = $palette_field.remove_modifier(tui::style::Modifier::BOLD); + } + } } } } @@ -236,7 +244,7 @@ pub(super) use {opt, set_colour, set_colour_list, set_style}; #[cfg(test)] mod test { - use tui::style::Style; + use tui::style::{Modifier, Style}; use crate::options::config::style::{ColorStr, TextStyleConfig}; @@ -408,6 +416,10 @@ mod test { text_c: Option, text_d: Option, text_e: Option, + bad_color: Option, + bad_list: Option>, + bad_text_a: Option, + bad_text_b: Option, } impl Default for InnerDummyConfig { @@ -427,14 +439,30 @@ mod test { text_c: Some(TextStyleConfig::TextStyle { color: Some(ColorStr("magenta".into())), bg_color: Some(ColorStr("255, 255, 255".into())), - bold: Some(false), + bold: Some(true), }), text_d: Some(TextStyleConfig::TextStyle { color: Some(ColorStr("#fff".into())), bg_color: Some(ColorStr("1, 1, 1".into())), - bold: Some(true), + bold: Some(false), }), text_e: None, + bad_color: Some(ColorStr("asdf".into())), + bad_list: Some(vec![ + ColorStr("red".into()), + ColorStr("asdf".into()), + ColorStr("ghi".into()), + ]), + bad_text_a: Some(TextStyleConfig::TextStyle { + color: Some(ColorStr("asdf".into())), + bg_color: None, + bold: None, + }), + bad_text_b: Some(TextStyleConfig::TextStyle { + color: None, + bg_color: Some(ColorStr("asdf".into())), + bold: None, + }), } } } @@ -465,6 +493,21 @@ mod test { Ok(()) } + #[test] + fn test_bad_set_colour() { + let mut _s = Style::default().fg(Color::Black); + let dummy = DummyConfig { + inner: Some(InnerDummyConfig::default()), + }; + + (move || -> anyhow::Result<()> { + set_colour!(_s, &dummy.inner, bad_color); + + Ok(()) + })() + .unwrap_err(); + } + #[test] fn test_set_multi_colours() -> anyhow::Result<()> { let mut s: Vec