feature: support italic text styling (#1514)

Support italics as a text styling option.
This commit is contained in:
Clement Tsang 2024-07-31 01:54:26 +00:00 committed by GitHub
parent c77256eaaf
commit 4b14ccb56b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 3 deletions

View File

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1353](https://github.com/ClementTsang/bottom/pull/1353): Support selecting the average CPU graph as a default. - [#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. - [#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. - [#1512](https://github.com/ClementTsang/bottom/pull/1512): Support bold text styling options.
- [#1514](https://github.com/ClementTsang/bottom/pull/1514): Support italic text styling options.
### Changes ### Changes
@ -47,7 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.9.7] - 2023-08-26 ## [0.9.7] - 2023-08-26
## Other ## Bug Fixes
- [#1500](https://github.com/ClementTsang/bottom/issues/1500): Fix builds for Rust 1.80. - [#1500](https://github.com/ClementTsang/bottom/issues/1500): Fix builds for Rust 1.80.

View File

@ -912,6 +912,13 @@
"type": "null" "type": "null"
} }
] ]
},
"italics": {
"description": "Whether to make this text italicized or not. If not set, will default to built-in defaults.",
"type": [
"boolean",
"null"
]
} }
} }
} }

View File

@ -49,6 +49,10 @@ pub(crate) enum TextStyleConfig {
/// Whether to make this text bolded or not. If not set, /// Whether to make this text bolded or not. If not set,
/// will default to built-in defaults. /// will default to built-in defaults.
bold: Option<bool>, bold: Option<bool>,
/// Whether to make this text italicized or not. If not set,
/// will default to built-in defaults.
italics: Option<bool>,
}, },
} }

View File

@ -148,7 +148,7 @@ macro_rules! set_style {
})? })?
); );
} }
TextStyleConfig::TextStyle {color, bg_color, bold} => { TextStyleConfig::TextStyle {color, bg_color, bold, italics} => {
if let Some(fg) = &color { if let Some(fg) = &color {
$palette_field = $palette_field.fg( $palette_field = $palette_field.fg(
crate::options::config::style::utils::str_to_colour(&fg.0) crate::options::config::style::utils::str_to_colour(&fg.0)
@ -188,6 +188,14 @@ macro_rules! set_style {
$palette_field = $palette_field.remove_modifier(tui::style::Modifier::BOLD); $palette_field = $palette_field.remove_modifier(tui::style::Modifier::BOLD);
} }
} }
if let Some(italics) = &italics {
if *italics {
$palette_field = $palette_field.add_modifier(tui::style::Modifier::ITALIC);
} else {
$palette_field = $palette_field.remove_modifier(tui::style::Modifier::ITALIC);
}
}
} }
} }
} }
@ -435,16 +443,19 @@ mod test {
color: None, color: None,
bg_color: None, bg_color: None,
bold: None, bold: None,
italics: None,
}), }),
text_c: Some(TextStyleConfig::TextStyle { text_c: Some(TextStyleConfig::TextStyle {
color: Some(ColorStr("magenta".into())), color: Some(ColorStr("magenta".into())),
bg_color: Some(ColorStr("255, 255, 255".into())), bg_color: Some(ColorStr("255, 255, 255".into())),
bold: Some(true), bold: Some(true),
italics: Some(false),
}), }),
text_d: Some(TextStyleConfig::TextStyle { text_d: Some(TextStyleConfig::TextStyle {
color: Some(ColorStr("#fff".into())), color: Some(ColorStr("#fff".into())),
bg_color: Some(ColorStr("1, 1, 1".into())), bg_color: Some(ColorStr("1, 1, 1".into())),
bold: Some(false), bold: Some(false),
italics: Some(true),
}), }),
text_e: None, text_e: None,
bad_color: Some(ColorStr("asdf".into())), bad_color: Some(ColorStr("asdf".into())),
@ -457,11 +468,13 @@ mod test {
color: Some(ColorStr("asdf".into())), color: Some(ColorStr("asdf".into())),
bg_color: None, bg_color: None,
bold: None, bold: None,
italics: None,
}), }),
bad_text_b: Some(TextStyleConfig::TextStyle { bad_text_b: Some(TextStyleConfig::TextStyle {
color: None, color: None,
bg_color: Some(ColorStr("asdf".into())), bg_color: Some(ColorStr("asdf".into())),
bold: None, bold: None,
italics: None,
}), }),
} }
} }
@ -562,11 +575,13 @@ mod test {
assert_eq!(s.fg.unwrap(), Color::Magenta); assert_eq!(s.fg.unwrap(), Color::Magenta);
assert_eq!(s.bg.unwrap(), Color::Rgb(255, 255, 255)); assert_eq!(s.bg.unwrap(), Color::Rgb(255, 255, 255));
assert!(s.add_modifier.contains(Modifier::BOLD)); assert!(s.add_modifier.contains(Modifier::BOLD));
assert!(!s.add_modifier.contains(Modifier::ITALIC));
set_style!(s, &dummy.inner, text_d); set_style!(s, &dummy.inner, text_d);
assert_eq!(s.fg.unwrap(), Color::Rgb(255, 255, 255)); assert_eq!(s.fg.unwrap(), Color::Rgb(255, 255, 255));
assert_eq!(s.bg.unwrap(), Color::Rgb(1, 1, 1)); assert_eq!(s.bg.unwrap(), Color::Rgb(1, 1, 1));
assert!(s.add_modifier.is_empty()); assert!(!s.add_modifier.contains(Modifier::BOLD));
assert!(s.add_modifier.contains(Modifier::ITALIC));
Ok(()) Ok(())
} }

View File

@ -12,6 +12,13 @@ bold = false
[styles.tables] [styles.tables]
headers = { color = "red", bg_color = "black", bold = true } headers = { color = "red", bg_color = "black", bold = true }
# Test italics
[styles.widgets.widget_title]
color = "#0f0f0f"
bg_color = "#f0f0f0"
bold = true
italics = true
# Test using normal colour where inline table can also work # Test using normal colour where inline table can also work
[styles.widgets] [styles.widgets]
selected_text = "#fff" selected_text = "#fff"