Debian Codegraph @

src/style/content_style.rs

raw
1 //! This module contains the `content style` that can be applied to an `styled content`.
2
3 use std::fmt::Display;
4
5 use crate::style::{Attributes, Color, StyledContent};
6
7 /// The style that can be put on content.
8 #[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
9 pub struct ContentStyle {
10 /// The foreground color.
11 pub foreground_color: Option<Color>,
12 /// The background color.
13 pub background_color: Option<Color>,
14 /// The underline color.
15 pub underline_color: Option<Color>,
16 /// List of attributes.
17 pub attributes: Attributes,
18 }
19
20 impl ContentStyle {
21 /// Creates a `StyledContent` by applying the style to the given `val`.
22 #[inline]
23 pub fn apply<D: Display>(self, val: D) -> StyledContent<D> {
24 StyledContent::new(self, val)
25 }
26
27 /// Creates a new `ContentStyle`.
28 #[inline]
29 pub fn new() -> ContentStyle {
30 ContentStyle::default()
31 }
32 }
33
34 impl AsRef<ContentStyle> for ContentStyle {
35 fn as_ref(&self) -> &Self {
36 self
37 }
38 }
39 impl AsMut<ContentStyle> for ContentStyle {
40 fn as_mut(&mut self) -> &mut Self {
41 self
42 }
43 }