Skip to content

Commit

Permalink
Merge pull request #7 from Volte6/256-color-fix
Browse files Browse the repository at this point in the history
Changing tags used for default reversion
  • Loading branch information
Volte6 committed Feb 5, 2024
2 parents e914ab0 + dca4c2e commit 61e010a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions ansiproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
defaultFg int = 39
defaultBg int = 49

// 256 color specific
defaultFg256 int = -2
defaultBg256 int = -2

Expand Down Expand Up @@ -107,14 +106,23 @@ func (p *ansiProperties) AnsiReset() string {
func (p ansiProperties) PropagateAnsiCode(previous *ansiProperties) string {

if previous != nil {
if p.fg == defaultFg {
p.fg = previous.fg
}
if p.bg == defaultBg {
p.bg = previous.bg
}
if !p.bold {
p.bold = previous.bold
if colorMode == Color8 {
if p.fg == defaultFg {
p.fg = previous.fg
}
if p.bg == defaultBg {
p.bg = previous.bg
}
if !p.bold {
p.bold = previous.bold
}
} else {
if p.fg == defaultFg256 {
p.fg = previous.fg
}
if p.bg == defaultBg256 {
p.bg = previous.bg
}
}
}

Expand Down Expand Up @@ -152,16 +160,17 @@ func (p ansiProperties) PropagateAnsiCode(previous *ansiProperties) string {
}
}
} else {

if p.fg > -1 {
colorCode += "\033[38;5;" + strconv.Itoa(p.fg) + `m`
} else if p.fg == defaultFg256 {
colorCode += "\033[38;5;m"
colorCode += "\033[39m"
}

if p.bg > -1 {
colorCode += "\033[48;5;" + strconv.Itoa(p.bg) + `m`
} else if p.bg == defaultBg256 {
colorCode += "\033[48;5;m"
colorCode += "\033[49m"
}
}

Expand Down

0 comments on commit 61e010a

Please sign in to comment.