[][src]Struct crossterm_style::styledobject::StyledObject

pub struct StyledObject<D: Display> {
    pub object_style: ObjectStyle,
    pub content: D,
}

Struct that contains both the style and the content wits can be styled.

Fields

object_style: ObjectStylecontent: D

Methods

impl<'a, D: Display + 'a> StyledObject<D>
[src]

pub fn with(self, foreground_color: Color) -> StyledObject<D>
[src]

Set the foreground of the styled object to the passed Color.

Remarks

This methods consumes 'self', and works like a builder. By having this functionality you can do: with().on().attr()

pub fn on(self, background_color: Color) -> StyledObject<D>
[src]

Set the background of the styled object to the passed Color.

Remarks

This methods consumes 'self', and works like a builder. By having this functionality you can do: with().on().attr()

pub fn attr(self, attr: Attribute) -> StyledObject<D>
[src]

Set the attribute of an styled object to the passed Attribute.

Remarks

This methods consumes 'self', and works like a builder. By having this functionality you can do: with().on().attr()

pub fn bold(self) -> StyledObject<D>
[src]

Increase the font intensity.

pub fn underlined(self) -> StyledObject<D>
[src]

Underline font.

pub fn negative(self) -> StyledObject<D>
[src]

Invert colours.

pub fn into_displayable(
    self,
    stdout: &'a Arc<TerminalOutput>
) -> DisplayableObject<'a, D>
[src]

This converts an styled object into an DisplayableObject witch implements: Display and could be used inside the write function of the standard library.

StyledObject already implements Display right?

This is true, however there are some complex issues why this won't work on alternate screen. That is the reason why this functions exists. You could just pass in the 'screen' from your alternate screen to this method and your StyledObject will be printed to the alternate screen just fine.

   let screen = Screen::default(); /* represents the alternate screen */
   let styled_object = style("test").with(Color::Yellow);
   let display_object = styled_object.into_displayable(&screen);
   println!("Colored text: {}. Default color", display_object);

pub fn paint(&self, stdout: &Arc<TerminalOutput>) -> Result<()>
[src]

This could be used to paint the styled object onto the given screen. You have to pass a reference to the screen whereon you want to perform the painting.

style("Some colored text")
    .with(Color::Blue)
    .on(Color::Black)
    .paint(&screen);

You should take not that StyledObject implements Display. You don't need to call paint unless you are on alternate screen. Checkout into_displayable() for more information about this.

Trait Implementations

impl<D: Display> Display for StyledObject<D>
[src]

Auto Trait Implementations

impl<D> Send for StyledObject<D> where
    D: Send

impl<D> Sync for StyledObject<D> where
    D: Sync

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]