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 super::*;
use crate::style::Style;
use ascii_canvas::AsciiView;
use std::fmt::{Debug, Error, Formatter};

pub struct Styled {
    style: Style,
    content: Box<dyn Content>,
}

impl Styled {
    pub fn new(style: Style, content: Box<dyn Content>) -> Self {
        Styled { style, content }
    }
}

impl Content for Styled {
    fn min_width(&self) -> usize {
        self.content.min_width()
    }

    fn emit(&self, view: &mut dyn AsciiView) {
        self.content.emit(&mut view.styled(self.style))
    }

    fn into_wrap_items(self: Box<Self>, wrap_items: &mut Vec<Box<dyn Content>>) {
        let style = self.style;
        super::into_wrap_items_map(self.content, wrap_items, |item| Styled::new(style, item))
    }
}

impl Debug for Styled {
    fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
        fmt.debug_struct("Styled")
            .field("content", &self.content)
            .finish()
    }
}