tui_markup/generator/ratatui/
span.rs

1use ratatui::{
2    style::{Color, Modifier, Style},
3    text::Span,
4};
5
6use crate::generator::{
7    helper::{FlattenableSpan, FlattenableStyle},
8    Tag, TagConvertor,
9};
10
11impl<'a, C> From<Tag<'a, C>> for Style
12where
13    C: TagConvertor<'a, Color = Color, Modifier = Modifier, Custom = Style>,
14{
15    fn from(t: Tag<'a, C>) -> Self {
16        match t {
17            Tag::Fg(c) => Style::default().fg(c),
18            Tag::Bg(c) => Style::default().bg(c),
19            Tag::Modifier(m) => Style::default().add_modifier(m),
20            Tag::Custom(style) => style,
21        }
22    }
23}
24
25impl FlattenableStyle for Style {
26    fn patch(self, other: Self) -> Self {
27        self.patch(other)
28    }
29}
30
31impl<'a> FlattenableSpan<'a, Style> for Span<'a> {
32    fn with_style(s: &'a str, style: Option<Style>) -> Self {
33        match style {
34            Some(style) => Span::styled(s, style),
35            None => Span::raw(s),
36        }
37    }
38}