added displaying functionality of StyledObject
This commit is contained in:
parent
e8e8e6242d
commit
a92274c028
@ -9,7 +9,7 @@
|
|||||||
extern crate crossterm;
|
extern crate crossterm;
|
||||||
|
|
||||||
// modules that could be test
|
// modules that could be test
|
||||||
mod terminal;
|
//mod terminal;
|
||||||
mod color;
|
mod color;
|
||||||
mod cursor;
|
mod cursor;
|
||||||
mod some_types;
|
mod some_types;
|
||||||
@ -17,6 +17,14 @@ mod input;
|
|||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::{thread,time};
|
use std::{thread,time};
|
||||||
|
|
||||||
|
use crossterm::style::{style, Color, DisplayableObject};
|
||||||
|
use crossterm::terminal::terminal;
|
||||||
|
use crossterm::Screen;
|
||||||
|
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
|
let screen = Screen::default();
|
||||||
|
|
||||||
|
println!("\nExample:\n\n\taws --profile {} s3 ls\n", DisplayableObject::new(&screen, &style("test").with(Color::Yellow)));
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ use std::fmt::Display;
|
|||||||
pub use self::color::{TerminalColor, color};
|
pub use self::color::{TerminalColor, color};
|
||||||
pub use self::objectstyle::ObjectStyle;
|
pub use self::objectstyle::ObjectStyle;
|
||||||
pub use self::styledobject::StyledObject;
|
pub use self::styledobject::StyledObject;
|
||||||
|
pub use self::styledobject::DisplayableObject;
|
||||||
use super::functions;
|
use super::functions;
|
||||||
use TerminalOutput;
|
use TerminalOutput;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ pub struct StyledObject<D: Display> {
|
|||||||
pub content: D,
|
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`
|
/// Set the foreground of the styled object to the passed `Color`
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
@ -179,4 +179,33 @@ impl<D: Display> StyledObject<D> {
|
|||||||
colored_terminal.reset();
|
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user