Skip to main content

ctl_text/
style.rs

1//! Combining two styles.
2
3use anstyle::Style;
4
5/// `base` with `top` painted over it.
6///
7/// A colour `top` sets (foreground, background, or underline) replaces the one
8/// in `base`; a colour it leaves unset keeps `base`'s. Effects add up, because
9/// [`anstyle::Effects`] has no way to say "not bold": `top` can switch an
10/// effect on but not off.
11#[must_use]
12pub fn overlay(base: Style, top: Style) -> Style {
13    Style::new()
14        .fg_color(top.get_fg_color().or_else(|| base.get_fg_color()))
15        .bg_color(top.get_bg_color().or_else(|| base.get_bg_color()))
16        .underline_color(
17            top.get_underline_color()
18                .or_else(|| base.get_underline_color()),
19        )
20        .effects(base.get_effects() | top.get_effects())
21}