1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-05-30 23:20:52 +00:00
starship/src/print.rs
2019-04-04 20:33:36 -04:00

36 lines
847 B
Rust

use crate::modules;
use crate::modules::Segment;
use clap::ArgMatches;
pub fn prompt(args: ArgMatches) {
let default_prompt = vec!["dir", "line_sep", "char"];
default_prompt.into_iter()
.map(|module| modules::handle(module, &args))
.map(|segment| stringify_segment(segment))
.for_each(|segment_string| print!("{}", segment_string));
}
pub fn stringify_segment(segment: Segment) -> String {
let Segment {
prefix,
value,
style,
suffix,
} = segment;
let mut segment_string = String::new();
if let Some(prefix) = prefix {
segment_string += &stringify_segment(*prefix);
}
segment_string += &style.paint(value).to_string();
if let Some(suffix) = suffix {
segment_string += &stringify_segment(*suffix);
}
segment_string
}