Add line_sep section

This commit is contained in:
Matan Kushner
2019-04-04 20:33:36 -04:00
parent 52a529c627
commit 168d568d54
5 changed files with 35 additions and 13 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ mod tests {
.get_matches_from(vec!["starship", "0"]); .get_matches_from(vec!["starship", "0"]);
let segment = modules::handle("char", &args); let segment = modules::handle("char", &args);
print::print_segment(segment) print::stringify_segment(segment)
}); });
} }
@@ -39,7 +39,7 @@ mod tests {
.get_matches_from(vec!["starship", "0"]); .get_matches_from(vec!["starship", "0"]);
let segment = modules::handle("dir", &args); let segment = modules::handle("dir", &args);
print::print_segment(segment) print::stringify_segment(segment)
}); });
} }
} }
+3
View File
@@ -1,5 +1,8 @@
#[macro_use] #[macro_use]
extern crate clap; extern crate clap;
extern crate rayon;
extern crate ansi_term;
extern crate dirs;
mod modules; mod modules;
mod print; mod print;
+13
View File
@@ -0,0 +1,13 @@
use super::Segment;
use clap::ArgMatches;
/// Creates a segment for the line break
pub fn segment(_: &ArgMatches) -> Segment {
const LINE_ENDING: &str = "\n";
Segment {
value: String::from(LINE_ENDING),
suffix: None,
..Default::default()
}
}
+2
View File
@@ -1,5 +1,6 @@
mod char; mod char;
mod dir; mod dir;
mod line_sep;
use clap::ArgMatches; use clap::ArgMatches;
use ansi_term::Style; use ansi_term::Style;
@@ -33,6 +34,7 @@ pub fn handle(module: &str, args: &ArgMatches) -> Segment {
match module { match module {
"char" => char::segment(&args), "char" => char::segment(&args),
"dir" => dir::segment(&args), "dir" => dir::segment(&args),
"line_sep" => line_sep::segment(&args),
_ => panic!("Unknown module: {}", module), _ => panic!("Unknown module: {}", module),
} }
+13 -9
View File
@@ -3,15 +3,15 @@ use crate::modules::Segment;
use clap::ArgMatches; use clap::ArgMatches;
pub fn prompt(args: ArgMatches) { pub fn prompt(args: ArgMatches) {
let default_prompt = vec!["dir", "char"]; let default_prompt = vec!["dir", "line_sep", "char"];
for module in default_prompt { default_prompt.into_iter()
let segment = modules::handle(module, &args); .map(|module| modules::handle(module, &args))
print_segment(segment); .map(|segment| stringify_segment(segment))
} .for_each(|segment_string| print!("{}", segment_string));
} }
pub fn print_segment(segment: Segment) { pub fn stringify_segment(segment: Segment) -> String {
let Segment { let Segment {
prefix, prefix,
value, value,
@@ -19,13 +19,17 @@ pub fn print_segment(segment: Segment) {
suffix, suffix,
} = segment; } = segment;
let mut segment_string = String::new();
if let Some(prefix) = prefix { if let Some(prefix) = prefix {
print_segment(*prefix); segment_string += &stringify_segment(*prefix);
} }
print!("{}", style.paint(value)); segment_string += &style.paint(value).to_string();
if let Some(suffix) = suffix { if let Some(suffix) = suffix {
print_segment(*suffix); segment_string += &stringify_segment(*suffix);
} }
segment_string
} }