-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crossterm Style API-discussion #254
Comments
@zrzka in reaction on the question to make fields from If yes, then I've got something like this on my mind ... #[derive(Debug, Clone, Default)]
pub struct ObjectStyle {
fg_color: Option<Color>,
bg_color: Option<Color>,
attrs: Vec<Attribute>,
}
impl ObjectStyle {
pub fn apply<D: Display + Clone>(&self, val: D) -> StyledObject<D> {
StyledObject {
object_style: self.clone(),
content: val,
}
}
pub fn new() -> ObjectStyle {
ObjectStyle::default()
}
pub fn background(mut self, color: Color) -> ObjectStyle {
self.bg_color = Some(color);
self
}
pub fn foreground(mut self, color: Color) -> ObjectStyle {
self.fg_color = Some(color);
self
}
pub fn attribute(mut self, attr: Attribute) -> ObjectStyle {
self.attrs.push(attr);
self
}
} In other words ...
... it will lead to something like ... let style = ObjectStyle::new()
.foreground(Color::Blue)
.background(Color::Yellow)
.attribute(Attribute::Italic);
let foo = style.apply("bar");
let bar = style.apply("baz"); |
It is very common for a builder pattern to have no One problem, although not big, is when we want to add multiple attributes this is going to look a bit weird: let style = ObjectStyle::new()
.foreground(Color::Blue)
.background(Color::Yellow)
.attribute(Attribute::Italic);
.attribute(Attribute::Bold);
.attribute(Attribute::Crossed);
|
I have 3 proposals as well:
My motivation behind this is that
pub struct StyledObject<D: Display + Clone> {
object_style: ObjectStyle,
content: D,
} Then add the following functions (if change 1,2 as well are approved. Otherwise replace fn content() -> D;
fn content_style() -> ObjectStyle |
Trait names - |
Styler & Colorizer although I have one problem with this, Colorizer is not a word in the dictionary and thus I decided to use Colorize a couple of months ago. |
|
Actual tasks are moved over here #286 |
Closing, because ideas were merged. |
In this issue, we will discuss all the API changes we want to make for crossterm_style.
The text was updated successfully, but these errors were encountered: