crossterm/style/
content_style.rs

1//! This module contains the `content style` that can be applied to an `styled content`.
2
3use std::fmt::Display;
4
5use crate::style::{Attributes, Color, StyledContent};
6
7/// The style that can be put on content.
8#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
9pub 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
20impl 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
34impl AsRef<ContentStyle> for ContentStyle {
35    fn as_ref(&self) -> &Self {
36        self
37    }
38}
39impl AsMut<ContentStyle> for ContentStyle {
40    fn as_mut(&mut self) -> &mut Self {
41        self
42    }
43}