mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-28 20:12:42 +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 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)]
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user