Giter VIP home page Giter VIP logo

Comments (6)

TimonPost avatar TimonPost commented on July 24, 2024 1

I think this will be the way to go: I will add another function so you do not need to create the DisplayableObject itself manually instead StyledObject will have this function:

pub fn into_displayable(self, screen: &'a Screen) -> DisplayableObject<'a, D>
{
     return DisplayableObject::new(screen, self)
}

So now you can call it like this:

println!("\nExample:\n\n\taws --profile {} s3 ls\n", style("test").with(Color::Yellow).into_displayable(&screen));

If you have any feedback or you don't like it please let me know. Otherwise tonight I'll release a new version.

from crossterm.

TimonPost avatar TimonPost commented on July 24, 2024

Yea It's a know problem unfortunately (if folks used the old API) allot has been changed and almost the whole API has been thrown over. It needed to be done and this crate had some crate benefits from it. If you have a few minutes I'll look into it. But am not sure there was a reason why I had removed it. I'll let you know...

from crossterm.

TimonPost avatar TimonPost commented on July 24, 2024

Oke I have been experimenting and have come up with something. I can't work further on it now need to go. But I see that this is something that needs to be implemented because it is quite useful to have this kind of functionality. Look at the code below of how I have implemented it for now:


fn main()
{
    let screen = Screen::default();
    println!("\nExample:\n\n\taws --profile {} s3 ls\n", DisplayableObject::new(&screen, &style("test").with(Color::Yellow)));
}

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(())
    }
}

This will wrap a StyledObject inside a DisplayableObject which can be used in the write functions. It works but still need to experiment with it a little further. And yea maybe if this is the way I go I'll release the version tomorrow.

And also implementing Display for StyledObject needs to be investigated so work in progresss...

You could copy the code above for now but unfortunately, you still need to update 60 rows :(

from crossterm.

Rukenshia avatar Rukenshia commented on July 24, 2024

That looks pretty good to me! Thanks so much for the quick implementation of this @TimonPost

from crossterm.

TimonPost avatar TimonPost commented on July 24, 2024

I published the new version with the changes. So I'll close the issue.

from crossterm.

Rukenshia avatar Rukenshia commented on July 24, 2024

Upgrade went pretty smooth, thanks for the quick turnaround on this.

from crossterm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.