Comments (6)
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.
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.
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.
That looks pretty good to me! Thanks so much for the quick implementation of this @TimonPost
from crossterm.
I published the new version with the changes. So I'll close the issue.
from crossterm.
Upgrade went pretty smooth, thanks for the quick turnaround on this.
from crossterm.
Related Issues (20)
- SetUnderlineColor command error on Windows 7
- Unsupported input escape sequences reported as keypresses
- Panic in parse_csi_sgr_mouse
- random test failures in style::types::colored::tests::test_parse_ansi_bg/fg
- Temporarily disable async key event polling HOT 1
- something wrong when running inside container
- `crossterm::event::poll(Duration::ZERO)` incorrectly returns false with `use-dev-tty` enabled
- Error on Windows PowerShell with event-read example
- Iterm2 unicode
- Why are ansi 3/4 bit colors not supported? HOT 2
- Port from libc to rustix on Unix platforms HOT 4
- Surrogate pairs are ignored on Windows Terminal HOT 1
- Document the feature `use-dev-tty` on `crossterm::event::{poll, read}` HOT 1
- Event::Mouse doesn't capture modifiers in zellij HOT 1
- Support for sending ansi special characters to terminal
- `event::read` incorrectly returns `Esc` key press event while scrolling the mouse wheel HOT 2
- Padding when trying to fill whole terminal. HOT 1
- Terminal settings do not get restored on exit when using bash HOT 1
- Differentiate between keyboard/numpad chars
- Mac doesnt report Shift or Ctrl with enter key HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crossterm.