mirror of
https://github.com/starship/starship.git
synced 2025-01-22 22:29:40 +01:00
Add line_sep section
This commit is contained in:
parent
52a529c627
commit
168d568d54
@ -27,7 +27,7 @@ mod tests {
|
||||
.get_matches_from(vec!["starship", "0"]);
|
||||
|
||||
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"]);
|
||||
|
||||
let segment = modules::handle("dir", &args);
|
||||
print::print_segment(segment)
|
||||
print::stringify_segment(segment)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
extern crate rayon;
|
||||
extern crate ansi_term;
|
||||
extern crate dirs;
|
||||
|
||||
mod modules;
|
||||
mod print;
|
||||
|
13
src/modules/line_sep.rs
Normal file
13
src/modules/line_sep.rs
Normal 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()
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
mod char;
|
||||
mod dir;
|
||||
mod line_sep;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use ansi_term::Style;
|
||||
@ -33,6 +34,7 @@ pub fn handle(module: &str, args: &ArgMatches) -> Segment {
|
||||
match module {
|
||||
"char" => char::segment(&args),
|
||||
"dir" => dir::segment(&args),
|
||||
"line_sep" => line_sep::segment(&args),
|
||||
|
||||
_ => panic!("Unknown module: {}", module),
|
||||
}
|
||||
|
26
src/print.rs
26
src/print.rs
@ -3,29 +3,33 @@ use crate::modules::Segment;
|
||||
use clap::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 {
|
||||
let segment = modules::handle(module, &args);
|
||||
print_segment(segment);
|
||||
}
|
||||
default_prompt.into_iter()
|
||||
.map(|module| modules::handle(module, &args))
|
||||
.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 {
|
||||
prefix,
|
||||
value,
|
||||
style,
|
||||
suffix,
|
||||
} = segment;
|
||||
} = segment;
|
||||
|
||||
let mut segment_string = String::new();
|
||||
|
||||
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 {
|
||||
print_segment(*suffix);
|
||||
segment_string += &stringify_segment(*suffix);
|
||||
}
|
||||
|
||||
segment_string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user