mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
feat: support transparent in color override
This commit is contained in:
parent
41822b81fd
commit
24ea32f41c
|
@ -149,11 +149,11 @@ Text character to use at the end of the segment. Will take the background color
|
|||
|
||||
### 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
|
||||
|
||||
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
|
||||
|
||||
|
@ -201,6 +201,9 @@ do so like this:
|
|||
"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
|
||||
|
||||
```json
|
||||
|
@ -296,3 +299,4 @@ do so like this:
|
|||
[nf]: https://www.nerdfonts.com/
|
||||
[segments]: /docs/battery
|
||||
[colors]: https://htmlcolorcodes.com/color-chart/material-design-color-chart/
|
||||
[fg]: /docs/configure#foreground
|
||||
|
|
|
@ -91,13 +91,13 @@ func (r *Renderer) writeAndRemoveText(background string, foreground string, text
|
|||
}
|
||||
|
||||
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)
|
||||
for i := range match {
|
||||
// get the text before the color override and write that first
|
||||
textBeforeColorOverride := strings.Split(text, match[i][0])[0]
|
||||
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
|
||||
r.writeColoredText(background, foreground, text)
|
||||
|
|
|
@ -51,8 +51,7 @@
|
|||
"leading_diamond": "",
|
||||
"trailing_diamond": "",
|
||||
"properties": {
|
||||
"prefix": " ",
|
||||
"prefix": "<#193549> </>"
|
||||
"prefix": "<transparent> </>"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
"windows_registry_icon": "",
|
||||
"folder_separator_icon": "",
|
||||
"style": "short",
|
||||
"prefix": "<#193549></> ",
|
||||
"prefix": "<transparent></> ",
|
||||
"postfix": " "
|
||||
}
|
||||
},
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
"always_enabled": true,
|
||||
"error_color": "#f1184c",
|
||||
"color_background": true,
|
||||
"prefix": "<#193549></> "
|
||||
"prefix": "<transparent></> "
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue