1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-01 01:04:00 +00:00

Use builder pattern in char section

This commit is contained in:
Matan Kushner 2019-04-12 18:12:29 -04:00
parent d82ebc4457
commit fec5c4db4e
No known key found for this signature in database
GPG Key ID: 4B98C3A8949CA8A4
2 changed files with 12 additions and 10 deletions

View File

@ -17,17 +17,13 @@ pub fn segment(args: &ArgMatches) -> Segment {
let segment = Segment::new("char");
let color = if args.value_of("status_code").unwrap() == "0" {
if args.value_of("status_code").unwrap() == "0" {
segment.set_style(COLOR_SUCCESS);
} else {
COLOR_FAILURE
segment.set_style(COLOR_FAILURE);
};
Segment {
value: String::from(PROMPT_CHAR),
style: Style::from(color),
..Default::default()
}
segment
}
#[cfg(test)]

View File

@ -9,7 +9,10 @@ pub struct Segment {
}
impl Segment {
pub fn new<S>(name: S) -> Segment where S: Into<String> {
pub fn new<T>(name: T) -> Segment
where
T: Into<String>,
{
let default_prefix = Some(Box::new(Segment {
name: Some(format!("{} {}", name.into(), "prefix")),
style: Style::default(),
@ -35,8 +38,11 @@ impl Segment {
}
}
pub fn set_style<'a>(&'a mut self, style: Style) -> &'a mut Segment {
self.style = style;
pub fn set_style<'a, T>(&'a mut self, style: T) -> &'a mut Segment
where
T: Into<Style>,
{
self.style = style.into();
self
}