From eca24bebcce3ff429296e68c115dd27cea6d9f18 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 24 Oct 2021 18:42:01 +0200 Subject: [PATCH] fix: inherit Transparent when no parent --- src/ansi_color.go | 6 ++++++ src/ansi_color_test.go | 12 ++++++++++++ src/segment_az_functions.go | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ansi_color.go b/src/ansi_color.go index 299192e7..beabb8d5 100644 --- a/src/ansi_color.go +++ b/src/ansi_color.go @@ -137,9 +137,15 @@ func (a *AnsiColor) write(background, foreground, text string) { if background == Inherit && a.Parent != nil { background = a.Parent.Background } + if background == Inherit && a.Parent == nil { + background = Transparent + } if foreground == Inherit && a.Parent != nil { foreground = a.Parent.Foreground } + if foreground == Inherit && a.Parent == nil { + foreground = Transparent + } inverted := foreground == Transparent && len(background) != 0 background = a.getAnsiFromColorString(background, !inverted) foreground = a.getAnsiFromColorString(foreground, false) diff --git a/src/ansi_color_test.go b/src/ansi_color_test.go index 665024b5..12efb409 100644 --- a/src/ansi_color_test.go +++ b/src/ansi_color_test.go @@ -92,6 +92,18 @@ func TestWriteANSIColors(t *testing.T) { Colors: &Color{Foreground: "black", Background: "white"}, Parent: &Color{Foreground: "yellow", Background: "red"}, }, + { + Case: "Inherit no parent foreground", + Input: "hello world", + Expected: "\x1b[47m\x1b[30mhello \x1b[0m\x1b[47;49m\x1b[7mworld\x1b[0m", + Colors: &Color{Foreground: "black", Background: "white"}, + }, + { + Case: "Inherit no parent background", + Input: "hello <,inherit>world", + Expected: "\x1b[47m\x1b[30mhello \x1b[0m\x1b[30mworld\x1b[0m", + Colors: &Color{Foreground: "black", Background: "white"}, + }, { Case: "Inline override", Input: "hello, world, rabbit", diff --git a/src/segment_az_functions.go b/src/segment_az_functions.go index 6f8c685a..aa78d88b 100644 --- a/src/segment_az_functions.go +++ b/src/segment_az_functions.go @@ -12,7 +12,7 @@ func (az *azfunc) init(props *properties, env environmentInfo) { az.language = &language{ env: env, props: props, - extensions: []string{"host.json", "local.settings.json"}, + extensions: []string{"host.json", "local.settings.json", "function.json"}, commands: []*cmd{ { executable: "func",