diff --git a/helper.go b/helper.go index 5a71afb..b15496e 100644 --- a/helper.go +++ b/helper.go @@ -30,7 +30,7 @@ const ( ColorWhite ) -//Have a constant that defines number of colors +// Have a constant that defines number of colors const NumberofColors = 8 // Text style @@ -45,6 +45,18 @@ var ( dotw = rw.StringWidth(dot) ) +// termbox passthrough +type OutputMode int + +// termbox passthrough +const ( + OutputCurrent OutputMode = iota + OutputNormal + Output256 + Output216 + OutputGrayscale +) + /* ----------------------- End ----------------------------- */ func toTmAttr(x Attribute) tm.Attribute { @@ -220,3 +232,19 @@ func CellsToStr(cs []Cell) string { } return str } + +// Passthrough to termbox using termbox constants above +func SetOutputMode(mode OutputMode) { + switch mode { + case OutputCurrent: + tm.SetOutputMode(tm.OutputCurrent) + case OutputNormal: + tm.SetOutputMode(tm.OutputNormal) + case Output256: + tm.SetOutputMode(tm.Output256) + case Output216: + tm.SetOutputMode(tm.Output216) + case OutputGrayscale: + tm.SetOutputMode(tm.OutputGrayscale) + } +} diff --git a/textbuilder.go b/textbuilder.go index 12e2055..7c56d38 100644 --- a/textbuilder.go +++ b/textbuilder.go @@ -52,6 +52,11 @@ var attrMap = map[string]Attribute{ "reverse": AttrReverse, } +// Allow users to add/override the string to attribute mapping +func AddColorMap(str string, attr Attribute) { + colorMap[str] = attr +} + func rmSpc(s string) string { reg := regexp.MustCompile(`\s+`) return reg.ReplaceAllString(s, "") @@ -85,10 +90,10 @@ func (mtb MarkdownTxBuilder) readAttr(s string) (Attribute, Attribute) { if len(subs) > 1 { if subs[0] == "fg" { fgs = append(fgs, subs[1]) - } - if subs[0] == "bg" { + } else if subs[0] == "bg" { bgs = append(bgs, subs[1]) } + // else maybe error somehow? } } diff --git a/theme.go b/theme.go index 21fb3bf..70f5024 100644 --- a/theme.go +++ b/theme.go @@ -138,3 +138,8 @@ func ColorRGB(r, g, b int) Attribute { r, b, g = within(r), within(b), within(g) return Attribute(0x0f + 36*r + 6*g + b) } + +// Convert from familiar 24 bit colors into 6 bit terminal colors +func ColorRGB24(r, g, b int) Attribute { + return ColorRGB(r/51, g/51, b/51) +}