1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 15:56:28 +00:00

fix: Don't print the first module prefix after a line-break (#473)

This commit is contained in:
(´⌣`ʃƪ) 2019-10-06 08:46:46 -07:00 committed by Matan Kushner
parent ab5dae3d05
commit 77c25b60c2
2 changed files with 16 additions and 7 deletions

View File

@ -127,6 +127,11 @@ impl<'a> Module<'a> {
}
}
/// Get module's name
pub fn get_name(&self) -> &String {
&self._name
}
/// Whether a module has non-empty segments
pub fn is_empty(&self) -> bool {
self.segments.iter().all(|segment| segment.is_empty())

View File

@ -41,16 +41,20 @@ pub fn prompt(args: ArgMatches) {
.flatten()
.collect::<Vec<Module>>(); // Remove segments set to `None`
let mut print_without_prefix = true;
let mut printable = modules.iter();
// Print the first module without its prefix
if let Some(first_module) = printable.next() {
let module_without_prefix = first_module.to_string_without_prefix();
write!(handle, "{}", module_without_prefix).unwrap()
}
for module in printable {
// Skip printing the prefix of a module after the line_break
if print_without_prefix {
let module_without_prefix = module.to_string_without_prefix();
write!(handle, "{}", module_without_prefix).unwrap()
} else {
write!(handle, "{}", module).unwrap();
}
// Print all remaining modules
printable.for_each(|module| write!(handle, "{}", module).unwrap());
print_without_prefix = module.get_name() == "line_break"
}
}
pub fn module(module_name: &str, args: ArgMatches) {