diff --git a/app/main.go b/app/main.go index d7278b6..a025dca 100644 --- a/app/main.go +++ b/app/main.go @@ -81,7 +81,14 @@ func main() { fmt.Printf("C1: %s \n",c1.EscapeValues()) fmt.Println(c1) - c1 = c1.SetStyle(ansi.StyleBlink) + c1 = c1.SetStyle(ansi.StyleBlink).SetBgColor(ansi.ColorHWhite) fmt.Printf("C1: %s \n",c1.EscapeValues()) + fmt.Print(c1.Esc()) fmt.Println(c1) + + c1 = c1.DelStyle(ansi.StyleBold) + fmt.Printf("C1: %s \n",c1.EscapeValues()) + fmt.Print(c1.Esc()) + fmt.Println(c1) + } diff --git a/core/ansi/code.go b/core/ansi/code.go index 257515a..0ee6ea9 100644 --- a/core/ansi/code.go +++ b/core/ansi/code.go @@ -44,6 +44,7 @@ const ( txMask Code = 0b1111110000000000 bgShift int = 5 stShift int = 10 + stOpts int = 3 ) @@ -119,15 +120,22 @@ func (c Code) SetColors(fg, bg Color) Code { func (c Code) SetStyle (sty Style) Code { - v := Code(sty) - s := c >> 10 - if s != 0 { - v = (((s >> 3) & ^ v) << 3) | v - } - + /* + v := Code(sty) + v = ((((c >> 10) >> stOpts) & ^ v) << stOpts) | v return v << 10 | (c & clMask) + + */ + v := Code(sty) << stShift + return ((((c & txMask) >> stOpts) &^ v) << stOpts | v) | c & clMask } +func (c Code) DelStyle (sty Style) Code { + v := Code(sty) << (stOpts + stShift) + return ((((c & txMask) << stOpts) &^ v) >> stOpts | v) | c & clMask +} + + func (c Code) IsBoldOn () bool { return c & TextBoldOn != 0 } diff --git a/core/ansi/style.go b/core/ansi/style.go index ad019ff..403e675 100644 --- a/core/ansi/style.go +++ b/core/ansi/style.go @@ -30,11 +30,9 @@ const ( StyleUnderline StyleBlink - //StyleNonBold - //StyleNonUnderline - //StyleNonBlink - StyleNone Style = 0 + + allStyles = StyleBold | StyleUnderline | StyleBlink ) type ( @@ -45,6 +43,6 @@ type ( func (s Style) IsValid () bool { - return true + return s <= allStyles }