diff options
author | Matan Kushner <hello@matchai.me> | 2019-04-12 18:12:29 -0400 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-04-12 18:12:29 -0400 |
commit | fec5c4db4ebd35fa004da524df252f13cb86094e (patch) | |
tree | e48b8767a5733c3364d182f035cbebc8b2a826ab | |
parent | d82ebc4457adefcd9ad45c4d3d6d611c28d80cc3 (diff) |
Use builder pattern in char section
-rw-r--r-- | src/modules/character.rs | 10 | ||||
-rw-r--r-- | src/segment.rs | 12 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/modules/character.rs b/src/modules/character.rs index 98b9b254e..9ebc8fa61 100644 --- a/src/modules/character.rs +++ b/src/modules/character.rs @@ -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)] diff --git a/src/segment.rs b/src/segment.rs index df3017628..9fe50e904 100644 --- a/src/segment.rs +++ b/src/segment.rs @@ -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 } |