feat: support transparent in color override

This commit is contained in:
Jan De Dobbeleer 2020-10-06 15:28:07 +02:00 committed by Jan De Dobbeleer
parent 41822b81fd
commit 24ea32f41c
5 changed files with 11 additions and 8 deletions

View file

@ -149,11 +149,11 @@ Text character to use at the end of the segment. Will take the background color
### Foreground ### Foreground
Hex [color][colors] to use as the segment text foreground color. Hex [color][colors] to use as the segment text foreground color. Also supports transparency using the `transparent` keyword.
### Background ### Background
Hex [color][colors] to use as the segment text background color. Hex [color][colors] to use as the segment text background color. Also supports transparency using the `transparent` keyword.
### Properties ### Properties
@ -201,6 +201,9 @@ do so like this:
"prefix": "<#CB4B16>┏[</>", "prefix": "<#CB4B16>┏[</>",
``` ```
Oh my Posh offers support for hex [colors][colors] as well as the `transparent` keyword to create either a transparent foreground
override or transparent background color using the segement's [foreground][fg] property.
## Full Sample ## Full Sample
```json ```json
@ -296,3 +299,4 @@ do so like this:
[nf]: https://www.nerdfonts.com/ [nf]: https://www.nerdfonts.com/
[segments]: /docs/battery [segments]: /docs/battery
[colors]: https://htmlcolorcodes.com/color-chart/material-design-color-chart/ [colors]: https://htmlcolorcodes.com/color-chart/material-design-color-chart/
[fg]: /docs/configure#foreground

View file

@ -91,13 +91,13 @@ func (r *Renderer) writeAndRemoveText(background string, foreground string, text
} }
func (r *Renderer) write(background string, foreground string, text string) { func (r *Renderer) write(background string, foreground string, text string) {
rex := regexp.MustCompile(`<\s*(?P<color>#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})>(?P<text>.*?)<\s*/\s*>`) rex := regexp.MustCompile(`<((#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|transparent))>(.*?)</>`)
match := rex.FindAllStringSubmatch(text, -1) match := rex.FindAllStringSubmatch(text, -1)
for i := range match { for i := range match {
// get the text before the color override and write that first // get the text before the color override and write that first
textBeforeColorOverride := strings.Split(text, match[i][0])[0] textBeforeColorOverride := strings.Split(text, match[i][0])[0]
text = r.writeAndRemoveText(background, foreground, textBeforeColorOverride, textBeforeColorOverride, text) text = r.writeAndRemoveText(background, foreground, textBeforeColorOverride, textBeforeColorOverride, text)
text = r.writeAndRemoveText(background, match[i][1], match[i][2], match[i][0], text) text = r.writeAndRemoveText(background, match[i][1], match[i][4], match[i][0], text)
} }
// color the remaining part of text with background and foreground // color the remaining part of text with background and foreground
r.writeColoredText(background, foreground, text) r.writeColoredText(background, foreground, text)

View file

@ -51,8 +51,7 @@
"leading_diamond": "", "leading_diamond": "",
"trailing_diamond": "", "trailing_diamond": "",
"properties": { "properties": {
"prefix": "  ", "prefix": "<transparent> </>"
"prefix": "<#193549> </>"
} }
} }
] ]

View file

@ -40,7 +40,7 @@
"windows_registry_icon": "", "windows_registry_icon": "",
"folder_separator_icon": "", "folder_separator_icon": "",
"style": "short", "style": "short",
"prefix": "<#193549></> ", "prefix": "<transparent></> ",
"postfix": " " "postfix": " "
} }
}, },

View file

@ -122,7 +122,7 @@
"always_enabled": true, "always_enabled": true,
"error_color": "#f1184c", "error_color": "#f1184c",
"color_background": true, "color_background": true,
"prefix": "<#193549></> " "prefix": "<transparent></> "
} }
} }
] ]