...

Source file src/github.com/rivo/tview/demos/presentation/colors.go

Documentation: github.com/rivo/tview/demos/presentation

     1  package main
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/gdamore/tcell/v2"
     7  	"github.com/rivo/tview"
     8  )
     9  
    10  const colorsText = `You can use color tags almost everywhere to partially change the color of a string. Simply put a color name or hex string in square brackets to change [::s]all[::-]the following characters' color. H[green]er[white]e i[yellow]s a[darkcyan]n ex[red]amp[white]le. [::i]The [black:red]tags [black:green]look [black:yellow]like [::u]this: [blue:yellow:u[] [#00ff00[]`
    11  
    12  // Colors demonstrates how to use colors.
    13  func Colors(nextSlide func()) (title string, content tview.Primitive) {
    14  	table := tview.NewTable().
    15  		SetBorders(true).
    16  		SetBordersColor(tcell.ColorBlue).
    17  		SetDoneFunc(func(key tcell.Key) {
    18  			nextSlide()
    19  		})
    20  	var row, column int
    21  	for _, word := range strings.Split(colorsText, " ") {
    22  		table.SetCellSimple(row, column, word)
    23  		column++
    24  		if column > 6 {
    25  			column = 0
    26  			row++
    27  		}
    28  	}
    29  	table.SetBorderPadding(1, 1, 2, 2).
    30  		SetBorder(true).
    31  		SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:] [::bu]title")
    32  	return "Colors", Center(78, 19, table)
    33  }
    34  

View as plain text