crossterm/style/
styled_content.rs1use std::fmt::{self, Display, Formatter};
4
5use super::{ContentStyle, PrintStyledContent};
6
7#[derive(Copy, Clone, Debug, Eq, PartialEq)]
22pub struct StyledContent<D: Display> {
23 style: ContentStyle,
25 content: D,
27}
28
29impl<D: Display> StyledContent<D> {
30 #[inline]
32 pub fn new(style: ContentStyle, content: D) -> StyledContent<D> {
33 StyledContent { style, content }
34 }
35
36 #[inline]
38 pub fn content(&self) -> &D {
39 &self.content
40 }
41
42 #[inline]
44 pub fn style(&self) -> &ContentStyle {
45 &self.style
46 }
47
48 #[inline]
51 pub fn style_mut(&mut self) -> &mut ContentStyle {
52 &mut self.style
53 }
54}
55
56impl<D: Display> AsRef<ContentStyle> for StyledContent<D> {
57 fn as_ref(&self) -> &ContentStyle {
58 &self.style
59 }
60}
61impl<D: Display> AsMut<ContentStyle> for StyledContent<D> {
62 fn as_mut(&mut self) -> &mut ContentStyle {
63 &mut self.style
64 }
65}
66
67impl<D: Display> Display for StyledContent<D> {
68 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
69 crate::command::execute_fmt(
70 f,
71 PrintStyledContent(StyledContent {
72 style: self.style,
73 content: &self.content,
74 }),
75 )
76 }
77}