From 52ee681981b215fee5579d1fd7fc79f86a034fa0 Mon Sep 17 00:00:00 2001 From: Marcel Schramm Date: Sat, 24 Oct 2020 13:22:48 +0200 Subject: [PATCH] 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.+) --- config/theme.go | 2 +- femto/cellview.go | 2 +- femto/colorscheme.go | 2 +- go.mod | 2 +- go.sum | 4 +- shortcuts/shortcuts.go | 2 +- tools/keyevents/main.go | 2 +- tools/layout/main.go | 2 +- tools/theme/theme.go | 2 +- tview/application.go | 2 +- tview/box.go | 90 +++++++++++--------------- tview/button.go | 2 +- tview/checkbox.go | 2 +- tview/demos/box/main.go | 2 - tview/demos/frame/main.go | 2 +- tview/demos/inputfield-paste/main.go | 2 +- tview/demos/inputfield/main.go | 2 +- tview/demos/modal/main.go | 2 +- tview/demos/presentation/colors.go | 2 +- tview/demos/presentation/cover.go | 2 +- tview/demos/presentation/end.go | 2 +- tview/demos/presentation/flex.go | 2 +- tview/demos/presentation/grid.go | 2 +- tview/demos/presentation/helloworld.go | 2 +- tview/demos/presentation/inputfield.go | 4 +- tview/demos/presentation/main.go | 2 +- tview/demos/presentation/table.go | 2 +- tview/demos/presentation/textview.go | 4 +- tview/demos/presentation/treeview.go | 2 +- tview/demos/primitive/main.go | 2 +- tview/demos/table/main.go | 2 +- tview/demos/textview/main.go | 2 +- tview/demos/treeview/main.go | 2 +- tview/dropdown.go | 2 +- tview/flex.go | 2 +- tview/form.go | 2 +- tview/frame.go | 2 +- tview/grid.go | 2 +- tview/inputfield.go | 2 +- tview/list.go | 2 +- tview/modal.go | 2 +- tview/mousesupport.go | 2 +- tview/pages.go | 2 +- tview/primitive.go | 2 +- tview/semigraphics.go | 2 +- tview/styles.go | 2 +- tview/table.go | 54 +++------------- tview/textview.go | 2 +- tview/treeview.go | 28 ++++---- tview/util.go | 2 +- ui/channeltree.go | 11 ++-- ui/channeltree_test.go | 2 +- ui/chatview.go | 2 +- ui/commandview.go | 2 +- ui/{ => components}/bottombar.go | 4 +- ui/{ => components}/bottombar_test.go | 4 +- ui/dialogs.go | 2 +- ui/editor.go | 15 ++--- ui/guildlist.go | 13 ++-- ui/login.go | 2 +- ui/privatechats.go | 16 +++-- ui/shortcutdialog/dialog.go | 30 +++------ ui/shortcutdialog/table.go | 5 +- ui/tviewutil/color.go | 2 +- ui/tviewutil/color_test.go | 2 +- ui/tviewutil/treeview.go | 2 +- ui/usertree.go | 2 +- ui/window.go | 16 ++--- 68 files changed, 170 insertions(+), 234 deletions(-) rename ui/{ => components}/bottombar.go (97%) rename ui/{ => components}/bottombar_test.go (95%) diff --git a/config/theme.go b/config/theme.go index ee8d008..941bad5 100644 --- a/config/theme.go +++ b/config/theme.go @@ -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 diff --git a/femto/cellview.go b/femto/cellview.go index 6d5d8e2..2ed0137 100644 --- a/femto/cellview.go +++ b/femto/cellview.go @@ -1,7 +1,7 @@ package femto import ( - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/mattn/go-runewidth" ) diff --git a/femto/colorscheme.go b/femto/colorscheme.go index 93ab4a3..2060289 100644 --- a/femto/colorscheme.go +++ b/femto/colorscheme.go @@ -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 diff --git a/go.mod b/go.mod index 56a7306..0c0ffaf 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b3d1d4c..30c3ad4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/shortcuts/shortcuts.go b/shortcuts/shortcuts.go index cd0b4d3..ac9ef65 100644 --- a/shortcuts/shortcuts.go +++ b/shortcuts/shortcuts.go @@ -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" diff --git a/tools/keyevents/main.go b/tools/keyevents/main.go index fd4db41..bfb658d 100644 --- a/tools/keyevents/main.go +++ b/tools/keyevents/main.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/Bios-Marcel/cordless/tview" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" ) func main() { diff --git a/tools/layout/main.go b/tools/layout/main.go index 605cdb0..de3fa0e 100644 --- a/tools/layout/main.go +++ b/tools/layout/main.go @@ -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() { diff --git a/tools/theme/theme.go b/tools/theme/theme.go index 677db9e..1e2d98c 100644 --- a/tools/theme/theme.go +++ b/tools/theme/theme.go @@ -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" ) diff --git a/tview/application.go b/tview/application.go index 1359dde..873d736 100644 --- a/tview/application.go +++ b/tview/application.go @@ -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. diff --git a/tview/box.go b/tview/box.go index 4ee3d96..cdb2360 100644 --- a/tview/box.go +++ b/tview/box.go @@ -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) } } diff --git a/tview/button.go b/tview/button.go index 54e841a..dc91bc1 100644 --- a/tview/button.go +++ b/tview/button.go @@ -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. diff --git a/tview/checkbox.go b/tview/checkbox.go index f19dc48..3974c85 100644 --- a/tview/checkbox.go +++ b/tview/checkbox.go @@ -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 diff --git a/tview/demos/box/main.go b/tview/demos/box/main.go index c81b9f0..d19f8bf 100644 --- a/tview/demos/box/main.go +++ b/tview/demos/box/main.go @@ -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) diff --git a/tview/demos/frame/main.go b/tview/demos/frame/main.go index 6dea366..f603743 100644 --- a/tview/demos/frame/main.go +++ b/tview/demos/frame/main.go @@ -2,7 +2,7 @@ package main import ( - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/inputfield-paste/main.go b/tview/demos/inputfield-paste/main.go index 65057f8..e911676 100644 --- a/tview/demos/inputfield-paste/main.go +++ b/tview/demos/inputfield-paste/main.go @@ -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() { diff --git a/tview/demos/inputfield/main.go b/tview/demos/inputfield/main.go index 7015f04..3eecd04 100644 --- a/tview/demos/inputfield/main.go +++ b/tview/demos/inputfield/main.go @@ -2,7 +2,7 @@ package main import ( - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/modal/main.go b/tview/demos/modal/main.go index fc8a27d..0eb61a3 100644 --- a/tview/demos/modal/main.go +++ b/tview/demos/modal/main.go @@ -4,7 +4,7 @@ package main import ( "strings" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/colors.go b/tview/demos/presentation/colors.go index 6ea7b40..2aa7005 100644 --- a/tview/demos/presentation/colors.go +++ b/tview/demos/presentation/colors.go @@ -3,7 +3,7 @@ package main import ( "strings" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/cover.go b/tview/demos/presentation/cover.go index 315561d..e8a59e7 100644 --- a/tview/demos/presentation/cover.go +++ b/tview/demos/presentation/cover.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/end.go b/tview/demos/presentation/end.go index b033ca9..7fb9b60 100644 --- a/tview/demos/presentation/end.go +++ b/tview/demos/presentation/end.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/flex.go b/tview/demos/presentation/flex.go index 7285354..2118d61 100644 --- a/tview/demos/presentation/flex.go +++ b/tview/demos/presentation/flex.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/grid.go b/tview/demos/presentation/grid.go index 26b0c49..9c15532 100644 --- a/tview/demos/presentation/grid.go +++ b/tview/demos/presentation/grid.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/helloworld.go b/tview/demos/presentation/helloworld.go index 7383941..764cada 100644 --- a/tview/demos/presentation/helloworld.go +++ b/tview/demos/presentation/helloworld.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/inputfield.go b/tview/demos/presentation/inputfield.go index aa770f9..ee25caa 100644 --- a/tview/demos/presentation/inputfield.go +++ b/tview/demos/presentation/inputfield.go @@ -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] ) diff --git a/tview/demos/presentation/main.go b/tview/demos/presentation/main.go index b91f8cb..a23c571 100644 --- a/tview/demos/presentation/main.go +++ b/tview/demos/presentation/main.go @@ -16,7 +16,7 @@ import ( "fmt" "strconv" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/table.go b/tview/demos/presentation/table.go index 58f9644..5c0ab57 100644 --- a/tview/demos/presentation/table.go +++ b/tview/demos/presentation/table.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/presentation/textview.go b/tview/demos/presentation/textview.go index 8e62299..507eb2f 100644 --- a/tview/demos/presentation/textview.go +++ b/tview/demos/presentation/textview.go @@ -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] ) diff --git a/tview/demos/presentation/treeview.go b/tview/demos/presentation/treeview.go index 6ae7265..145b590 100644 --- a/tview/demos/presentation/treeview.go +++ b/tview/demos/presentation/treeview.go @@ -3,7 +3,7 @@ package main import ( "strings" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/primitive/main.go b/tview/demos/primitive/main.go index fded359..6c6da87 100644 --- a/tview/demos/primitive/main.go +++ b/tview/demos/primitive/main.go @@ -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. diff --git a/tview/demos/table/main.go b/tview/demos/table/main.go index 2af7f71..3910eeb 100644 --- a/tview/demos/table/main.go +++ b/tview/demos/table/main.go @@ -4,7 +4,7 @@ package main import ( "strings" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/textview/main.go b/tview/demos/textview/main.go index 7eb9763..226323b 100644 --- a/tview/demos/textview/main.go +++ b/tview/demos/textview/main.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" "github.com/Bios-Marcel/cordless/tview" ) diff --git a/tview/demos/treeview/main.go b/tview/demos/treeview/main.go index 8877771..14995aa 100644 --- a/tview/demos/treeview/main.go +++ b/tview/demos/treeview/main.go @@ -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" ) diff --git a/tview/dropdown.go b/tview/dropdown.go index 2120c9e..8427611 100644 --- a/tview/dropdown.go +++ b/tview/dropdown.go @@ -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. diff --git a/tview/flex.go b/tview/flex.go index 0a20b39..c83a29a 100644 --- a/tview/flex.go +++ b/tview/flex.go @@ -1,7 +1,7 @@ package tview import ( - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" ) // Configuration values. diff --git a/tview/form.go b/tview/form.go index 8ba2b2d..1fcc46e 100644 --- a/tview/form.go +++ b/tview/form.go @@ -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 diff --git a/tview/frame.go b/tview/frame.go index 8f98bf3..6057a46 100644 --- a/tview/frame.go +++ b/tview/frame.go @@ -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. diff --git a/tview/grid.go b/tview/grid.go index f525511..649c8cb 100644 --- a/tview/grid.go +++ b/tview/grid.go @@ -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. diff --git a/tview/inputfield.go b/tview/inputfield.go index 2c5722e..7fd0beb 100644 --- a/tview/inputfield.go +++ b/tview/inputfield.go @@ -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 diff --git a/tview/list.go b/tview/list.go index ad5dad5..42f5730 100644 --- a/tview/list.go +++ b/tview/list.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" ) // listItem represents one item in a List. diff --git a/tview/modal.go b/tview/modal.go index 764f7f0..cc0817b 100644 --- a/tview/modal.go +++ b/tview/modal.go @@ -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 diff --git a/tview/mousesupport.go b/tview/mousesupport.go index 5effbae..8a1c621 100644 --- a/tview/mousesupport.go +++ b/tview/mousesupport.go @@ -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 { diff --git a/tview/pages.go b/tview/pages.go index 10354d2..168d5f4 100644 --- a/tview/pages.go +++ b/tview/pages.go @@ -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. diff --git a/tview/primitive.go b/tview/primitive.go index f559c21..ef54225 100644 --- a/tview/primitive.go +++ b/tview/primitive.go @@ -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 { diff --git a/tview/semigraphics.go b/tview/semigraphics.go index 3b66c5f..bf5ba4e 100644 --- a/tview/semigraphics.go +++ b/tview/semigraphics.go @@ -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. // diff --git a/tview/styles.go b/tview/styles.go index 4be4e97..bf895e1 100644 --- a/tview/styles.go +++ b/tview/styles.go @@ -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 { diff --git a/tview/table.go b/tview/table.go index b67fc84..ee77823 100644 --- a/tview/table.go +++ b/tview/table.go @@ -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) } diff --git a/tview/textview.go b/tview/textview.go index cc5ce1e..9a875a2 100644 --- a/tview/textview.go +++ b/tview/textview.go @@ -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" ) diff --git a/tview/treeview.go b/tview/treeview.go index 9a45842..51c4b35 100644 --- a/tview/treeview.go +++ b/tview/treeview.go @@ -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 diff --git a/tview/util.go b/tview/util.go index 25111a9..bb95ae1 100644 --- a/tview/util.go +++ b/tview/util.go @@ -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" ) diff --git a/ui/channeltree.go b/ui/channeltree.go index 583a9c2..f99ab6b 100644 --- a/ui/channeltree.go +++ b/ui/channeltree.go @@ -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) } diff --git a/ui/channeltree_test.go b/ui/channeltree_test.go index c3b6ed8..734b15c 100644 --- a/ui/channeltree_test.go +++ b/ui/channeltree_test.go @@ -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) { diff --git a/ui/chatview.go b/ui/chatview.go index 478cbd3..e4a3ac9 100644 --- a/ui/chatview.go +++ b/ui/chatview.go @@ -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" diff --git a/ui/commandview.go b/ui/commandview.go index 0eed9b0..8269bb8 100644 --- a/ui/commandview.go +++ b/ui/commandview.go @@ -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 diff --git a/ui/bottombar.go b/ui/components/bottombar.go similarity index 97% rename from ui/bottombar.go rename to ui/components/bottombar.go index 28c2ed8..e65c07a 100644 --- a/ui/bottombar.go +++ b/ui/components/bottombar.go @@ -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" ) diff --git a/ui/bottombar_test.go b/ui/components/bottombar_test.go similarity index 95% rename from ui/bottombar_test.go rename to ui/components/bottombar_test.go index e612453..3ef44e0 100644 --- a/ui/bottombar_test.go +++ b/ui/components/bottombar_test.go @@ -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) { diff --git a/ui/dialogs.go b/ui/dialogs.go index 7bd04f6..78a5fe6 100644 --- a/ui/dialogs.go +++ b/ui/dialogs.go @@ -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 diff --git a/ui/editor.go b/ui/editor.go index e7bdc03..f4ff3f7 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -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 diff --git a/ui/guildlist.go b/ui/guildlist.go index bf4a2bf..49772de 100644 --- a/ui/guildlist.go +++ b/ui/guildlist.go @@ -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) } } diff --git a/ui/login.go b/ui/login.go index fdf2c58..b7e9129 100644 --- a/ui/login.go +++ b/ui/login.go @@ -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" diff --git a/ui/privatechats.go b/ui/privatechats.go index c53e633..ed938a4 100644 --- a/ui/privatechats.go +++ b/ui/privatechats.go @@ -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) } diff --git a/ui/shortcutdialog/dialog.go b/ui/shortcutdialog/dialog.go index f8925ba..1b0ab01 100644 --- a/ui/shortcutdialog/dialog.go +++ b/ui/shortcutdialog/dialog.go @@ -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) }) diff --git a/ui/shortcutdialog/table.go b/ui/shortcutdialog/table.go index baeab78..fffd592 100644 --- a/ui/shortcutdialog/table.go +++ b/ui/shortcutdialog/table.go @@ -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) diff --git a/ui/tviewutil/color.go b/ui/tviewutil/color.go index 4d983e9..d399933 100644 --- a/ui/tviewutil/color.go +++ b/ui/tviewutil/color.go @@ -3,7 +3,7 @@ package tviewutil import ( "fmt" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" ) var ( diff --git a/ui/tviewutil/color_test.go b/ui/tviewutil/color_test.go index aa9c0e6..90b7b4e 100644 --- a/ui/tviewutil/color_test.go +++ b/ui/tviewutil/color_test.go @@ -3,7 +3,7 @@ package tviewutil import ( "testing" - "github.com/gdamore/tcell" + tcell "github.com/gdamore/tcell/v2" ) func TestColorToHex(t *testing.T) { diff --git a/ui/tviewutil/treeview.go b/ui/tviewutil/treeview.go index ef7faa7..640b4d1 100644 --- a/ui/tviewutil/treeview.go +++ b/ui/tviewutil/treeview.go @@ -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 { diff --git a/ui/usertree.go b/ui/usertree.go index 0c6ad3e..562eeff 100644 --- a/ui/usertree.go +++ b/ui/usertree.go @@ -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. diff --git a/ui/window.go b/ui/window.go index bb40091..ed82312 100644 --- a/ui/window.go +++ b/ui/window.go @@ -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,