mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
feat: expand parent colors
This commit is contained in:
parent
e8f9bb20b0
commit
df78bad3b5
|
@ -24,7 +24,7 @@ type AnsiWriter struct {
|
|||
ansi *ansiUtils
|
||||
terminalBackground string
|
||||
Colors *Color
|
||||
ParentColors *Color
|
||||
ParentColors []*Color
|
||||
ansiColors AnsiColors
|
||||
}
|
||||
|
||||
|
@ -80,10 +80,13 @@ func (a *AnsiWriter) setColors(background, foreground string) {
|
|||
}
|
||||
|
||||
func (a *AnsiWriter) setParentColors(background, foreground string) {
|
||||
a.ParentColors = &Color{
|
||||
if a.ParentColors == nil {
|
||||
a.ParentColors = make([]*Color, 0)
|
||||
}
|
||||
a.ParentColors = append([]*Color{{
|
||||
Background: background,
|
||||
Foreground: foreground,
|
||||
}
|
||||
}}, a.ParentColors...)
|
||||
}
|
||||
|
||||
func (a *AnsiWriter) clearParentColors() {
|
||||
|
@ -183,16 +186,30 @@ func (a *AnsiWriter) isKeyword(color string) bool {
|
|||
}
|
||||
|
||||
func (a *AnsiWriter) expandKeyword(keyword string) string {
|
||||
resolveParentColor := func(keyword string) string {
|
||||
for _, color := range a.ParentColors {
|
||||
if color == nil {
|
||||
return Transparent
|
||||
}
|
||||
switch keyword {
|
||||
case ParentBackground:
|
||||
keyword = color.Background
|
||||
case ParentForeground:
|
||||
keyword = color.Foreground
|
||||
default:
|
||||
return keyword
|
||||
}
|
||||
}
|
||||
return keyword
|
||||
}
|
||||
resolveKeyword := func(keyword string) string {
|
||||
switch {
|
||||
case keyword == Background && a.Colors != nil:
|
||||
return a.Colors.Background
|
||||
case keyword == Foreground && a.Colors != nil:
|
||||
return a.Colors.Foreground
|
||||
case keyword == ParentBackground && a.ParentColors != nil:
|
||||
return a.ParentColors.Background
|
||||
case keyword == ParentForeground && a.ParentColors != nil:
|
||||
return a.ParentColors.Foreground
|
||||
case (keyword == ParentBackground || keyword == ParentForeground) && a.ParentColors != nil:
|
||||
return resolveParentColor(keyword)
|
||||
default:
|
||||
return Transparent
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ func TestWriteANSIColors(t *testing.T) {
|
|||
ansi.init("pwsh")
|
||||
renderer := &AnsiWriter{
|
||||
ansi: ansi,
|
||||
ParentColors: tc.Parent,
|
||||
ParentColors: []*Color{tc.Parent},
|
||||
Colors: tc.Colors,
|
||||
terminalBackground: tc.TerminalBackground,
|
||||
ansiColors: &DefaultColors{},
|
||||
|
|
Loading…
Reference in a new issue