Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support italic text styling #1514

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- [#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.
- [#1514](https://github.com/ClementTsang/bottom/pull/1514): Support italic text styling options.

### Changes

Expand Down Expand Up @@ -47,7 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.9.7] - 2023-08-26

## Other
## Bug Fixes

- [#1500](https://github.com/ClementTsang/bottom/issues/1500): Fix builds for Rust 1.80.

Expand Down
7 changes: 7 additions & 0 deletions schema/nightly/bottom.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,13 @@
"type": "null"
}
]
},
"italics": {
"description": "Whether to make this text italicized or not. If not set, will default to built-in defaults.",
"type": [
"boolean",
"null"
]
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/options/config/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ pub(crate) enum TextStyleConfig {
/// Whether to make this text bolded or not. If not set,
/// will default to built-in defaults.
bold: Option<bool>,

/// Whether to make this text italicized or not. If not set,
/// will default to built-in defaults.
italics: Option<bool>,
},
}

Expand Down
19 changes: 17 additions & 2 deletions src/options/config/style/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
$palette_field = $palette_field.fg(
crate::options::config::style::utils::str_to_colour(&fg.0)
Expand Down Expand Up @@ -188,6 +188,14 @@ macro_rules! set_style {
$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);
}
}
}
}
}
Expand Down Expand Up @@ -435,16 +443,19 @@ mod test {
color: None,
bg_color: None,
bold: None,
italics: None,
}),
text_c: Some(TextStyleConfig::TextStyle {
color: Some(ColorStr("magenta".into())),
bg_color: Some(ColorStr("255, 255, 255".into())),
bold: Some(true),
italics: Some(false),
}),
text_d: Some(TextStyleConfig::TextStyle {
color: Some(ColorStr("#fff".into())),
bg_color: Some(ColorStr("1, 1, 1".into())),
bold: Some(false),
italics: Some(true),
}),
text_e: None,
bad_color: Some(ColorStr("asdf".into())),
Expand All @@ -457,11 +468,13 @@ mod test {
color: Some(ColorStr("asdf".into())),
bg_color: None,
bold: None,
italics: None,
}),
bad_text_b: Some(TextStyleConfig::TextStyle {
color: None,
bg_color: Some(ColorStr("asdf".into())),
bold: None,
italics: None,
}),
}
}
Expand Down Expand Up @@ -562,11 +575,13 @@ mod test {
assert_eq!(s.fg.unwrap(), Color::Magenta);
assert_eq!(s.bg.unwrap(), Color::Rgb(255, 255, 255));
assert!(s.add_modifier.contains(Modifier::BOLD));
assert!(!s.add_modifier.contains(Modifier::ITALIC));

set_style!(s, &dummy.inner, text_d);
assert_eq!(s.fg.unwrap(), Color::Rgb(255, 255, 255));
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(())
}
Expand Down
7 changes: 7 additions & 0 deletions tests/valid_configs/styling.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ bold = false
[styles.tables]
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
[styles.widgets]
selected_text = "#fff"
Expand Down