mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat(path): allow coloring the folder_separator_icon on cycle
This commit is contained in:
parent
5ca932ae11
commit
66ca5ccf1f
|
@ -73,8 +73,10 @@ const (
|
||||||
MaxWidth properties.Property = "max_width"
|
MaxWidth properties.Property = "max_width"
|
||||||
// Hides the root location if it doesn't fit in max_depth. Used in Agnoster Short
|
// Hides the root location if it doesn't fit in max_depth. Used in Agnoster Short
|
||||||
HideRootLocation properties.Property = "hide_root_location"
|
HideRootLocation properties.Property = "hide_root_location"
|
||||||
// A foreground color cycle
|
// A color override cycle
|
||||||
Cycle properties.Property = "cycle"
|
Cycle properties.Property = "cycle"
|
||||||
|
// Color the path separators within the cycle
|
||||||
|
CycleFolderSeparator properties.Property = "cycle_folder_separator"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (pt *Path) Template() string {
|
func (pt *Path) Template() string {
|
||||||
|
@ -576,28 +578,44 @@ func (pt *Path) replaceFolderSeparators(pwd string) string {
|
||||||
|
|
||||||
func (pt *Path) colorizePath(root string, elements []string) string {
|
func (pt *Path) colorizePath(root string, elements []string) string {
|
||||||
cycle := pt.props.GetStringArray(Cycle, []string{})
|
cycle := pt.props.GetStringArray(Cycle, []string{})
|
||||||
|
skipColorize := len(cycle) == 0
|
||||||
folderSeparator := pt.getFolderSeparator()
|
folderSeparator := pt.getFolderSeparator()
|
||||||
|
colorSeparator := pt.props.GetBool(CycleFolderSeparator, false)
|
||||||
|
|
||||||
if len(cycle) != 0 {
|
colorizeElement := func(element string) string {
|
||||||
colorize := "<%s>%s</>"
|
if skipColorize || len(element) == 0 {
|
||||||
|
return element
|
||||||
if len(root) != 0 {
|
}
|
||||||
root = fmt.Sprintf(colorize, cycle[0], root)
|
defer func() {
|
||||||
cycle = append(cycle[1:], cycle[0])
|
cycle = append(cycle[1:], cycle[0])
|
||||||
|
}()
|
||||||
|
return fmt.Sprintf("<%s>%s</>", cycle[0], element)
|
||||||
|
}
|
||||||
|
|
||||||
|
colorizeSeparator := func() string {
|
||||||
|
if skipColorize || !colorSeparator {
|
||||||
|
return folderSeparator
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("<%s>%s</>", cycle[0], folderSeparator)
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder strings.Builder
|
||||||
|
|
||||||
|
builder.WriteString(colorizeElement(root))
|
||||||
|
|
||||||
|
if root != pt.env.PathSeparator() && len(root) != 0 {
|
||||||
|
builder.WriteString(colorizeSeparator())
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, element := range elements {
|
for i, element := range elements {
|
||||||
if len(element) == 0 {
|
if len(element) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
colored := fmt.Sprintf(colorize, cycle[0], element)
|
builder.WriteString(colorizeElement(element))
|
||||||
elements[i] = colored
|
if i != len(elements)-1 {
|
||||||
cycle = append(cycle[1:], cycle[0])
|
builder.WriteString(colorizeSeparator())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if root == pt.env.PathSeparator() || len(root) == 0 {
|
return builder.String()
|
||||||
return root + strings.Join(elements, folderSeparator)
|
|
||||||
}
|
|
||||||
return root + folderSeparator + strings.Join(elements, folderSeparator)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -957,6 +957,7 @@ func TestAgnosterPath(t *testing.T) {
|
||||||
GOOS string
|
GOOS string
|
||||||
PathSeparator string
|
PathSeparator string
|
||||||
Cycle []string
|
Cycle []string
|
||||||
|
ColorSeparator bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Case: "Windows registry drive case sensitive",
|
Case: "Windows registry drive case sensitive",
|
||||||
|
@ -1082,6 +1083,15 @@ func TestAgnosterPath(t *testing.T) {
|
||||||
PathSeparator: "/",
|
PathSeparator: "/",
|
||||||
Cycle: []string{"blue", "yellow"},
|
Cycle: []string{"blue", "yellow"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Case: "Unix, colorize with folder separator",
|
||||||
|
Expected: "<blue>mnt</><yellow> > </><yellow>f</><blue> > </><blue>location</>",
|
||||||
|
Home: homeDir,
|
||||||
|
PWD: "/mnt/folder/location",
|
||||||
|
PathSeparator: "/",
|
||||||
|
Cycle: []string{"blue", "yellow"},
|
||||||
|
ColorSeparator: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
@ -1103,6 +1113,7 @@ func TestAgnosterPath(t *testing.T) {
|
||||||
FolderIcon: "f",
|
FolderIcon: "f",
|
||||||
HomeIcon: "~",
|
HomeIcon: "~",
|
||||||
Cycle: tc.Cycle,
|
Cycle: tc.Cycle,
|
||||||
|
CycleFolderSeparator: tc.ColorSeparator,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
path.setPaths()
|
path.setPaths()
|
||||||
|
|
|
@ -1774,6 +1774,19 @@
|
||||||
"title": "Hide the root location",
|
"title": "Hide the root location",
|
||||||
"description": "Hides the root location, when using agnoster_short style, if it doesn't fit in the last max_depth folders.",
|
"description": "Hides the root location, when using agnoster_short style, if it doesn't fit in the last max_depth folders.",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"cycle": {
|
||||||
|
"type": "array",
|
||||||
|
"title": "Color overrides to use to cycle through and color the path per folder",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cycle_folder_separator": {
|
||||||
|
"type": "boolean",
|
||||||
|
"title": "Cycle the folder_separator_icon",
|
||||||
|
"description": "Colorize the folder_separator_icon as well when using a cycle.",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2771,7 +2784,9 @@
|
||||||
{
|
{
|
||||||
"if": {
|
"if": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"type": { "const": "unity" }
|
"type": {
|
||||||
|
"const": "unity"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"then": {
|
"then": {
|
||||||
|
|
|
@ -34,7 +34,7 @@ import Config from "@site/src/components/Config.js";
|
||||||
| --------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
| --------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `folder_separator_icon` | `string` | the symbol to use as a separator between folders - defaults to platform path separator |
|
| `folder_separator_icon` | `string` | the symbol to use as a separator between folders - defaults to platform path separator |
|
||||||
| `folder_separator_template` | `string` | the [template][templates] to use as a separator between folders - defaults to `` |
|
| `folder_separator_template` | `string` | the [template][templates] to use as a separator between folders - defaults to `` |
|
||||||
| `home_icon` | `string` | the icon to display when at `$HOME`, defaults to `~` |
|
| `home_icon` | `string` | the icon to display when at `$HOME` - defaults to `~` |
|
||||||
| `folder_icon` | `string` | the icon to use as a folder indication - defaults to `..` |
|
| `folder_icon` | `string` | the icon to use as a folder indication - defaults to `..` |
|
||||||
| `windows_registry_icon` | `string` | the icon to display when in the Windows registry - defaults to `\uE0B1` |
|
| `windows_registry_icon` | `string` | the icon to display when in the Windows registry - defaults to `\uE0B1` |
|
||||||
| `style` | `enum` | how to display the current path |
|
| `style` | `enum` | how to display the current path |
|
||||||
|
@ -42,7 +42,8 @@ import Config from "@site/src/components/Config.js";
|
||||||
| `max_depth` | `number` | maximum path depth to display before shortening when using `agnoster_short`, defaults to `1` |
|
| `max_depth` | `number` | maximum path depth to display before shortening when using `agnoster_short`, defaults to `1` |
|
||||||
| `max_width` | `number` | maximum path length to display when using `powerlevel`, defaults to `0` |
|
| `max_width` | `number` | maximum path length to display when using `powerlevel`, defaults to `0` |
|
||||||
| `hide_root_location` | `boolean` | hides the root location if it doesn't fit in the last `max_depth` folders, when using `agnoster_short` - defaults to `false` |
|
| `hide_root_location` | `boolean` | hides the root location if it doesn't fit in the last `max_depth` folders, when using `agnoster_short` - defaults to `false` |
|
||||||
| `cycle` | `[]string` | a list of foreground colors to cycle through to colorize the individual path folders |
|
| `cycle` | `[]string` | a list of color overrides to cycle through to colorize the individual path folders, e.g. `[ "#ffffff,#111111" ]` |
|
||||||
|
| `cycle_folder_separator` | `boolean` | colorize the `folder_separator_icon` as well when using a cycle - defaults to `false` |
|
||||||
|
|
||||||
## Mapped Locations
|
## Mapped Locations
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue