added displaying functionality of StyledObject

This commit is contained in:
TimonPost 2018-09-20 22:24:10 +02:00
parent e8e8e6242d
commit a92274c028
3 changed files with 40 additions and 2 deletions

View File

@ -9,7 +9,7 @@
extern crate crossterm;
// modules that could be test
mod terminal;
//mod terminal;
mod color;
mod cursor;
mod some_types;
@ -17,6 +17,14 @@ mod input;
use std::io::Write;
use std::{thread,time};
use crossterm::style::{style, Color, DisplayableObject};
use crossterm::terminal::terminal;
use crossterm::Screen;
fn main()
{
let screen = Screen::default();
println!("\nExample:\n\n\taws --profile {} s3 ls\n", DisplayableObject::new(&screen, &style("test").with(Color::Yellow)));
}

View File

@ -20,6 +20,7 @@ use std::fmt::Display;
pub use self::color::{TerminalColor, color};
pub use self::objectstyle::ObjectStyle;
pub use self::styledobject::StyledObject;
pub use self::styledobject::DisplayableObject;
use super::functions;
use TerminalOutput;

View File

@ -14,7 +14,7 @@ pub struct StyledObject<D: Display> {
pub content: D,
}
impl<D: Display> StyledObject<D> {
impl<'a, D: Display> StyledObject<D> {
/// Set the foreground of the styled object to the passed `Color`
///
/// ```rust
@ -179,4 +179,33 @@ impl<D: Display> StyledObject<D> {
colored_terminal.reset();
}
}
// pub fn get_displayable(&self, screen: &'a Screen) -> DisplayableObject<'a, D>
// {
// return DisplayableObject::new(screen, &self)
// }
}
use std::fmt::{Formatter, Error};
pub struct DisplayableObject<'a, D:Display + 'a>
{
styled_object: &'a StyledObject<D>,
screen: &'a Screen,
}
impl <'a, D: Display + 'a> DisplayableObject<'a, D>
{
pub fn new(screen: &'a Screen, styled_object: &'a StyledObject<D>) -> DisplayableObject<'a, D>
{
DisplayableObject { screen, styled_object }
}
}
impl<'a, D: Display + 'a> Display for DisplayableObject<'a, D>
{
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
self.styled_object.paint(&self.screen);
return Ok(())
}
}