From 8292f9baf209a96067f368ac19e762a560848687 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sun, 30 Aug 2020 08:36:03 -0700 Subject: [PATCH] Upgrade tcell to v2 Resolves #32. --- CHANGELOG | 1 + application.go | 2 +- box.go | 4 +- button.go | 2 +- checkbox.go | 2 +- demos/box/main.go | 2 +- demos/frame/main.go | 16 ++++---- demos/inputfield/autocomplete/main.go | 2 +- demos/inputfield/autocompleteasync/main.go | 2 +- demos/inputfield/simple/main.go | 2 +- demos/presentation/colors.go | 2 +- demos/presentation/cover.go | 12 +++--- demos/presentation/end.go | 2 +- demos/presentation/flex.go | 2 +- demos/presentation/grid.go | 2 +- demos/presentation/inputfield.go | 2 +- demos/presentation/main.go | 2 +- demos/presentation/table.go | 44 +++++++++++----------- demos/presentation/textview.go | 6 +-- demos/presentation/treeview.go | 6 +-- demos/primitive/main.go | 4 +- demos/table/main.go | 8 ++-- demos/textview/main.go | 2 +- demos/treeview/main.go | 6 +-- doc_test.go | 2 +- dropdown.go | 2 +- flex.go | 2 +- form.go | 2 +- frame.go | 2 +- go.mod | 7 ++-- go.sum | 30 +++++---------- grid.go | 2 +- inputfield.go | 2 +- keys.go | 2 +- list.go | 8 ++-- modal.go | 2 +- pages.go | 2 +- primitive.go | 2 +- progressbar.go | 2 +- semigraphics.go | 2 +- styles.go | 34 ++++++++--------- table.go | 14 +++---- textview.go | 6 +-- treeview.go | 4 +- util.go | 17 +++++++-- util_test.go | 2 +- 46 files changed, 141 insertions(+), 142 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 49e6272..9ae5003 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ v1.4.9 (WIP) - Add InputField.GetCursorPosition and InputField.SetCursorPosition +- Upgrade tcell to v2 v1.4.8 (2020-08-11) - Add italic text formatting flag diff --git a/application.go b/application.go index c360d16..59dd8f1 100644 --- a/application.go +++ b/application.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) const ( diff --git a/box.go b/box.go index 81a4760..ebc665b 100644 --- a/box.go +++ b/box.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // Box is the base Primitive for all widgets. It has a background color and @@ -397,7 +397,7 @@ func (b *Box) Draw(screen tcell.Screen) { // Draw border. if b.border && b.width >= 2 && b.height >= 2 { - border := background.Foreground(b.borderColor) | tcell.Style(b.borderAttributes) + border := SetAttributes(background.Foreground(b.borderColor), b.borderAttributes) var vertical, horizontal, topLeft, topRight, bottomLeft, bottomRight rune var hasFocus bool diff --git a/button.go b/button.go index baf42e0..bcfd873 100644 --- a/button.go +++ b/button.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // Button is labeled box that triggers an action when selected. diff --git a/checkbox.go b/checkbox.go index fd4dccd..980e65b 100644 --- a/checkbox.go +++ b/checkbox.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // CheckBox implements a simple box for boolean values which can be checked and diff --git a/demos/box/main.go b/demos/box/main.go index 9c0df89..09d6396 100644 --- a/demos/box/main.go +++ b/demos/box/main.go @@ -2,7 +2,7 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/frame/main.go b/demos/frame/main.go index 362bc65..ed65c05 100644 --- a/demos/frame/main.go +++ b/demos/frame/main.go @@ -2,20 +2,20 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) func main() { app := cview.NewApplication() - frame := cview.NewFrame(cview.NewBox().SetBackgroundColor(tcell.ColorBlue)). + frame := cview.NewFrame(cview.NewBox().SetBackgroundColor(tcell.ColorBlue.TrueColor())). SetBorders(2, 2, 2, 2, 4, 4). - AddText("Header left", true, cview.AlignLeft, tcell.ColorWhite). - AddText("Header middle", true, cview.AlignCenter, tcell.ColorWhite). - AddText("Header right", true, cview.AlignRight, tcell.ColorWhite). - AddText("Header second middle", true, cview.AlignCenter, tcell.ColorRed). - AddText("Footer middle", false, cview.AlignCenter, tcell.ColorGreen). - AddText("Footer second middle", false, cview.AlignCenter, tcell.ColorGreen) + AddText("Header left", true, cview.AlignLeft, tcell.ColorWhite.TrueColor()). + AddText("Header middle", true, cview.AlignCenter, tcell.ColorWhite.TrueColor()). + AddText("Header right", true, cview.AlignRight, tcell.ColorWhite.TrueColor()). + AddText("Header second middle", true, cview.AlignCenter, tcell.ColorRed.TrueColor()). + AddText("Footer middle", false, cview.AlignCenter, tcell.ColorGreen.TrueColor()). + AddText("Footer second middle", false, cview.AlignCenter, tcell.ColorGreen.TrueColor()) if err := app.SetRoot(frame, true).EnableMouse(true).Run(); err != nil { panic(err) } diff --git a/demos/inputfield/autocomplete/main.go b/demos/inputfield/autocomplete/main.go index 658eb36..0d5b3a8 100644 --- a/demos/inputfield/autocomplete/main.go +++ b/demos/inputfield/autocomplete/main.go @@ -3,7 +3,7 @@ package main import ( "strings" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/inputfield/autocompleteasync/main.go b/demos/inputfield/autocompleteasync/main.go index 6e6c2a7..f866194 100644 --- a/demos/inputfield/autocompleteasync/main.go +++ b/demos/inputfield/autocompleteasync/main.go @@ -7,7 +7,7 @@ import ( "strings" "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/inputfield/simple/main.go b/demos/inputfield/simple/main.go index e45f477..1fce6d3 100644 --- a/demos/inputfield/simple/main.go +++ b/demos/inputfield/simple/main.go @@ -2,7 +2,7 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/presentation/colors.go b/demos/presentation/colors.go index 486b5ac..8a80aa0 100644 --- a/demos/presentation/colors.go +++ b/demos/presentation/colors.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/presentation/cover.go b/demos/presentation/cover.go index 41c1c12..3aeb61e 100644 --- a/demos/presentation/cover.go +++ b/demos/presentation/cover.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) @@ -34,7 +34,7 @@ func Cover(nextSlide func()) (title string, content cview.Primitive) { } } logoBox := cview.NewTextView(). - SetTextColor(tcell.ColorGreen). + SetTextColor(tcell.ColorGreen.TrueColor()). SetDoneFunc(func(key tcell.Key) { nextSlide() }) @@ -43,10 +43,10 @@ func Cover(nextSlide func()) (title string, content cview.Primitive) { // Create a frame for the subtitle and navigation infos. frame := cview.NewFrame(cview.NewBox()). SetBorders(0, 0, 0, 0, 0, 0). - AddText(subtitle, true, cview.AlignCenter, tcell.ColorWhite). - AddText("", true, cview.AlignCenter, tcell.ColorWhite). - AddText(mouse, true, cview.AlignCenter, tcell.ColorDarkMagenta). - AddText(navigation, true, cview.AlignCenter, tcell.ColorDarkMagenta) + AddText(subtitle, true, cview.AlignCenter, tcell.ColorWhite.TrueColor()). + AddText("", true, cview.AlignCenter, tcell.ColorWhite.TrueColor()). + AddText(mouse, true, cview.AlignCenter, tcell.ColorDarkMagenta.TrueColor()). + AddText(navigation, true, cview.AlignCenter, tcell.ColorDarkMagenta.TrueColor()) // Create a Flex layout that centers the logo and subtitle. flex := cview.NewFlex(). diff --git a/demos/presentation/end.go b/demos/presentation/end.go index 09419d6..d17c2da 100644 --- a/demos/presentation/end.go +++ b/demos/presentation/end.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/presentation/flex.go b/demos/presentation/flex.go index 99fcf49..ac5f90e 100644 --- a/demos/presentation/flex.go +++ b/demos/presentation/flex.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/presentation/grid.go b/demos/presentation/grid.go index a77c580..006fa72 100644 --- a/demos/presentation/grid.go +++ b/demos/presentation/grid.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/presentation/inputfield.go b/demos/presentation/inputfield.go index 7eb8601..2851d68 100644 --- a/demos/presentation/inputfield.go +++ b/demos/presentation/inputfield.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/presentation/main.go b/demos/presentation/main.go index c99ae58..b7a430e 100644 --- a/demos/presentation/main.go +++ b/demos/presentation/main.go @@ -20,7 +20,7 @@ import ( _ "net/http/pprof" "strconv" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/presentation/table.go b/demos/presentation/table.go index 7570f7a..e11b9ea 100644 --- a/demos/presentation/table.go +++ b/demos/presentation/table.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) @@ -58,11 +58,11 @@ const tableBasic = `[green]func[white] [yellow]main[white]() { [yellow]SetFixed[white]([red]1[white], [red]1[white]) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { - color := tcell.ColorWhite + color := tcell.ColorWhite.TrueColor() [yellow]if[white] row == [red]0[white] { - color = tcell.ColorYellow + color = tcell.ColorYellow.TrueColor() } [yellow]else[white] [yellow]if[white] column == [red]0[white] { - color = tcell.ColorDarkCyan + color = tcell.ColorDarkCyan.TrueColor() } align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { @@ -90,11 +90,11 @@ const tableSeparator = `[green]func[white] [yellow]main[white]() { [yellow]SetSeparator[white](Borders.Vertical) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { - color := tcell.ColorWhite + color := tcell.ColorWhite.TrueColor() [yellow]if[white] row == [red]0[white] { - color = tcell.ColorYellow + color = tcell.ColorYellow.TrueColor() } [yellow]else[white] [yellow]if[white] column == [red]0[white] { - color = tcell.ColorDarkCyan + color = tcell.ColorDarkCyan.TrueColor() } align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { @@ -122,11 +122,11 @@ const tableBorders = `[green]func[white] [yellow]main[white]() { [yellow]SetBorders[white](true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { - color := tcell.ColorWhite + color := tcell.ColorWhite.TrueColor() [yellow]if[white] row == [red]0[white] { - color = tcell.ColorYellow + color = tcell.ColorYellow.TrueColor() } [yellow]else[white] [yellow]if[white] column == [red]0[white] { - color = tcell.ColorDarkCyan + color = tcell.ColorDarkCyan.TrueColor() } align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { @@ -154,11 +154,11 @@ const tableSelectRow = `[green]func[white] [yellow]main[white]() { [yellow]SetSelectable[white](true, false) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { - color := tcell.ColorWhite + color := tcell.ColorWhite.TrueColor() [yellow]if[white] row == [red]0[white] { - color = tcell.ColorYellow + color = tcell.ColorYellow.TrueColor() } [yellow]else[white] [yellow]if[white] column == [red]0[white] { - color = tcell.ColorDarkCyan + color = tcell.ColorDarkCyan.TrueColor() } align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { @@ -187,11 +187,11 @@ const tableSelectColumn = `[green]func[white] [yellow]main[white]() { [yellow]SetSelectable[white](false, true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { - color := tcell.ColorWhite + color := tcell.ColorWhite.TrueColor() [yellow]if[white] row == [red]0[white] { - color = tcell.ColorYellow + color = tcell.ColorYellow.TrueColor() } [yellow]else[white] [yellow]if[white] column == [red]0[white] { - color = tcell.ColorDarkCyan + color = tcell.ColorDarkCyan.TrueColor() } align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { @@ -220,11 +220,11 @@ const tableSelectCell = `[green]func[white] [yellow]main[white]() { [yellow]SetSelectable[white](true, true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { - color := tcell.ColorWhite + color := tcell.ColorWhite.TrueColor() [yellow]if[white] row == [red]0[white] { - color = tcell.ColorYellow + color = tcell.ColorYellow.TrueColor() } [yellow]else[white] [yellow]if[white] column == [red]0[white] { - color = tcell.ColorDarkCyan + color = tcell.ColorDarkCyan.TrueColor() } align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { @@ -253,11 +253,11 @@ func Table(nextSlide func()) (title string, content cview.Primitive) { SetFixed(1, 1) for row, line := range strings.Split(tableData, "\n") { for column, cell := range strings.Split(line, "|") { - color := tcell.ColorWhite + color := tcell.ColorWhite.TrueColor() if row == 0 { - color = tcell.ColorYellow + color = tcell.ColorYellow.TrueColor() } else if column == 0 { - color = tcell.ColorDarkCyan + color = tcell.ColorDarkCyan.TrueColor() } align := cview.AlignLeft if row == 0 { diff --git a/demos/presentation/textview.go b/demos/presentation/textview.go index ccca782..16eab95 100644 --- a/demos/presentation/textview.go +++ b/demos/presentation/textview.go @@ -5,14 +5,14 @@ import ( "strconv" "time" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) const textView1 = `[green]func[white] [yellow]main[white]() { app := cview.[yellow]NewApplication[white]() textView := cview.[yellow]NewTextView[white](). - [yellow]SetTextColor[white](tcell.ColorYellow). + [yellow]SetTextColor[white](tcell.ColorYellow.TrueColor()). [yellow]SetScrollable[white](false). [yellow]SetChangedFunc[white]([yellow]func[white]() { app.[yellow]Draw[white]() @@ -32,7 +32,7 @@ const textView1 = `[green]func[white] [yellow]main[white]() { // TextView1 demonstrates the basic text view. func TextView1(nextSlide func()) (title string, content cview.Primitive) { textView := cview.NewTextView(). - SetTextColor(tcell.ColorYellow). + SetTextColor(tcell.ColorYellow.TrueColor()). SetScrollable(false). SetDoneFunc(func(key tcell.Key) { nextSlide() diff --git a/demos/presentation/treeview.go b/demos/presentation/treeview.go index 6cd5a49..a1033d0 100644 --- a/demos/presentation/treeview.go +++ b/demos/presentation/treeview.go @@ -3,7 +3,7 @@ package main import ( "strings" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) @@ -119,9 +119,9 @@ func TreeView(nextSlide func()) (title string, content cview.Primitive) { SetExpanded(target == rootNode). SetReference(target) if target.expand { - node.SetColor(tcell.ColorGreen) + node.SetColor(tcell.ColorGreen.TrueColor()) } else if target.selected != nil { - node.SetColor(tcell.ColorRed) + node.SetColor(tcell.ColorRed.TrueColor()) } for _, child := range target.children { node.AddChild(add(child)) diff --git a/demos/primitive/main.go b/demos/primitive/main.go index 2910a68..b7e1808 100644 --- a/demos/primitive/main.go +++ b/demos/primitive/main.go @@ -4,7 +4,7 @@ package main import ( "fmt" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) @@ -37,7 +37,7 @@ func (r *RadioButtons) Draw(screen tcell.Screen) { radioButton = "\u25c9" // Checked. } line := fmt.Sprintf(`%s[white] %s`, radioButton, option) - cview.Print(screen, line, x, y+index, width, cview.AlignLeft, tcell.ColorYellow) + cview.Print(screen, line, x, y+index, width, cview.AlignLeft, tcell.ColorYellow.TrueColor()) } } diff --git a/demos/table/main.go b/demos/table/main.go index 4eb415e..2c2cfad 100644 --- a/demos/table/main.go +++ b/demos/table/main.go @@ -4,7 +4,7 @@ package main import ( "strings" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) @@ -17,9 +17,9 @@ func main() { word := 0 for r := 0; r < rows; r++ { for c := 0; c < cols; c++ { - color := tcell.ColorWhite + color := tcell.ColorWhite.TrueColor() if c < 1 || r < 1 { - color = tcell.ColorYellow + color = tcell.ColorYellow.TrueColor() } table.SetCell(r, c, cview.NewTableCell(lorem[word]). @@ -36,7 +36,7 @@ func main() { table.SetSelectable(true, true) } }).SetSelectedFunc(func(row int, column int) { - table.GetCell(row, column).SetTextColor(tcell.ColorRed) + table.GetCell(row, column).SetTextColor(tcell.ColorRed.TrueColor()) table.SetSelectable(false, false) }) if err := app.SetRoot(table, true).EnableMouse(true).Run(); err != nil { diff --git a/demos/textview/main.go b/demos/textview/main.go index 4da4a7a..de0e316 100644 --- a/demos/textview/main.go +++ b/demos/textview/main.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) diff --git a/demos/treeview/main.go b/demos/treeview/main.go index c8abeb8..2ec5da2 100644 --- a/demos/treeview/main.go +++ b/demos/treeview/main.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "path/filepath" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cview" ) @@ -13,7 +13,7 @@ import ( func main() { rootDir := "." root := cview.NewTreeNode(rootDir). - SetColor(tcell.ColorRed) + SetColor(tcell.ColorRed.TrueColor()) tree := cview.NewTreeView(). SetRoot(root). SetCurrentNode(root) @@ -30,7 +30,7 @@ func main() { SetReference(filepath.Join(path, file.Name())). SetSelectable(file.IsDir()) if file.IsDir() { - node.SetColor(tcell.ColorGreen) + node.SetColor(tcell.ColorGreen.TrueColor()) } target.AddChild(node) } diff --git a/doc_test.go b/doc_test.go index a925489..565810a 100644 --- a/doc_test.go +++ b/doc_test.go @@ -3,7 +3,7 @@ package cview import ( "fmt" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // Example of an application with multiple layouts. diff --git a/dropdown.go b/dropdown.go index 99c1c90..b2f4932 100644 --- a/dropdown.go +++ b/dropdown.go @@ -4,7 +4,7 @@ import ( "strings" "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // dropDownOption is one option that can be selected in a drop-down primitive. diff --git a/flex.go b/flex.go index afb7f7d..106a498 100644 --- a/flex.go +++ b/flex.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // Configuration values. diff --git a/form.go b/form.go index 659c3f6..108d20b 100644 --- a/form.go +++ b/form.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // DefaultFormFieldWidth is the default field screen width of form elements diff --git a/frame.go b/frame.go index d9b9ee2..5b9b49b 100644 --- a/frame.go +++ b/frame.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // frameText holds information about a line of text shown in the frame. diff --git a/go.mod b/go.mod index 96b3181..2fa58d0 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,10 @@ module gitlab.com/tslocum/cview go 1.12 require ( - github.com/gdamore/tcell v1.3.1-0.20200823221337-776d98d3850b + github.com/gdamore/tcell/v2 v2.0.0-dev.0.20200830100347-23606a43e286 github.com/lucasb-eyer/go-colorful v1.0.3 github.com/mattn/go-runewidth v0.0.9 github.com/rivo/uniseg v0.1.0 - gitlab.com/tslocum/cbind v0.1.1 - golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect - golang.org/x/text v0.3.3 // indirect + gitlab.com/tslocum/cbind v0.1.2-0.20200826214515-b5f2c6a8711a + golang.org/x/sys v0.0.0-20200828194041-157a740278f4 // indirect ) diff --git a/go.sum b/go.sum index ed1e746..7d5ef7e 100644 --- a/go.sum +++ b/go.sum @@ -1,35 +1,23 @@ -github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08= -github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM= -github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM= -github.com/gdamore/tcell v1.3.1-0.20200823221337-776d98d3850b h1:i5YlGe2SivCwep7niKxoTEgya61QwQRtkv6vclekai8= -github.com/gdamore/tcell v1.3.1-0.20200823221337-776d98d3850b/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0= -github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4= -github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s= +github.com/gdamore/tcell/v2 v2.0.0-dev/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= +github.com/gdamore/tcell/v2 v2.0.0-dev.0.20200830100347-23606a43e286 h1:29adRtDgT5AaOR9RiDQaZeiY+lb8mbQwz9WklTK6EuQ= +github.com/gdamore/tcell/v2 v2.0.0-dev.0.20200830100347-23606a43e286/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= -github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -gitlab.com/tslocum/cbind v0.1.1 h1:JXXtxMWHgWLvoF+QkrvcNvOQ59juy7OE1RhT7hZfdt0= -gitlab.com/tslocum/cbind v0.1.1/go.mod h1:rX7vkl0pUSg/yy427MmD1FZAf99S7WwpUlxF/qTpPqk= -golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10= +gitlab.com/tslocum/cbind v0.1.2-0.20200826214515-b5f2c6a8711a h1:6u2QDDcKdeFhyHT/srxPDzLfDJqwKTgy1v+3209LYBY= +gitlab.com/tslocum/cbind v0.1.2-0.20200826214515-b5f2c6a8711a/go.mod h1:HfB7qAhHSZbn1rFK8M9SvSN5NG6ScAg/3h3iE6xdeeI= golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 h1:AvbQYmiaaaza3cW3QXRyPo5kYgpFIzOAfeAAN7m3qQ4= -golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8= +golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200828194041-157a740278f4 h1:kCCpuwSAoYJPkNc6x0xT9yTtV4oKtARo4RGBQWOfg9E= +golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/grid.go b/grid.go index 1bb759a..d2027da 100644 --- a/grid.go +++ b/grid.go @@ -4,7 +4,7 @@ import ( "math" "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // gridItem represents one primitive and its possible position on a grid. diff --git a/inputfield.go b/inputfield.go index b316760..7039a20 100644 --- a/inputfield.go +++ b/inputfield.go @@ -7,7 +7,7 @@ import ( "sync" "unicode/utf8" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // InputField is a one-line box (three lines if there is a title) where the diff --git a/keys.go b/keys.go index 86ba0d4..096b218 100644 --- a/keys.go +++ b/keys.go @@ -1,7 +1,7 @@ package cview import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "gitlab.com/tslocum/cbind" ) diff --git a/list.go b/list.go index 22f9e06..2a966a5 100644 --- a/list.go +++ b/list.go @@ -5,7 +5,7 @@ import ( "strings" "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // listItem represents one item in a List. @@ -763,11 +763,11 @@ func (l *List) Draw(screen tcell.Screen) { } else if !item.Enabled { // Disabled item // Shortcuts. if showShortcuts && item.Shortcut != 0 { - Print(screen, fmt.Sprintf("(%s)", string(item.Shortcut)), x-5, y, 4, AlignRight, tcell.ColorDarkSlateGray) + Print(screen, fmt.Sprintf("(%s)", string(item.Shortcut)), x-5, y, 4, AlignRight, tcell.ColorDarkSlateGray.TrueColor()) } // Main text. - Print(screen, item.MainText, x, y, width, AlignLeft, tcell.ColorGray) + Print(screen, item.MainText, x, y, width, AlignLeft, tcell.ColorGray.TrueColor()) RenderScrollBar(screen, l.scrollBarVisibility, scrollBarX, y, scrollBarHeight, len(l.items), l.currentItem, index-l.offset, l.hasFocus, l.scrollBarColor) y++ @@ -797,7 +797,7 @@ func (l *List) Draw(screen tcell.Screen) { if fg == l.mainTextColor { fg = l.selectedTextColor } - style = style.Background(l.selectedBackgroundColor).Foreground(fg) | tcell.Style(l.selectedTextAttributes) + style = SetAttributes(style.Background(l.selectedBackgroundColor).Foreground(fg), l.selectedTextAttributes) screen.SetContent(x+bx, y, m, c, style) } } diff --git a/modal.go b/modal.go index d6b4100..d5d928d 100644 --- a/modal.go +++ b/modal.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // Modal is a centered message window used to inform the user or prompt them diff --git a/pages.go b/pages.go index 0ae9557..f4e22c8 100644 --- a/pages.go +++ b/pages.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // page represents one page of a Pages object. diff --git a/primitive.go b/primitive.go index 9714471..a12b990 100644 --- a/primitive.go +++ b/primitive.go @@ -1,6 +1,6 @@ package cview -import "github.com/gdamore/tcell" +import "github.com/gdamore/tcell/v2" // Primitive is the top-most interface for all graphical primitives. type Primitive interface { diff --git a/progressbar.go b/progressbar.go index b278f2c..eb8b650 100644 --- a/progressbar.go +++ b/progressbar.go @@ -4,7 +4,7 @@ import ( "math" "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // ProgressBar indicates the progress of an operation. diff --git a/semigraphics.go b/semigraphics.go index 64f55ac..9bc3679 100644 --- a/semigraphics.go +++ b/semigraphics.go @@ -1,6 +1,6 @@ package cview -import "github.com/gdamore/tcell" +import "github.com/gdamore/tcell/v2" // Semigraphics provides an easy way to access unicode characters for drawing. // diff --git a/styles.go b/styles.go index 667f0fb..4dbe436 100644 --- a/styles.go +++ b/styles.go @@ -1,6 +1,6 @@ package cview -import "github.com/gdamore/tcell" +import "github.com/gdamore/tcell/v2" // Theme defines the colors used when primitives are initialized. type Theme struct { @@ -21,38 +21,38 @@ type Theme struct { ContrastBackgroundColor tcell.Color // Background color for contrasting elements. MoreContrastBackgroundColor tcell.Color // Background color for even more contrasting elements. + // Scroll bar + ScrollBarColor tcell.Color // Scroll bar color. + // Context menu ContextMenuPaddingTop int // Top padding. ContextMenuPaddingBottom int // Bottom padding. ContextMenuPaddingLeft int // Left padding. ContextMenuPaddingRight int // Right padding. - - // Scroll bar - ScrollBarColor tcell.Color // Scroll bar color. } // Styles defines the appearance of an application. The default is for a black // background and some basic colors: black, white, yellow, green, cyan, and // blue. var Styles = Theme{ - TitleColor: tcell.ColorWhite, - BorderColor: tcell.ColorWhite, - GraphicsColor: tcell.ColorWhite, + TitleColor: tcell.ColorWhite.TrueColor(), + BorderColor: tcell.ColorWhite.TrueColor(), + GraphicsColor: tcell.ColorWhite.TrueColor(), - PrimaryTextColor: tcell.ColorWhite, - SecondaryTextColor: tcell.ColorYellow, - TertiaryTextColor: tcell.ColorGreen, - InverseTextColor: tcell.ColorBlue, - ContrastSecondaryTextColor: tcell.ColorDarkCyan, + PrimaryTextColor: tcell.ColorWhite.TrueColor(), + SecondaryTextColor: tcell.ColorYellow.TrueColor(), + TertiaryTextColor: tcell.ColorGreen.TrueColor(), + InverseTextColor: tcell.ColorBlue.TrueColor(), + ContrastSecondaryTextColor: tcell.ColorDarkCyan.TrueColor(), - PrimitiveBackgroundColor: tcell.ColorBlack, - ContrastBackgroundColor: tcell.ColorBlue, - MoreContrastBackgroundColor: tcell.ColorGreen, + PrimitiveBackgroundColor: tcell.ColorBlack.TrueColor(), + ContrastBackgroundColor: tcell.ColorBlue.TrueColor(), + MoreContrastBackgroundColor: tcell.ColorGreen.TrueColor(), + + ScrollBarColor: tcell.ColorWhite.TrueColor(), ContextMenuPaddingTop: 0, ContextMenuPaddingBottom: 0, ContextMenuPaddingLeft: 1, ContextMenuPaddingRight: 1, - - ScrollBarColor: tcell.ColorWhite, } diff --git a/table.go b/table.go index c4cb941..bda3e24 100644 --- a/table.go +++ b/table.go @@ -4,7 +4,7 @@ import ( "sort" "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" colorful "github.com/lucasb-eyer/go-colorful" ) @@ -301,8 +301,8 @@ type Table struct { // The scroll bar color. scrollBarColor tcell.Color - // The style of the selected rows. If this value is 0, selected rows are - // simply inverted. + // The style of the selected rows. If this value is StyleDefault, selected rows + // are simply inverted. selectedStyle tcell.Style // An optional function which gets called when the user presses Enter on a @@ -392,7 +392,7 @@ func (t *Table) SetSelectedStyle(foregroundColor, backgroundColor tcell.Color, a t.Lock() defer t.Unlock() - t.selectedStyle = tcell.StyleDefault.Foreground(foregroundColor).Background(backgroundColor) | tcell.Style(attributes) + t.selectedStyle = SetAttributes(tcell.StyleDefault.Foreground(foregroundColor).Background(backgroundColor), attributes) return t } @@ -1024,7 +1024,7 @@ ColumnLoop: finalWidth = width - columnX - 1 } cell.x, cell.y, cell.width = x+columnX+1, y+rowY, finalWidth - _, printed := printWithStyle(screen, cell.Text, x+columnX+1, y+rowY, finalWidth, cell.Align, tcell.StyleDefault.Foreground(cell.Color)|tcell.Style(cell.Attributes)) + _, printed := printWithStyle(screen, cell.Text, x+columnX+1, y+rowY, finalWidth, cell.Align, SetAttributes(tcell.StyleDefault.Foreground(cell.Color), cell.Attributes)) if TaggedStringWidth(cell.Text)-printed > 0 && printed > 0 { _, _, style, _ := screen.GetContent(x+columnX+finalWidth, y+rowY) printWithStyle(screen, string(SemigraphicsHorizontalEllipsis), x+columnX+finalWidth, y+rowY, 1, AlignLeft, style) @@ -1125,7 +1125,7 @@ ColumnLoop: if attr != 0 { a = attr } - style = style.Background(bg).Foreground(fg) | tcell.Style(a) + style = SetAttributes(style.Background(bg).Foreground(fg), a) } screen.SetContent(fromX+bx, fromY+by, m, c, style) } @@ -1188,7 +1188,7 @@ ColumnLoop: entries := cellsByBackgroundColor[bgColor] for _, cell := range entries { if cell.selected { - if t.selectedStyle != 0 { + if t.selectedStyle != tcell.StyleDefault { defer colorBackground(cell.x, cell.y, cell.w, cell.h, selBg, selFg, selAttr, false) } else { defer colorBackground(cell.x, cell.y, cell.w, cell.h, bgColor, cell.text, 0, true) diff --git a/textview.go b/textview.go index fa0356c..7dd2d0f 100644 --- a/textview.go +++ b/textview.go @@ -7,7 +7,7 @@ import ( "sync" "unicode/utf8" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "github.com/lucasb-eyer/go-colorful" "github.com/mattn/go-runewidth" "github.com/rivo/uniseg" @@ -1126,9 +1126,9 @@ func (t *TextView) Draw(screen tcell.Screen) { c := colorful.Color{R: float64(r) / 255, G: float64(g) / 255, B: float64(b) / 255} _, _, li := c.Hcl() if li < .5 { - bg = tcell.ColorWhite + bg = tcell.ColorWhite.TrueColor() } else { - bg = tcell.ColorBlack + bg = tcell.ColorBlack.TrueColor() } } style = style.Background(fg).Foreground(bg) diff --git a/treeview.go b/treeview.go index 24be257..cb060bf 100644 --- a/treeview.go +++ b/treeview.go @@ -3,7 +3,7 @@ package cview import ( "sync" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // Tree navigation events. @@ -855,7 +855,7 @@ func (t *TreeView) Draw(screen tcell.Screen) { } // Draw scroll bar. - RenderScrollBar(screen, t.scrollBarVisibility, x+(width-1), posY, height, rows, cursor, posY-y, t.hasFocus, tcell.ColorWhite) + RenderScrollBar(screen, t.scrollBarVisibility, x+(width-1), posY, height, rows, cursor, posY-y, t.hasFocus, tcell.ColorWhite.TrueColor()) // Advance. posY++ diff --git a/util.go b/util.go index 56b3b51..a3b4914 100644 --- a/util.go +++ b/util.go @@ -6,7 +6,7 @@ import ( "sort" "strconv" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" runewidth "github.com/mattn/go-runewidth" "github.com/rivo/uniseg" ) @@ -142,14 +142,14 @@ func overlayStyle(background tcell.Color, defaultStyle tcell.Style, fgColor, bgC if fgColor == "-" { style = style.Foreground(defFg) } else { - style = style.Foreground(tcell.GetColor(fgColor)) + style = style.Foreground(tcell.GetColor(fgColor).TrueColor()) } } if bgColor == "-" || bgColor == "" && defBg != tcell.ColorDefault { style = style.Background(defBg) } else if bgColor != "" { - style = style.Background(tcell.GetColor(bgColor)) + style = style.Background(tcell.GetColor(bgColor).TrueColor()) } if attributes == "-" { @@ -182,6 +182,17 @@ func overlayStyle(background tcell.Color, defaultStyle tcell.Style, fgColor, bgC return style } +// SetAttributes sets attributes on a style. +func SetAttributes(style tcell.Style, attrs tcell.AttrMask) tcell.Style { + return style. + Blink(attrs&tcell.AttrBlink != 0). + Bold(attrs&tcell.AttrBold != 0). + Dim(attrs&tcell.AttrDim != 0). + Italic(attrs&tcell.AttrItalic != 0). + Reverse(attrs&tcell.AttrReverse != 0). + Underline(attrs&tcell.AttrUnderline != 0) +} + // decomposeString returns information about a string which may contain color // tags or region tags, depending on which ones are requested to be found. It // returns the indices of the color tags (as returned by diff --git a/util_test.go b/util_test.go index daaf86c..b29c4dd 100644 --- a/util_test.go +++ b/util_test.go @@ -1,7 +1,7 @@ package cview import ( - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" ) // newTestApp returns a new application connected to a simulation screen.