Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matan Kushner
committed
Apr 12, 2019
1 parent
7356faa
commit d82ebc4
Showing
7 changed files
with
91 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Lib is present to allow for benchmarking | ||
pub mod modules; | ||
pub mod print; | ||
pub mod segment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ extern crate git2; | |
|
||
mod modules; | ||
mod print; | ||
mod segment; | ||
|
||
use clap::{App, Arg}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use ansi_term::Style; | ||
|
||
pub struct Segment { | ||
name: Option<String>, | ||
style: Style, | ||
value: String, | ||
prefix: OptionalSegment, | ||
suffix: OptionalSegment, | ||
} | ||
|
||
impl Segment { | ||
pub fn new<S>(name: S) -> Segment where S: Into<String> { | ||
let default_prefix = Some(Box::new(Segment { | ||
name: Some(format!("{} {}", name.into(), "prefix")), | ||
style: Style::default(), | ||
value: String::from("via "), | ||
prefix: None, | ||
suffix: None, | ||
})); | ||
|
||
let default_suffix = Some(Box::new(Segment { | ||
name: Some(format!("{} {}", name.into(), "suffix")), | ||
style: Style::default(), | ||
value: String::from(" "), | ||
prefix: None, | ||
suffix: None, | ||
})); | ||
|
||
Segment { | ||
name: Some(name.into()), | ||
style: Style::default(), | ||
value: String::from(""), | ||
prefix: default_prefix, | ||
suffix: default_suffix, | ||
} | ||
} | ||
|
||
pub fn set_style<'a>(&'a mut self, style: Style) -> &'a mut Segment { | ||
self.style = style; | ||
self | ||
} | ||
|
||
pub fn set_value<'a>(&'a mut self, value: String) -> &'a mut Segment { | ||
self.value = value; | ||
self | ||
} | ||
|
||
pub fn set_prefix<'a>(&'a mut self, prefix: Segment) -> &'a mut Segment { | ||
self.prefix = Some(Box::new(prefix)); | ||
self | ||
} | ||
|
||
pub fn set_suffix<'a>(&'a mut self, suffix: Segment) -> &'a mut Segment { | ||
self.suffix = Some(Box::new(suffix)); | ||
self | ||
} | ||
|
||
pub fn output<'a>(&'a self) -> String { | ||
let Segment { | ||
name: _name, | ||
prefix, | ||
value, | ||
style, | ||
suffix, | ||
} = self; | ||
|
||
let mut segment_string = String::new(); | ||
|
||
if let Some(prefix) = prefix { | ||
segment_string += &prefix.output() | ||
} | ||
|
||
segment_string += &style.paint(value).to_string(); | ||
|
||
if let Some(suffix) = suffix { | ||
segment_string += &suffix.output(); | ||
} | ||
|
||
segment_string | ||
} | ||
} | ||
|
||
type OptionalSegment = Option<Box<Segment>>; |