1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use tui::{
    style::{Color, Modifier, Style},
    text::Span,
};

use crate::generator::{
    helper::{FlattenableSpan, FlattenableStyle},
    Tag, TagConvertor,
};

impl<'a, C> From<Tag<'a, C>> for Style
where
    C: TagConvertor<'a, Color = Color, Modifier = Modifier, Custom = Style>,
{
    fn from(t: Tag<'a, C>) -> Self {
        match t {
            Tag::Fg(c) => Style::default().fg(c),
            Tag::Bg(c) => Style::default().bg(c),
            Tag::Modifier(m) => Style::default().add_modifier(m),
            Tag::Custom(style) => style,
        }
    }
}

impl FlattenableStyle for Style {
    fn patch(self, other: Self) -> Self {
        self.patch(other)
    }
}

impl<'a> FlattenableSpan<'a, Style> for Span<'a> {
    fn with_style(s: &'a str, style: Option<Style>) -> Self {
        match style {
            Some(style) => Span::styled(s, style),
            None => Span::raw(s),
        }
    }
}