fix: inherit Transparent when no parent

This commit is contained in:
Jan De Dobbeleer 2021-10-24 18:42:01 +02:00 committed by Jan De Dobbeleer
parent 631aace7a8
commit eca24bebcc
3 changed files with 19 additions and 1 deletions

View file

@ -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)

View file

@ -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 <inherit>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, <red>world</>, rabbit",

View file

@ -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",