Update to tcell v2.0.0 (#358)

Migrate tcell to 2.0.0

* tview.TreeView#SetSelectedStyle removed
* tview.Primitives don't allow directly setting attributes for now (might change again with tview 2.+)
This commit is contained in:
Marcel Schramm 2020-10-24 13:22:48 +02:00 committed by GitHub
parent 62946ab52f
commit 52ee681981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
68 changed files with 170 additions and 234 deletions

View File

@ -7,7 +7,7 @@ import (
"path/filepath"
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// Theme is a wrapper around the tview.Theme. This wrapper can be extended with

View File

@ -1,7 +1,7 @@
package femto
import (
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/mattn/go-runewidth"
)

View File

@ -6,7 +6,7 @@ import (
"strconv"
"strings"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// Colorscheme is a map from string to style -- it represents a colorscheme

2
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/alecthomas/chroma v0.6.6
github.com/atotto/clipboard v0.1.2
github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/gdamore/tcell v1.4.0
github.com/gdamore/tcell/v2 v2.0.0
github.com/gen2brain/beeep v0.0.0-20200526185328-e9c15c258e28
github.com/google/go-github/v29 v29.0.3
github.com/lucasb-eyer/go-colorful v1.0.3

4
go.sum
View File

@ -33,8 +33,8 @@ github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
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.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
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/gen2brain/beeep v0.0.0-20200526185328-e9c15c258e28 h1:M2Zt3G2w6Q57GZndOYk42p7RvMeO8izO8yKTfIxGqxA=
github.com/gen2brain/beeep v0.0.0-20200526185328-e9c15c258e28/go.mod h1:ElSskYZe3oM8kThaHGJ+kiN2yyUMVXMZ7WxF9QqLDS8=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=

View File

@ -8,7 +8,7 @@ import (
"os"
"path/filepath"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/Bios-Marcel/cordless/config"
"github.com/Bios-Marcel/cordless/tview"

View File

@ -4,7 +4,7 @@ import (
"fmt"
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
func main() {

View File

@ -2,7 +2,7 @@ package main
import (
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
func main() {

View File

@ -7,7 +7,7 @@ import (
"strings"
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/Bios-Marcel/cordless/config"
)

View File

@ -3,7 +3,7 @@ package tview
import (
"sync"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// The size of the event/update/redraw channels.

View File

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// Box implements Primitive with a background and optional elements such as a
@ -41,11 +41,7 @@ type Box struct {
// The color of the border when the box has focus.
borderFocusColor tcell.Color
// The style attributes of the border.
borderAttributes tcell.AttrMask
// The style attributes of the border when the box has focus.
borderFocusAttributes tcell.AttrMask
borderBlinking bool
// If set to true, the text view will show down and up arrows if there is
// content out of sight. While box doesn't implement scrolling, this is
@ -99,7 +95,6 @@ func NewBox() *Box {
backgroundColor: Styles.PrimitiveBackgroundColor,
borderColor: Styles.BorderColor,
borderFocusColor: Styles.BorderFocusColor,
borderFocusAttributes: tcell.AttrNone,
titleColor: Styles.TitleColor,
titleAlign: AlignCenter,
borderTop: true,
@ -110,10 +105,6 @@ func NewBox() *Box {
nextFocusableComponents: make(map[FocusDirection][]Primitive),
}
if IsVtxxx {
b.borderFocusAttributes = tcell.AttrBold
}
b.focus = b
return b
}
@ -346,21 +337,8 @@ func (b *Box) IsBorderLeft() bool {
return b.border && b.borderLeft
}
// SetBorderAttributes sets the border's style attributes. You can combine
// different attributes using bitmask operations:
//
// box.SetBorderAttributes(tcell.AttrUnderline | tcell.AttrBold)
func (b *Box) SetBorderAttributes(attr tcell.AttrMask) *Box {
b.borderAttributes = attr
return b
}
// SetBorderFocusAttributes sets the border's style attributes when focused. You can combine
// different attributes using bitmask operations:
//
// box.SetBorderFocusAttributes(tcell.AttrUnderline | tcell.AttrBold)
func (b *Box) SetBorderFocusAttributes(attr tcell.AttrMask) *Box {
b.borderFocusAttributes = attr
func (b *Box) SetBorderBlinking(blinking bool) *Box {
b.borderBlinking = blinking
return b
}
@ -402,16 +380,20 @@ func (b *Box) Draw(screen tcell.Screen) bool {
// Draw border.
if b.border && b.width >= 2 && b.height >= 1 {
var border tcell.Style
var borderStyle tcell.Style
if b.hasFocus {
if b.borderFocusAttributes != 0 {
border = background.Foreground(b.borderFocusColor) | tcell.Style(b.borderFocusAttributes)
} else {
border = background.Foreground(b.borderFocusColor) | tcell.Style(b.borderAttributes)
borderStyle = background.Foreground(b.borderFocusColor)
if IsVtxxx {
borderStyle = borderStyle.Bold(true)
}
} else {
border = background.Foreground(b.borderColor) | tcell.Style(b.borderAttributes)
borderStyle = background.Foreground(b.borderColor)
}
if b.borderBlinking {
borderStyle = borderStyle.Blink(true)
}
var vertical, horizontal, topLeft, topRight, bottomLeft, bottomRight rune
horizontal = Borders.Horizontal
@ -424,19 +406,19 @@ func (b *Box) Draw(screen tcell.Screen) bool {
//Special case in order to render only the title-line of something properly.
if b.borderTop {
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, horizontal, nil, borderStyle)
}
if b.borderLeft {
screen.SetContent(b.x, b.y, topLeft, nil, border)
screen.SetContent(b.x, b.y, topLeft, nil, borderStyle)
} else {
screen.SetContent(b.x, b.y, horizontal, nil, border)
screen.SetContent(b.x, b.y, horizontal, nil, borderStyle)
}
if b.borderRight {
screen.SetContent(b.x+b.width-1, b.y, topRight, nil, border)
screen.SetContent(b.x+b.width-1, b.y, topRight, nil, borderStyle)
} else {
screen.SetContent(b.x+b.width-1, b.y, horizontal, nil, border)
screen.SetContent(b.x+b.width-1, b.y, horizontal, nil, borderStyle)
}
}
@ -444,62 +426,62 @@ func (b *Box) Draw(screen tcell.Screen) bool {
if b.height > 1 {
if b.borderBottom {
for x := b.x + 1; x < b.x+b.width-1; x++ {
screen.SetContent(x, b.y+b.height-1, horizontal, nil, border)
screen.SetContent(x, b.y+b.height-1, horizontal, nil, borderStyle)
}
if b.borderLeft {
screen.SetContent(b.x, b.y+b.height-1, bottomLeft, nil, border)
screen.SetContent(b.x, b.y+b.height-1, bottomLeft, nil, borderStyle)
} else {
screen.SetContent(b.x, b.y+b.height-1, horizontal, nil, border)
screen.SetContent(b.x, b.y+b.height-1, horizontal, nil, borderStyle)
}
if b.borderRight {
screen.SetContent(b.x+b.width-1, b.y+b.height-1, bottomRight, nil, border)
screen.SetContent(b.x+b.width-1, b.y+b.height-1, bottomRight, nil, borderStyle)
} else {
screen.SetContent(b.x+b.width-1, b.y+b.height-1, horizontal, nil, border)
screen.SetContent(b.x+b.width-1, b.y+b.height-1, horizontal, nil, borderStyle)
}
}
if b.borderLeft {
for y := b.y + 1; y < b.y+b.height-1; y++ {
screen.SetContent(b.x, y, vertical, nil, border)
screen.SetContent(b.x, y, vertical, nil, borderStyle)
}
if b.borderTop {
screen.SetContent(b.x, b.y, topLeft, nil, border)
screen.SetContent(b.x, b.y, topLeft, nil, borderStyle)
} else {
screen.SetContent(b.x, b.y, vertical, nil, border)
screen.SetContent(b.x, b.y, vertical, nil, borderStyle)
}
if b.borderBottom {
screen.SetContent(b.x, b.y+b.height-1, bottomLeft, nil, border)
screen.SetContent(b.x, b.y+b.height-1, bottomLeft, nil, borderStyle)
} else {
screen.SetContent(b.x, b.y+b.height-1, vertical, nil, border)
screen.SetContent(b.x, b.y+b.height-1, vertical, nil, borderStyle)
}
}
if b.borderRight {
for y := b.y + 1; y < b.y+b.height-1; y++ {
screen.SetContent(b.x+b.width-1, y, vertical, nil, border)
screen.SetContent(b.x+b.width-1, y, vertical, nil, borderStyle)
}
if b.borderTop {
screen.SetContent(b.x+b.width-1, b.y, topRight, nil, border)
screen.SetContent(b.x+b.width-1, b.y, topRight, nil, borderStyle)
} else {
screen.SetContent(b.x+b.width-1, b.y, vertical, nil, border)
screen.SetContent(b.x+b.width-1, b.y, vertical, nil, borderStyle)
}
if b.borderBottom {
screen.SetContent(b.x+b.width-1, b.y+b.height-1, bottomRight, nil, border)
screen.SetContent(b.x+b.width-1, b.y+b.height-1, bottomRight, nil, borderStyle)
} else {
screen.SetContent(b.x+b.width-1, b.y+b.height-1, vertical, nil, border)
screen.SetContent(b.x+b.width-1, b.y+b.height-1, vertical, nil, borderStyle)
}
}
} else if b.height == 1 && !b.borderTop && !b.borderBottom {
if b.borderLeft {
screen.SetContent(b.x, b.y, vertical, nil, border)
screen.SetContent(b.x, b.y, vertical, nil, borderStyle)
}
if b.borderRight {
screen.SetContent(b.x+b.width-1, b.y+b.height-1, vertical, nil, border)
screen.SetContent(b.x+b.width-1, b.y+b.height-1, vertical, nil, borderStyle)
}
}

View File

@ -1,7 +1,7 @@
package tview
import (
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// Button is labeled box that triggers an action when selected.

View File

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

View File

@ -2,14 +2,12 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/Bios-Marcel/cordless/tview"
)
func main() {
box := tview.NewBox().
SetBorder(true).
SetBorderAttributes(tcell.AttrBold).
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")
if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil {
panic(err)

View File

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

View File

@ -2,7 +2,7 @@ package main
import (
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
func main() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ import (
"fmt"
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// RadioButtons implements a simple primitive for radio button selections.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import (
"strings"
"unicode/utf8"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// InputField is a one-line box (three lines if there is a title) where the

View File

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

View File

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

View File

@ -1,6 +1,6 @@
package tview
import "github.com/gdamore/tcell"
import tcell "github.com/gdamore/tcell/v2"
// MouseSupport defines wether a component supports accepting mouse events
type MouseSupport interface {

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ package tview
import (
"sort"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
colorful "github.com/lucasb-eyer/go-colorful"
)
@ -247,10 +247,6 @@ type Table struct {
// The number of visible rows the last time the table was drawn.
visibleRows int
// The style of the selected rows. If this value is 0, selected rows are
// simply inverted.
selectedStyle tcell.Style
// An optional function which gets called when the user presses Enter on a
// selected cell. If entire rows selected, the column value is undefined.
// Likewise for entire columns.
@ -296,18 +292,6 @@ func (t *Table) SetBordersColor(color tcell.Color) *Table {
return t
}
// SetSelectedStyle sets a specific style for selected cells. If no such style
// is set, per default, selected cells are inverted (i.e. their foreground and
// background colors are swapped).
//
// 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)
return t
}
// SetSeparator sets the character used to fill the space between two
// neighboring cells. This is a space character ' ' per default but you may
// want to set it to Borders.Vertical (or any other rune) if the column
@ -804,7 +788,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))
if TaggedStringWidth(cell.Text)-printed > 0 && printed > 0 {
_, _, style, _ := screen.GetContent(x+columnX+1+finalWidth-1, y+rowY)
printWithStyle(screen, string(SemigraphicsHorizontalEllipsis), x+columnX+1+finalWidth-1, y+rowY, 1, AlignLeft, style)
@ -854,27 +838,14 @@ ColumnLoop:
for by := 0; by < h && fromY+by < y+height; by++ {
for bx := 0; bx < w && fromX+bx < x+width; bx++ {
m, c, style, _ := screen.GetContent(fromX+bx, fromY+by)
fg, bg, a := style.Decompose()
if invert {
if fg == textColor || fg == t.bordersColor {
fg = backgroundColor
}
if fg == tcell.ColorDefault {
fg = t.backgroundColor
}
style = style.Background(textColor).Foreground(fg)
} else {
if backgroundColor != tcell.ColorDefault {
bg = backgroundColor
}
if textColor != tcell.ColorDefault {
fg = textColor
}
if attr != 0 {
a = attr
}
style = style.Background(bg).Foreground(fg) | tcell.Style(a)
fg, bg, _ := style.Decompose()
if backgroundColor != tcell.ColorDefault {
bg = backgroundColor
}
if textColor != tcell.ColorDefault {
fg = textColor
}
style = style.Background(bg).Foreground(fg).Reverse(invert)
screen.SetContent(fromX+bx, fromY+by, m, c, style)
}
}
@ -931,16 +902,11 @@ ColumnLoop:
_, _, lj := c.Hcl()
return li < lj
})
selFg, selBg, selAttr := t.selectedStyle.Decompose()
for _, bgColor := range backgroundColors {
entries := cellsByBackgroundColor[bgColor]
for _, cell := range entries {
if cell.selected {
if t.selectedStyle != 0 {
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)
}
defer colorBackground(cell.x, cell.y, cell.w, cell.h, bgColor, cell.text, 0, true)
} else {
colorBackground(cell.x, cell.y, cell.w, cell.h, bgColor, tcell.ColorDefault, 0, false)
}

View File

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

View File

@ -5,7 +5,7 @@ import (
"strings"
"time"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// Tree navigation events.
@ -36,8 +36,9 @@ type TreeNode struct {
// The text color.
color tcell.Color
// The text attributes.
attr tcell.AttrMask
blinking bool
underline bool
// Whether or not this node can be selected.
selectable bool
@ -263,15 +264,12 @@ func (n *TreeNode) SetColor(color tcell.Color) *TreeNode {
return n
}
// GetAttributes gets the node's attributes.
func (n *TreeNode) GetAttributes() tcell.AttrMask {
return n.attr
func (n *TreeNode) SetUnderline(underline bool) {
n.underline = underline
}
// SetAttributes sets the node's attributes.
func (n *TreeNode) SetAttributes(attr tcell.AttrMask) *TreeNode {
n.attr = attr
return n
func (n *TreeNode) SetBlinking(blinking bool) {
n.blinking = blinking
}
// SetIndent sets an additional indentation for this node's text. A value of 0
@ -801,14 +799,20 @@ func (t *TreeView) Draw(screen tcell.Screen) bool {
// Text.
if node.textX+bulletCharacterWidth < width {
style := tcell.StyleDefault.Foreground(node.color) | tcell.Style(node.attr)
style := tcell.StyleDefault.Foreground(node.color)
if node == t.currentNode {
if IsVtxxx {
style = tcell.StyleDefault.Reverse(true)
} else {
style = tcell.StyleDefault.Background(node.color).Foreground(t.backgroundColor) | tcell.Style(node.attr)
style = tcell.StyleDefault.Background(node.color).Foreground(t.backgroundColor)
}
}
if node.blinking {
style = style.Blink(true)
}
if node.underline {
style = style.Underline(true)
}
var fullPrefix string
for _, prefix := range node.prefixes {
fullPrefix += prefix

View File

@ -7,7 +7,7 @@ import (
"sort"
"strconv"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
runewidth "github.com/mattn/go-runewidth"
"github.com/rivo/uniseg"
)

View File

@ -4,8 +4,6 @@ import (
"sort"
"sync"
"github.com/gdamore/tcell"
"github.com/Bios-Marcel/cordless/ui/tviewutil"
"github.com/Bios-Marcel/cordless/tview"
@ -295,7 +293,8 @@ func (channelTree *ChannelTree) MarkAsUnread(channelID string) {
func (channelTree *ChannelTree) markNodeAsUnread(node *tview.TreeNode) {
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrBlink)
node.SetBlinking(true)
node.SetUnderline(false)
} else {
node.SetColor(config.GetTheme().AttentionColor)
}
@ -312,7 +311,8 @@ func (channelTree *ChannelTree) MarkAsRead(channelID string) {
func (channelTree *ChannelTree) markNodeAsRead(node *tview.TreeNode) {
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrNone)
node.SetBlinking(false)
node.SetUnderline(false)
} else {
node.SetColor(config.GetTheme().PrimaryTextColor)
}
@ -371,7 +371,8 @@ func (channelTree *ChannelTree) MarkAsLoaded(channelID string) {
func (channelTree *ChannelTree) markNodeAsLoaded(node *tview.TreeNode) {
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrUnderline)
node.SetUnderline(true)
node.SetBlinking(false)
} else {
node.SetColor(tview.Styles.ContrastBackgroundColor)
}

View File

@ -4,7 +4,7 @@ import (
"testing"
"github.com/Bios-Marcel/discordgo"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
func TestChannelTree(t *testing.T) {

View File

@ -11,7 +11,7 @@ import (
"sync"
linkshortener "github.com/Bios-Marcel/shortnotforlong"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/Bios-Marcel/cordless/config"
"github.com/Bios-Marcel/cordless/discordutil"

View File

@ -4,7 +4,7 @@ import (
"strings"
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
const noHistoryIndexSelected = -1

View File

@ -1,11 +1,11 @@
package ui
package components
import (
"sync"
"github.com/Bios-Marcel/cordless/config"
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/mattn/go-runewidth"
"github.com/rivo/uniseg"
)

View File

@ -1,10 +1,10 @@
package ui
package components
import (
"strings"
"testing"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
func TestBottomBar(t *testing.T) {

View File

@ -4,7 +4,7 @@ import (
"github.com/Bios-Marcel/cordless/shortcuts"
"github.com/Bios-Marcel/cordless/tview"
"github.com/atotto/clipboard"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// PrompSecretSingleLineInput shows a fullscreen input dialog that masks the

View File

@ -5,7 +5,7 @@ import (
"github.com/Bios-Marcel/cordless/tview"
"github.com/atotto/clipboard"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/Bios-Marcel/cordless/config"
"github.com/Bios-Marcel/cordless/femto"
@ -599,16 +599,9 @@ func (editor *Editor) SetBorderColor(color tcell.Color) {
editor.internalTextView.SetBorderColor(color)
}
// SetBorderAttributes delegates to the underlying components SetBorderAttributes
// method.
func (editor *Editor) SetBorderAttributes(attr tcell.AttrMask) {
editor.internalTextView.SetBorderAttributes(attr)
}
// SetBorderFocusAttributes delegates to the underlying components SetBorderFocusAttributes
// method.
func (editor *Editor) SetBorderFocusAttributes(attr tcell.AttrMask) {
editor.internalTextView.SetBorderFocusAttributes(attr)
// SetBorderBlinking sets the blinking attribute of the border in tview.
func (editor *Editor) SetBorderBlinking(blinking bool) {
editor.internalTextView.SetBorderBlinking(blinking)
}
// SetInputCapture sets the alternative input capture that will be used if the

View File

@ -6,7 +6,6 @@ import (
"github.com/Bios-Marcel/cordless/readstate"
"github.com/Bios-Marcel/cordless/tview"
"github.com/Bios-Marcel/discordgo"
"github.com/gdamore/tcell"
"github.com/Bios-Marcel/cordless/config"
"github.com/Bios-Marcel/cordless/ui/tviewutil"
@ -77,14 +76,18 @@ func (g *GuildList) updateNodeState(guild *discordgo.Guild, node *tview.TreeNode
if loaded {
g.markNodeAsLoaded(node)
} else {
//Reset to avoid mistakes
if tview.IsVtxxx {
node.SetBlinking(false)
node.SetUnderline(false)
}
if !readstate.HasGuildBeenRead(guild.ID) {
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrBlink)
node.SetBlinking(true)
} else {
node.SetColor(config.GetTheme().AttentionColor)
}
} else {
node.SetAttributes(tcell.AttrNone)
node.SetColor(tview.Styles.PrimaryTextColor)
}
}
@ -164,9 +167,11 @@ func (g *GuildList) MarkAsLoaded(guildID string) {
}
func (g *GuildList) markNodeAsLoaded(node *tview.TreeNode) {
node.SetBlinking(false)
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrUnderline)
node.SetUnderline(true)
} else {
node.SetUnderline(false)
node.SetColor(tview.Styles.ContrastBackgroundColor)
}
}

View File

@ -8,7 +8,7 @@ import (
"github.com/Bios-Marcel/cordless/tview"
"github.com/Bios-Marcel/discordgo"
"github.com/atotto/clipboard"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/Bios-Marcel/cordless/ui/tviewutil"
"github.com/Bios-Marcel/cordless/util/text"

View File

@ -4,7 +4,7 @@ import (
"fmt"
"sort"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/Bios-Marcel/cordless/discordutil"
"github.com/Bios-Marcel/cordless/readstate"
@ -132,7 +132,7 @@ func (privateList *PrivateChatList) addChannel(channel *discordgo.Channel) {
if !readstate.HasBeenRead(channel, channel.LastMessageID) {
privateList.privateChannelStates[newNode] = unread
if tview.IsVtxxx {
newNode.SetAttributes(tcell.AttrBlink)
newNode.SetBlinking(true)
} else {
newNode.SetColor(config.GetTheme().AttentionColor)
}
@ -228,7 +228,7 @@ func (privateList *PrivateChatList) MarkAsUnread(channelID string) {
privateList.privateChannelStates[node] = unread
privateList.setNotificationCount(privateList.amountOfUnreadChannels())
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrBlink)
node.SetBlinking(true)
} else {
node.SetColor(config.GetTheme().AttentionColor)
}
@ -253,7 +253,8 @@ func (privateList *PrivateChatList) MarkAsRead(channelID string) {
privateList.setNotificationCount(privateList.amountOfUnreadChannels())
privateList.privateChannelStates[node] = read
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrNone)
node.SetBlinking(false)
node.SetUnderline(false)
} else {
node.SetColor(config.GetTheme().PrimaryTextColor)
}
@ -297,7 +298,8 @@ func (privateList *PrivateChatList) MarkAsLoaded(channelID string) {
if state == loaded {
privateList.privateChannelStates[node] = read
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrNone)
node.SetBlinking(false)
node.SetUnderline(false)
} else {
node.SetColor(config.GetTheme().PrimaryTextColor)
}
@ -309,8 +311,8 @@ func (privateList *PrivateChatList) MarkAsLoaded(channelID string) {
referenceChannelID, ok := node.GetReference().(string)
if ok && referenceChannelID == channelID {
privateList.privateChannelStates[node] = loaded
if tview.IsVtxxx {
node.SetAttributes(tcell.AttrUnderline)
if !tview.IsVtxxx {
node.SetUnderline(true)
} else {
node.SetColor(tview.Styles.ContrastBackgroundColor)
}

View File

@ -5,15 +5,13 @@ import (
"github.com/Bios-Marcel/cordless/shortcuts"
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
"github.com/Bios-Marcel/cordless/config"
"github.com/Bios-Marcel/cordless/ui/tviewutil"
"github.com/Bios-Marcel/cordless/ui/components"
tcell "github.com/gdamore/tcell/v2"
)
func ShowShortcutsDialog(app *tview.Application, onClose func()) {
var table *ShortcutTable
var shortcutDescription *tview.TextView
var shortcutDescription *components.BottomBar
var exitButton *tview.Button
var resetButton *tview.Button
@ -55,22 +53,14 @@ func ShowShortcutsDialog(app *tview.Application, onClose func()) {
return nil
})
primitiveBGColor := tviewutil.ColorToHex(config.GetTheme().PrimitiveBackgroundColor)
primaryTextColor := tviewutil.ColorToHex(config.GetTheme().PrimaryTextColor)
shortcutDescription = components.NewBottomBar()
shortcutDescription.SetBorderPadding(1, 0, 0, 0)
shortcutDescription.AddItem("R - Reset shortcut")
shortcutDescription.AddItem("Backspace - Delete shortcut")
shortcutDescription.AddItem("Enter - Change shortcut")
shortcutDescription.AddItem("ESC - Close dialog")
shortcutDescription = tview.NewTextView()
shortcutDescription.SetDynamicColors(true).SetBorderPadding(1, 0, 0, 0)
if tview.IsVtxxx {
shortcutDescription.SetText("R [::r]Reset shortcut[::-]" +
"[::-] Backspace [::r]Delete shortcut" +
"[::-] Enter [::r]Change shortcut" +
"[::-] Esc [::r]Close dialog")
} else {
shortcutDescription.SetText("[" + primaryTextColor + "][:" + primitiveBGColor + "]R [:" + primaryTextColor + "][" + primitiveBGColor + "]Reset shortcut" +
"[" + primaryTextColor + "][:" + primitiveBGColor + "] Backspace [:" + primaryTextColor + "][" + primitiveBGColor + "]Delete shortcut" +
"[" + primaryTextColor + "][:" + primitiveBGColor + "] Enter [:" + primaryTextColor + "][" + primitiveBGColor + "]Change shortcut" +
"[" + primaryTextColor + "][:" + primitiveBGColor + "] Esc [:" + primaryTextColor + "][" + primitiveBGColor + "]Close dialog")
}
table.SetFocusNext(func() { app.SetFocus(resetButton) })
table.SetFocusPrevious(func() { app.SetFocus(exitButton) })

View File

@ -6,7 +6,7 @@ import (
"github.com/Bios-Marcel/cordless/shortcuts"
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
const (
@ -35,9 +35,6 @@ func NewShortcutTable() *ShortcutTable {
table.SetSelectable(true, false)
table.SetBorder(true)
if tview.IsVtxxx {
table.SetSelectedStyle(tcell.ColorBlack, tcell.ColorWhite, tcell.AttrReverse)
}
//Header + emptyrow
table.SetFixed(2, 3)

View File

@ -3,7 +3,7 @@ package tviewutil
import (
"fmt"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
var (

View File

@ -3,7 +3,7 @@ package tviewutil
import (
"testing"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
func TestColorToHex(t *testing.T) {

View File

@ -2,7 +2,7 @@ package tviewutil
import (
"github.com/Bios-Marcel/cordless/tview"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
func CreateFocusTextViewOnTypeInputHandler(app *tview.Application, component *tview.TextView) func(event *tcell.EventKey) *tcell.EventKey {

View File

@ -10,7 +10,7 @@ import (
"github.com/Bios-Marcel/cordless/tview"
"github.com/Bios-Marcel/discordgo"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
)
// UserTree represents the visual list of users in a guild.

View File

@ -26,7 +26,7 @@ import (
"github.com/atotto/clipboard"
"github.com/Bios-Marcel/discordgo"
"github.com/gdamore/tcell"
tcell "github.com/gdamore/tcell/v2"
"github.com/gen2brain/beeep"
"github.com/Bios-Marcel/cordless/tview"
@ -38,6 +38,7 @@ import (
"github.com/Bios-Marcel/cordless/scripting"
"github.com/Bios-Marcel/cordless/scripting/js"
"github.com/Bios-Marcel/cordless/shortcuts"
"github.com/Bios-Marcel/cordless/ui/components"
"github.com/Bios-Marcel/cordless/ui/shortcutdialog"
"github.com/Bios-Marcel/cordless/ui/tviewutil"
"github.com/Bios-Marcel/cordless/util/maths"
@ -861,7 +862,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
window.rootContainer.AddItem(window.dialogReplacement, 2, 0, false)
if config.Current.ShowBottomBar {
bottomBar := NewBottomBar()
bottomBar := components.NewBottomBar()
bottomBar.AddItem(fmt.Sprintf("Logged in as: '%s'", tviewutil.Escape(session.State.User.Username)))
bottomBar.AddItem(fmt.Sprintf("View / Change shortcuts: %s", shortcutdialog.EventToString(shortcutsDialogShortcut)))
window.rootContainer.AddItem(bottomBar, 1, 0, false)
@ -2343,9 +2344,8 @@ func (window *Window) startEditingMessage(message *discordgo.Message) {
window.messageInput.SetText(message.Content)
window.messageInput.SetBorderColor(tcell.ColorYellow)
window.messageInput.SetBorderFocusColor(tcell.ColorYellow)
if tview.IsVtxxx {
window.messageInput.SetBorderFocusAttributes(tcell.AttrBlink | tcell.AttrBold)
}
//On Vtxxx the yellow color won't work, so we blink instead.
window.messageInput.SetBorderBlinking(tview.IsVtxxx)
window.editingMessageID = &message.ID
window.app.SetFocus(window.messageInput.GetPrimitive())
}
@ -2360,12 +2360,10 @@ func (window *Window) exitMessageEditMode() {
func (window *Window) exitMessageEditModeAndKeepText() {
window.editingMessageID = nil
//On Vtxxx the yellow color won't work, so we blink instead.
window.messageInput.SetBorderBlinking(false)
window.messageInput.SetBorderColor(tview.Styles.BorderColor)
window.messageInput.SetBorderFocusColor(tview.Styles.BorderFocusColor)
if tview.IsVtxxx {
window.messageInput.SetBorderFocusAttributes(tcell.AttrBold)
window.messageInput.SetBorderAttributes(tcell.AttrNone)
}
}
// ShowErrorDialog shows a simple error dialog that has only an Okay button,