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

Add a new line before the prompt

This commit is contained in:
Matan Kushner 2019-04-08 17:35:38 -04:00
parent 0e0bed0837
commit d58ea0659b
No known key found for this signature in database
GPG Key ID: 4B98C3A8949CA8A4
2 changed files with 19 additions and 6 deletions

View File

@ -66,6 +66,11 @@ fn get_repo_root(repo: Repository) -> PathBuf {
} }
/// Truncate a path to a predefined number of path components /// Truncate a path to a predefined number of path components
///
/// Trim the path in the prompt to only have the last few paths, set by `length`.
/// This function also serves to replace the top-level path of the prompt.
/// This can be used to replace the path to a git repo with only the repo
/// directory name.
fn truncate_path( fn truncate_path(
length: &usize, length: &usize,
full_path: &PathBuf, full_path: &PathBuf,
@ -91,10 +96,10 @@ fn truncate_path(
} }
format!( format!(
"{}{}{}", "{replacement}{separator}{path}",
top_level_replacement, replacement = top_level_replacement,
std::path::MAIN_SEPARATOR, separator = std::path::MAIN_SEPARATOR,
full_path path = full_path
.iter() .iter()
.skip(top_level_path_depth) .skip(top_level_path_depth)
.collect::<PathBuf>() .collect::<PathBuf>()

View File

@ -1,15 +1,23 @@
use std::io::{self, Write};
use clap::ArgMatches;
use crate::modules; use crate::modules;
use crate::modules::Segment; use crate::modules::Segment;
use clap::ArgMatches;
pub fn prompt(args: ArgMatches) { pub fn prompt(args: ArgMatches) {
let default_prompt = vec!["directory", "line_break", "character"]; let default_prompt = vec!["directory", "line_break", "character"];
let stdout = io::stdout();
let mut handle = stdout.lock();
// Write a new line before the prompt
write!(handle, "{}", "\n").unwrap();
default_prompt default_prompt
.into_iter() .into_iter()
.map(|module| modules::handle(module, &args)) .map(|module| modules::handle(module, &args))
.map(stringify_segment) .map(stringify_segment)
.for_each(|segment_string| print!("{}", segment_string)); .for_each(|segment_string| write!(handle, "{}", segment_string).unwrap());
} }
/// Create a string with the formatted contents of a segment /// Create a string with the formatted contents of a segment