Skip to main content

tui/rendering/
span.rs

1use super::style::Style;
2
3/// A contiguous run of text sharing a single [`Style`].
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct Span {
6    pub(crate) text: String,
7    pub(crate) style: Style,
8}
9
10impl Span {
11    pub fn new(text: impl Into<String>) -> Self {
12        Self {
13            text: text.into(),
14            style: Style::default(),
15        }
16    }
17
18    pub fn with_style(text: impl Into<String>, style: Style) -> Self {
19        Self {
20            text: text.into(),
21            style,
22        }
23    }
24
25    pub fn text(&self) -> &str {
26        &self.text
27    }
28
29    pub fn style(&self) -> Style {
30        self.style
31    }
32}