feat(directory): add before_repo_root_style (#4595)

This commit is contained in:
cgzones
2022-12-01 23:09:11 +01:00
committed by GitHub
parent ddd54e9b20
commit ea6249b524
4 changed files with 34 additions and 19 deletions
+3 -1
View File
@@ -19,6 +19,7 @@ pub struct DirectoryConfig<'a> {
pub repo_root_format: &'a str,
pub style: &'a str,
pub repo_root_style: Option<&'a str>,
pub before_repo_root_style: Option<&'a str>,
pub disabled: bool,
pub read_only: &'a str,
pub read_only_style: &'a str,
@@ -36,9 +37,10 @@ impl<'a> Default for DirectoryConfig<'a> {
use_logical_path: true,
substitutions: IndexMap::new(),
format: "[$path]($style)[$read_only]($read_only_style) ",
repo_root_format: "[$before_root_path]($style)[$repo_root]($repo_root_style)[$path]($style)[$read_only]($read_only_style) ",
repo_root_format: "[$before_root_path]($before_repo_root_style)[$repo_root]($repo_root_style)[$path]($style)[$read_only]($read_only_style) ",
style: "cyan bold",
repo_root_style: None,
before_repo_root_style: None,
disabled: false,
read_only: "🔒",
read_only_style: "red",
+6 -2
View File
@@ -137,6 +137,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
config.repo_root_format
};
let repo_root_style = config.repo_root_style.unwrap_or(config.style);
let before_repo_root_style = config.before_repo_root_style.unwrap_or(config.style);
let parsed = StringFormatter::new(display_format).and_then(|formatter| {
formatter
@@ -144,6 +145,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
"style" => Some(Ok(config.style)),
"read_only_style" => Some(Ok(config.read_only_style)),
"repo_root_style" => Some(Ok(repo_root_style)),
"before_repo_root_style" => Some(Ok(before_repo_root_style)),
_ => None,
})
.map(|variable| match variable {
@@ -1694,12 +1696,14 @@ mod tests {
truncation_symbol = "…/"
truncate_to_repo = false
repo_root_style = "green"
before_repo_root_style = "blue"
})
.path(dir)
.collect();
let expected = Some(format!(
"{}{}repo{} ",
Color::Cyan.bold().paint(convert_path_sep("…/above/")),
"{}{}{}repo{} ",
Color::Blue.prefix(),
convert_path_sep("…/above/"),
Color::Green.prefix(),
Color::Cyan.bold().paint(convert_path_sep("/src/sub/path"))
));