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:
parent
d82ebc4457
commit
fec5c4db4e
@ -17,17 +17,13 @@ pub fn segment(args: &ArgMatches) -> Segment {
|
|||||||
|
|
||||||
let segment = Segment::new("char");
|
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);
|
segment.set_style(COLOR_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
COLOR_FAILURE
|
segment.set_style(COLOR_FAILURE);
|
||||||
};
|
};
|
||||||
|
|
||||||
Segment {
|
segment
|
||||||
value: String::from(PROMPT_CHAR),
|
|
||||||
style: Style::from(color),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -9,7 +9,10 @@ pub struct Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
let default_prefix = Some(Box::new(Segment {
|
||||||
name: Some(format!("{} {}", name.into(), "prefix")),
|
name: Some(format!("{} {}", name.into(), "prefix")),
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
@ -35,8 +38,11 @@ impl Segment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_style<'a>(&'a mut self, style: Style) -> &'a mut Segment {
|
pub fn set_style<'a, T>(&'a mut self, style: T) -> &'a mut Segment
|
||||||
self.style = style;
|
where
|
||||||
|
T: Into<Style>,
|
||||||
|
{
|
||||||
|
self.style = style.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user