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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 19 deletions

View File

@ -330,13 +330,14 @@
},
"directory": {
"default": {
"before_repo_root_style": null,
"disabled": false,
"fish_style_pwd_dir_length": 0,
"format": "[$path]($style)[$read_only]($read_only_style) ",
"home_symbol": "~",
"read_only": "🔒",
"read_only_style": "red",
"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) ",
"repo_root_style": null,
"style": "cyan bold",
"substitutions": {},
@ -2468,7 +2469,7 @@
"type": "string"
},
"repo_root_format": {
"default": "[$before_root_path]($style)[$repo_root]($repo_root_style)[$path]($style)[$read_only]($read_only_style) ",
"default": "[$before_root_path]($before_repo_root_style)[$repo_root]($repo_root_style)[$path]($style)[$read_only]($read_only_style) ",
"type": "string"
},
"style": {
@ -2482,6 +2483,13 @@
"null"
]
},
"before_repo_root_style": {
"default": null,
"type": [
"string",
"null"
]
},
"disabled": {
"default": false,
"type": "boolean"

View File

@ -1103,20 +1103,21 @@ it would have been `nixpkgs/pkgs`.
### Options
| Option | Default | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| `truncation_length` | `3` | The number of parent folders that the current directory should be truncated to. |
| `truncate_to_repo` | `true` | Whether or not to truncate to the root of the git repo that you're currently in. |
| `format` | `'[$path]($style)[$read_only]($read_only_style) '` | The format for the module. |
| `style` | `'bold cyan'` | The style for the module. |
| `disabled` | `false` | Disables the `directory` module. |
| `read_only` | `'🔒'` | The symbol indicating current directory is read only. |
| `read_only_style` | `'red'` | The style for the read only symbol. |
| `truncation_symbol` | `''` | The symbol to prefix to truncated paths. eg: '…/' |
| `repo_root_style` | | The style for the root of the git repo. The default value is equivalent to `style`. |
| `repo_root_format` | `'[$before_root_path]($style)[$repo_root]($repo_root_style)[$path]($style)[$read_only]($read_only_style) '` | The format of a git repo when `repo_root_style` is defined. |
| `home_symbol` | `'~'` | The symbol indicating home directory. |
| `use_os_path_sep` | `true` | Use the OS specific path separator instead of always using `/` (e.g. `\` on Windows) |
| Option | Default | Description |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `truncation_length` | `3` | The number of parent folders that the current directory should be truncated to. |
| `truncate_to_repo` | `true` | Whether or not to truncate to the root of the git repo that you're currently in. |
| `format` | `'[$path]($style)[$read_only]($read_only_style) '` | The format for the module. |
| `style` | `'bold cyan'` | The style for the module. |
| `disabled` | `false` | Disables the `directory` module. |
| `read_only` | `'🔒'` | The symbol indicating current directory is read only. |
| `read_only_style` | `'red'` | The style for the read only symbol. |
| `truncation_symbol` | `''` | The symbol to prefix to truncated paths. eg: '…/' |
| `before_repo_root_style` | | The style for the path segment above the root of the git repo. The default value is equivalent to `style`. |
| `repo_root_style` | | The style for the root of the git repo. The default value is equivalent to `style`. |
| `repo_root_format` | `'[$before_root_path]($before_repo_root_style)[$repo_root]($repo_root_style)[$path]($style)[$read_only]($read_only_style) '` | The format of a git repo when `before_repo_root_style` and `repo_root_style` is defined. |
| `home_symbol` | `'~'` | The symbol indicating home directory. |
| `use_os_path_sep` | `true` | Use the OS specific path separator instead of always using `/` (e.g. `\` on Windows) |
<details>
<summary>This module has a few advanced configuration options that control how the directory is displayed.</summary>

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",

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"))
));