1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-10 04:12:20 +00:00

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

View File

@ -1103,20 +1103,21 @@ it would have been `nixpkgs/pkgs`.
### Options ### Options
| Option | Default | Description | | Option | Default | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `truncation_length` | `3` | The number of parent folders that the current directory should be truncated to. | | `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. | | `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. | | `format` | `'[$path]($style)[$read_only]($read_only_style) '` | The format for the module. |
| `style` | `'bold cyan'` | The style for the module. | | `style` | `'bold cyan'` | The style for the module. |
| `disabled` | `false` | Disables the `directory` module. | | `disabled` | `false` | Disables the `directory` module. |
| `read_only` | `'🔒'` | The symbol indicating current directory is read only. | | `read_only` | `'🔒'` | The symbol indicating current directory is read only. |
| `read_only_style` | `'red'` | The style for the read only symbol. | | `read_only_style` | `'red'` | The style for the read only symbol. |
| `truncation_symbol` | `''` | The symbol to prefix to truncated paths. eg: '…/' | | `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`. | | `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_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. | | `repo_root_style` | | The style for the root of the git repo. The default value is equivalent to `style`. |
| `home_symbol` | `'~'` | The symbol indicating home directory. | | `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. |
| `use_os_path_sep` | `true` | Use the OS specific path separator instead of always using `/` (e.g. `\` on Windows) | | `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> <details>
<summary>This module has a few advanced configuration options that control how the directory is displayed.</summary> <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 repo_root_format: &'a str,
pub style: &'a str, pub style: &'a str,
pub repo_root_style: Option<&'a str>, pub repo_root_style: Option<&'a str>,
pub before_repo_root_style: Option<&'a str>,
pub disabled: bool, pub disabled: bool,
pub read_only: &'a str, pub read_only: &'a str,
pub read_only_style: &'a str, pub read_only_style: &'a str,
@ -36,9 +37,10 @@ impl<'a> Default for DirectoryConfig<'a> {
use_logical_path: true, use_logical_path: true,
substitutions: IndexMap::new(), substitutions: IndexMap::new(),
format: "[$path]($style)[$read_only]($read_only_style) ", 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", style: "cyan bold",
repo_root_style: None, repo_root_style: None,
before_repo_root_style: None,
disabled: false, disabled: false,
read_only: "🔒", read_only: "🔒",
read_only_style: "red", read_only_style: "red",

View File

@ -137,6 +137,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
config.repo_root_format config.repo_root_format
}; };
let repo_root_style = config.repo_root_style.unwrap_or(config.style); 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| { let parsed = StringFormatter::new(display_format).and_then(|formatter| {
formatter formatter
@ -144,6 +145,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
"style" => Some(Ok(config.style)), "style" => Some(Ok(config.style)),
"read_only_style" => Some(Ok(config.read_only_style)), "read_only_style" => Some(Ok(config.read_only_style)),
"repo_root_style" => Some(Ok(repo_root_style)), "repo_root_style" => Some(Ok(repo_root_style)),
"before_repo_root_style" => Some(Ok(before_repo_root_style)),
_ => None, _ => None,
}) })
.map(|variable| match variable { .map(|variable| match variable {
@ -1694,12 +1696,14 @@ mod tests {
truncation_symbol = "…/" truncation_symbol = "…/"
truncate_to_repo = false truncate_to_repo = false
repo_root_style = "green" repo_root_style = "green"
before_repo_root_style = "blue"
}) })
.path(dir) .path(dir)
.collect(); .collect();
let expected = Some(format!( let expected = Some(format!(
"{}{}repo{} ", "{}{}{}repo{} ",
Color::Cyan.bold().paint(convert_path_sep("…/above/")), Color::Blue.prefix(),
convert_path_sep("…/above/"),
Color::Green.prefix(), Color::Green.prefix(),
Color::Cyan.bold().paint(convert_path_sep("/src/sub/path")) Color::Cyan.bold().paint(convert_path_sep("/src/sub/path"))
)); ));