Upgraded to latest tcell version. Results in a minor incompatibility in the Table class.

pull/516/head
Oliver 4 years ago
parent 42866ecf6c
commit e4d167311d

@ -86,12 +86,20 @@ For a presentation highlighting this package, compile and run the program found
## Documentation
Refer to https://pkg.go.dev/github.com/rivo/tview for the package's documentation.
Refer to https://pkg.go.dev/github.com/rivo/tview for the package's documentation. Also check out the [Wiki](https://github.com/rivo/tview/wiki).
## Dependencies
This package is based on [github.com/gdamore/tcell](https://github.com/gdamore/tcell) (and its dependencies) as well as on [github.com/rivo/uniseg](https://github.com/rivo/uniseg).
## Versioning and Backwards-Compatibility
I try really hard to keep this project backwards compatible. Your software should not break when you upgrade `tview`. But this also means that some of its shortcomings that were present in the initial versions will remain. In addition, at least for the time being, you won't find any version tags in this repo. The newest version shoud be the one to upgrade to. It has all the bugfixes and latest features. Having said that, backwards compatibility may still break when:
- a new version of an imported package (most likely [`tcell`](https://github.com/gdamore/tcell)) changes in such a way that forces me to make changes in `tview` as well,
- I fix something that I consider a bug, rather than a feature, something that does not work as originally intended,
- I make changes to "internal" interfaces such as [`Primitive`](https://pkg.go.dev/github.com/rivo/tview#Primitive) or [`Focusable`](https://pkg.go.dev/github.com/rivo/tview#Focusable). You shouldn't need these interfaces unless you're writing your own primitives for `tview`.
## Your Feedback
Add your issue here on GitHub. Feel free to get in touch if you have any questions.

@ -4,7 +4,7 @@ import (
"sync"
"time"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
const (

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// Box implements the Primitive interface with an empty background and optional
@ -30,11 +30,8 @@ type Box struct {
// two in width and height.
border bool
// The color of the border.
borderColor tcell.Color
// The style attributes of the border.
borderAttributes tcell.AttrMask
// The border style.
borderStyle tcell.Style
// The title. Only visible if there is a border, too.
title string
@ -73,7 +70,7 @@ func NewBox() *Box {
height: 10,
innerX: -1, // Mark as uninitialized.
backgroundColor: Styles.PrimitiveBackgroundColor,
borderColor: Styles.BorderColor,
borderStyle: tcell.StyleDefault.Foreground(Styles.BorderColor),
titleColor: Styles.TitleColor,
titleAlign: AlignCenter,
}
@ -267,7 +264,7 @@ func (b *Box) SetBorder(show bool) *Box {
// SetBorderColor sets the box's border color.
func (b *Box) SetBorderColor(color tcell.Color) *Box {
b.borderColor = color
b.borderStyle = b.borderStyle.Foreground(color)
return b
}
@ -276,18 +273,20 @@ func (b *Box) SetBorderColor(color tcell.Color) *Box {
//
// box.SetBorderAttributes(tcell.AttrUnderline | tcell.AttrBold)
func (b *Box) SetBorderAttributes(attr tcell.AttrMask) *Box {
b.borderAttributes = attr
b.borderStyle = b.borderStyle.Attributes(attr)
return b
}
// GetBorderAttributes returns the border's style attributes.
func (b *Box) GetBorderAttributes() tcell.AttrMask {
return b.borderAttributes
_, _, attr := b.borderStyle.Decompose()
return attr
}
// GetBorderColor returns the box's border color.
func (b *Box) GetBorderColor() tcell.Color {
return b.borderColor
color, _, _ := b.borderStyle.Decompose()
return color
}
// GetBackgroundColor returns the box's background color.
@ -340,7 +339,6 @@ 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)
var vertical, horizontal, topLeft, topRight, bottomLeft, bottomRight rune
if b.focus.HasFocus() {
horizontal = Borders.HorizontalFocus
@ -358,17 +356,17 @@ func (b *Box) Draw(screen tcell.Screen) {
bottomRight = Borders.BottomRight
}
for x := b.x + 1; x < b.x+b.width-1; x++ {
screen.SetContent(x, b.y, horizontal, nil, border)
screen.SetContent(x, b.y+b.height-1, horizontal, nil, border)
screen.SetContent(x, b.y, horizontal, nil, b.borderStyle)
screen.SetContent(x, b.y+b.height-1, horizontal, nil, b.borderStyle)
}
for y := b.y + 1; y < b.y+b.height-1; y++ {
screen.SetContent(b.x, y, vertical, nil, border)
screen.SetContent(b.x+b.width-1, y, vertical, nil, border)
screen.SetContent(b.x, y, vertical, nil, b.borderStyle)
screen.SetContent(b.x+b.width-1, y, vertical, nil, b.borderStyle)
}
screen.SetContent(b.x, b.y, topLeft, nil, border)
screen.SetContent(b.x+b.width-1, b.y, topRight, nil, border)
screen.SetContent(b.x, b.y+b.height-1, bottomLeft, nil, border)
screen.SetContent(b.x+b.width-1, b.y+b.height-1, bottomRight, nil, border)
screen.SetContent(b.x, b.y, topLeft, nil, b.borderStyle)
screen.SetContent(b.x+b.width-1, b.y, topRight, nil, b.borderStyle)
screen.SetContent(b.x, b.y+b.height-1, bottomLeft, nil, b.borderStyle)
screen.SetContent(b.x+b.width-1, b.y+b.height-1, bottomRight, nil, b.borderStyle)
// Draw title.
if b.title != "" && b.width >= 4 {

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// Button is labeled box that triggers an action when selected.
@ -95,13 +95,13 @@ func (b *Button) SetBlurFunc(handler func(key tcell.Key)) *Button {
// Draw draws this primitive onto the screen.
func (b *Button) Draw(screen tcell.Screen) {
// Draw the box.
borderColor := b.borderColor
backgroundColor := b.backgroundColor
borderColor := b.GetBorderColor()
backgroundColor := b.GetBackgroundColor()
if b.focus.HasFocus() {
b.backgroundColor = b.backgroundColorActivated
b.borderColor = b.labelColorActivated
b.SetBackgroundColor(b.backgroundColorActivated)
b.SetBorderColor(b.labelColorActivated)
defer func() {
b.borderColor = borderColor
b.SetBorderColor(borderColor)
}()
}
b.Box.Draw(screen)

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// Checkbox implements a simple box for boolean values which can be checked and

@ -2,7 +2,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -2,7 +2,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -3,7 +3,7 @@ package main
import (
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -7,7 +7,7 @@ import (
"strings"
"sync"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -2,7 +2,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -3,7 +3,7 @@ package main
import (
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -1,7 +1,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -1,7 +1,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -1,7 +1,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -1,7 +1,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
@ -10,7 +10,7 @@ const inputField = `[green]package[white] main
[green]import[white] (
[red]"strconv"[white]
[red]"github.com/gdamore/tcell"[white]
[red]"github.com/gdamore/tcell/v2"[white]
[red]"github.com/rivo/tview"[white]
)

@ -16,7 +16,7 @@ import (
"fmt"
"strconv"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -5,7 +5,7 @@ import (
"strconv"
"time"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
@ -68,7 +68,7 @@ const textView2 = `[green]package[white] main
[green]import[white] (
[red]"strconv"[white]
[red]"github.com/gdamore/tcell"[white]
[red]"github.com/gdamore/tcell/v2"[white]
[red]"github.com/rivo/tview"[white]
)

@ -3,7 +3,7 @@ package main
import (
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -4,7 +4,7 @@ package main
import (
"fmt"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -4,7 +4,7 @@ package main
import (
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -5,7 +5,7 @@ import (
"io/ioutil"
"path/filepath"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

@ -3,7 +3,7 @@ package tview
import (
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// dropDownOption is one option that can be selected in a drop-down primitive.

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// Configuration values.

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// DefaultFormFieldWidth is the default field screen width of form elements

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// frameText holds information about a line of text shown in the frame.

@ -3,10 +3,10 @@ module github.com/rivo/tview
go 1.12
require (
github.com/gdamore/tcell v1.3.0
github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591
github.com/lucasb-eyer/go-colorful v1.0.3
github.com/mattn/go-runewidth v0.0.9
github.com/rivo/uniseg v0.1.0
golang.org/x/sys v0.0.0-20200817155316-9781c653f443 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7 // indirect
golang.org/x/text v0.3.3 // indirect
)

@ -1,25 +1,22 @@
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/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 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs=
github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591 h1:0WWUDZ1oxq7NxVyGo8M3KI5jbkiwNAdZFFzAdC68up4=
github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591/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.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=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200817155316-9781c653f443 h1:X18bCaipMcoJGm27Nv7zr4XYPKGUy92GtqboKC2Hxaw=
golang.org/x/sys v0.0.0-20200817155316-9781c653f443/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7 h1:XtNJkfEjb4zR3q20BBBcYUykVOEMgZeIUOpBPfNYgxg=
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
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/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

@ -3,7 +3,7 @@ package tview
import (
"math"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// gridItem represents one primitive and its possible position on a grid.

@ -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

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// listItem represents one item in a List.

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// Modal is a centered message window used to inform the user or prompt them

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// page represents one page of a Pages object.

@ -1,6 +1,6 @@
package tview
import "github.com/gdamore/tcell"
import "github.com/gdamore/tcell/v2"
// Primitive is the top-most interface for all graphical primitives.
type Primitive interface {

@ -1,6 +1,6 @@
package tview
import "github.com/gdamore/tcell"
import "github.com/gdamore/tcell/v2"
// Semigraphics provides an easy way to access unicode characters for drawing.
//

@ -1,6 +1,6 @@
package tview
import "github.com/gdamore/tcell"
import "github.com/gdamore/tcell/v2"
// Theme defines the colors used when primitives are initialized.
type Theme struct {

@ -3,7 +3,7 @@ package tview
import (
"sort"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
colorful "github.com/lucasb-eyer/go-colorful"
)
@ -271,8 +271,8 @@ type Table struct {
// drawn.
visibleColumnWidths []int
// 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 the empty struct,
// selected rows are simply inverted.
selectedStyle tcell.Style
// An optional function which gets called when the user presses Enter on a
@ -327,8 +327,8 @@ func (t *Table) SetBordersColor(color tcell.Color) *Table {
// To reset a previous setting to its default, make the following call:
//
// table.SetSelectedStyle(tcell.ColorDefault, tcell.ColorDefault, 0)
func (t *Table) SetSelectedStyle(foregroundColor, backgroundColor tcell.Color, attributes tcell.AttrMask) *Table {
t.selectedStyle = tcell.StyleDefault.Foreground(foregroundColor).Background(backgroundColor) | tcell.Style(attributes)
func (t *Table) SetSelectedStyle(style tcell.Style) *Table {
t.selectedStyle = style
return t
}
@ -885,7 +885,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, tcell.StyleDefault.Foreground(cell.Color).Attributes(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)
@ -954,7 +954,7 @@ ColumnLoop:
if attr != 0 {
a = attr
}
style = style.Background(bg).Foreground(fg) | tcell.Style(a)
style = style.Background(bg).Foreground(fg).Attributes(a)
}
screen.SetContent(fromX+bx, fromY+by, m, c, style)
}
@ -1017,7 +1017,7 @@ ColumnLoop:
entries := cellsByBackgroundColor[bgColor]
for _, cell := range entries {
if cell.selected {
if t.selectedStyle != 0 {
if t.selectedStyle != (tcell.Style{}) {
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)

@ -8,7 +8,7 @@ import (
"sync"
"unicode/utf8"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
colorful "github.com/lucasb-eyer/go-colorful"
runewidth "github.com/mattn/go-runewidth"
"github.com/rivo/uniseg"

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
)
// Tree navigation events.

@ -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"
)

Loading…
Cancel
Save