diff --git a/demos/presentation/main.go b/demos/presentation/main.go index b86af38..60f2e68 100644 --- a/demos/presentation/main.go +++ b/demos/presentation/main.go @@ -67,7 +67,7 @@ func main() { for index, slide := range slides { title, primitive := slide(nextSlide) pages.AddPage(strconv.Itoa(index), primitive, true, index == currentSlide) - fmt.Fprintf(info, `%d ["%d"][cyan]%s[white][""] `, index+1, index, title) + fmt.Fprintf(info, `%d ["%d"][darkcyan]%s[white][""] `, index+1, index, title) } // Create the main layout. diff --git a/demos/textview/main.go b/demos/textview/main.go index 528827b..6eaf9d2 100644 --- a/demos/textview/main.go +++ b/demos/textview/main.go @@ -31,7 +31,7 @@ func main() { go func() { for _, word := range strings.Split(corporate, " ") { if word == "the" { - word = "[red]the[white]" + word = "[#ff0000]the[white]" } if word == "to" { word = fmt.Sprintf(`["%d"]to[""]`, numSelections) diff --git a/textview.go b/textview.go index 1b2709e..1ba5bc2 100644 --- a/textview.go +++ b/textview.go @@ -11,21 +11,9 @@ import ( runewidth "github.com/mattn/go-runewidth" ) -// textColors maps color strings which may be embedded in text sent to a -// TextView to their tcell counterparts. -var textColors = map[string]tcell.Color{ - "red": tcell.ColorRed, - "white": tcell.ColorWhite, - "yellow": tcell.ColorYellow, - "blue": tcell.ColorBlue, - "green": tcell.ColorGreen, - "cyan": tcell.ColorDarkCyan, - "magenta": tcell.ColorDarkMagenta, -} - // Regular expressions commonly used throughout the TextView class. var ( - colorPattern *regexp.Regexp // Initialized in the init() function. + colorPattern = regexp.MustCompile(`\[([a-zA-Z]+|#[0-9a-zA-Z]{6})\]`) regionPattern = regexp.MustCompile(`\["([a-zA-Z0-9_,;: \-\.]*)"\]`) ) @@ -72,8 +60,9 @@ type textViewIndex struct { // // This is a [red]warning[white]! // -// will print the word "warning" in red. The following colors are currently -// supported: white, yellow, blue, green, red, cyan, magenta. +// will print the word "warning" in red. You can provide W3C color names or +// hex strings starting with "#", followed by 6 hexadecimal digits. See +// tcell.GetColor() for more information. // // Regions and Highlights // @@ -489,7 +478,7 @@ func (t *TextView) reindexBuffer(width int) { // Skip any color tags. if currentTag < len(colorTags) && pos >= colorTagIndices[currentTag][0] && pos < colorTagIndices[currentTag][1] { if pos == colorTagIndices[currentTag][1]-1 { - color = textColors[colorTags[currentTag][1]] + color = tcell.GetColor(colorTags[currentTag][1]) currentTag++ } continue @@ -631,7 +620,7 @@ func (t *TextView) Draw(screen tcell.Screen) { // Get the color. if currentTag < len(colorTags) && pos >= colorTagIndices[currentTag][0] && pos < colorTagIndices[currentTag][1] { if pos == colorTagIndices[currentTag][1]-1 { - color = textColors[colorTags[currentTag][1]] + color = tcell.GetColor(colorTags[currentTag][1]) currentTag++ } continue diff --git a/util.go b/util.go index e4a5188..2505aba 100644 --- a/util.go +++ b/util.go @@ -2,7 +2,6 @@ package tview import ( "math" - "regexp" "strconv" "strings" @@ -75,16 +74,6 @@ func init() { return len([]rune(text)) <= maxLength } } - - // Regular expressions. - var colors string - for color := range textColors { - if len(colors) > 0 { - colors += "|" - } - colors += color - } - colorPattern = regexp.MustCompile(`\[(` + colors + `)\]`) } // Print prints text onto the screen into the given box at (x,y,maxWidth,1),