build: upgrade tview to latest
This commit is contained in:
parent
0243039600
commit
4a77d7cbd5
6 changed files with 43 additions and 38 deletions
|
|
@ -12,6 +12,12 @@ import (
|
|||
"github.com/zalando/go-keyring"
|
||||
)
|
||||
|
||||
const (
|
||||
flexPageName = "flex"
|
||||
mentionsListPageName = "mentionsList"
|
||||
attachmentsListPageName = "attachmentsList"
|
||||
)
|
||||
|
||||
type application struct {
|
||||
cfg *config.Config
|
||||
|
||||
|
|
@ -21,9 +27,6 @@ type application struct {
|
|||
guildsTree *guildsTree
|
||||
messagesText *messagesText
|
||||
messageInput *messageInput
|
||||
|
||||
flexPage int
|
||||
autocompletePage int
|
||||
}
|
||||
|
||||
func newApplication(cfg *config.Config) *application {
|
||||
|
|
@ -89,18 +92,20 @@ func (a *application) quit() {
|
|||
}
|
||||
|
||||
func (a *application) init() {
|
||||
a.pages.Clear()
|
||||
a.pages.ClearPages()
|
||||
a.flex.Clear()
|
||||
|
||||
right := tview.NewFlex()
|
||||
right.SetDirection(tview.FlexRow)
|
||||
right.AddItem(a.messagesText, 0, 1, false)
|
||||
right.AddItem(a.messageInput, 3, 1, false)
|
||||
right := tview.NewFlex().
|
||||
SetDirection(tview.FlexRow).
|
||||
AddItem(a.messagesText, 0, 1, false).
|
||||
AddItem(a.messageInput, 3, 1, false)
|
||||
// The guilds tree is always focused first at start-up.
|
||||
a.flex.AddItem(a.guildsTree, 0, 1, true)
|
||||
a.flex.AddItem(right, 0, 4, false)
|
||||
a.flexPage = a.pages.AddAndSwitchToPage(a.flex, true)
|
||||
a.autocompletePage = a.pages.AddPage(a.messageInput.autocomplete, false, false)
|
||||
a.flex.
|
||||
AddItem(a.guildsTree, 0, 1, true).
|
||||
AddItem(right, 0, 4, false)
|
||||
a.pages.
|
||||
AddAndSwitchToPage(flexPageName, a.flex, true).
|
||||
AddPage(mentionsListPageName, a.messageInput.autocomplete, false, false)
|
||||
}
|
||||
|
||||
func (a *application) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
||||
|
|
@ -119,11 +124,11 @@ func (a *application) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
|||
func (a *application) onFlexInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch event.Name() {
|
||||
case a.cfg.Keys.FocusGuildsTree:
|
||||
a.pages.HidePage(a.autocompletePage)
|
||||
a.pages.HidePage(mentionsListPageName)
|
||||
a.SetFocus(app.guildsTree)
|
||||
return nil
|
||||
case a.cfg.Keys.FocusMessagesText:
|
||||
a.pages.HidePage(a.autocompletePage)
|
||||
a.pages.HidePage(mentionsListPageName)
|
||||
a.SetFocus(app.messagesText)
|
||||
return nil
|
||||
case a.cfg.Keys.FocusMessageInput:
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func (mi *messageInput) reset() {
|
|||
func (mi *messageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch event.Name() {
|
||||
case mi.cfg.Keys.MessageInput.Send:
|
||||
if app.pages.GetVisible(app.autocompletePage) {
|
||||
if app.pages.GetVisibile(mentionsListPageName) {
|
||||
mi.tabComplete(false)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ func (mi *messageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
|||
mi.editor()
|
||||
return nil
|
||||
case mi.cfg.Keys.MessageInput.Cancel:
|
||||
if app.pages.GetVisible(app.autocompletePage) {
|
||||
if app.pages.GetVisibile(mentionsListPageName) {
|
||||
mi.stopTabCompletion()
|
||||
} else {
|
||||
mi.reset()
|
||||
|
|
@ -107,7 +107,7 @@ func (mi *messageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
|||
}
|
||||
|
||||
if mi.cfg.AutocompleteLimit > 0 {
|
||||
if app.pages.GetVisible(app.autocompletePage) {
|
||||
if app.pages.GetVisibile(mentionsListPageName) {
|
||||
count := mi.autocomplete.GetItemCount()
|
||||
cur := mi.autocomplete.GetCurrentItem()
|
||||
switch event.Name() {
|
||||
|
|
@ -371,7 +371,7 @@ func (mi *messageInput) showMentionList(col int) {
|
|||
x += min(col, maxW-w)
|
||||
}
|
||||
l.SetRect(x, y, w, h)
|
||||
app.pages.ShowPage(app.autocompletePage)
|
||||
app.pages.ShowPage(mentionsListPageName)
|
||||
app.SetFocus(mi)
|
||||
}
|
||||
|
||||
|
|
@ -416,7 +416,7 @@ func (mi *messageInput) addAutocompleteItem(gID discord.GuildID, m *discord.Memb
|
|||
|
||||
func (mi *messageInput) stopTabCompletion() {
|
||||
if mi.cfg.AutocompleteLimit > 0 {
|
||||
app.pages.HidePage(app.autocompletePage)
|
||||
app.pages.HidePage(mentionsListPageName)
|
||||
mi.autocomplete.Clear()
|
||||
app.SetFocus(mi)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ type messagesText struct {
|
|||
count uint
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
urlListPage int
|
||||
}
|
||||
|
||||
func newMessagesText(cfg *config.Config) *messagesText {
|
||||
|
|
@ -447,7 +445,7 @@ func extractURLs(content string) []string {
|
|||
|
||||
func (mt *messagesText) showUrlSelector(urls []string, attachments []discord.Attachment) {
|
||||
done := func() {
|
||||
app.pages.RemovePage(mt.urlListPage).SwitchToPage(app.flexPage)
|
||||
app.pages.RemovePage(attachmentsListPageName).SwitchToPage(flexPageName)
|
||||
app.SetFocus(mt)
|
||||
}
|
||||
|
||||
|
|
@ -486,8 +484,9 @@ func (mt *messagesText) showUrlSelector(urls []string, attachments []discord.Att
|
|||
})
|
||||
}
|
||||
|
||||
mt.urlListPage = app.pages.AddAndSwitchToPage(ui.Centered(list, 0, 0), true)
|
||||
app.pages.ShowPage(app.flexPage)
|
||||
app.pages.
|
||||
AddAndSwitchToPage(attachmentsListPageName, ui.Centered(list, 0, 0), true).
|
||||
ShowPage(flexPageName)
|
||||
}
|
||||
|
||||
func openURL(url string) {
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -5,7 +5,7 @@ go 1.24.3
|
|||
require (
|
||||
github.com/BurntSushi/toml v1.5.0
|
||||
github.com/atotto/clipboard v0.1.4
|
||||
github.com/ayn2op/tview v0.0.0-20250615214508-b6d99d0bd2e0
|
||||
github.com/ayn2op/tview v0.0.0-20250618224732-91a1a2f06994
|
||||
github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb
|
||||
github.com/diamondburned/arikawa/v3 v3.5.0
|
||||
github.com/diamondburned/ningen/v3 v3.0.1-0.20250607192146-d6b46a4689a5
|
||||
|
|
|
|||
8
go.sum
8
go.sum
|
|
@ -25,10 +25,8 @@ github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2
|
|||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/ayn2op/tview v0.0.0-20250615213508-2719974b344b h1:rTaFMJVkVySIJtIJnbE0fT7IcyhNBajPvNVGLAJ3kk4=
|
||||
github.com/ayn2op/tview v0.0.0-20250615213508-2719974b344b/go.mod h1:PuMMP3J7SfW0jgAc1fdABOHJkoGbQIw3jejRAkl0API=
|
||||
github.com/ayn2op/tview v0.0.0-20250615214508-b6d99d0bd2e0 h1:gmy5w73yKtOeFxSiFP1pERlOVi+9mwA4WIIgg96qzXg=
|
||||
github.com/ayn2op/tview v0.0.0-20250615214508-b6d99d0bd2e0/go.mod h1:PuMMP3J7SfW0jgAc1fdABOHJkoGbQIw3jejRAkl0API=
|
||||
github.com/ayn2op/tview v0.0.0-20250618224732-91a1a2f06994 h1:heK43Ba0uvQPH2BgJVFiB2G8vIJk1XocvFYCPfOSNhU=
|
||||
github.com/ayn2op/tview v0.0.0-20250618224732-91a1a2f06994/go.mod h1:PuMMP3J7SfW0jgAc1fdABOHJkoGbQIw3jejRAkl0API=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
|
|
@ -54,8 +52,6 @@ github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uh
|
|||
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
|
||||
github.com/gdamore/tcell/v2 v2.8.1 h1:KPNxyqclpWpWQlPLx6Xui1pMk8S+7+R37h3g07997NU=
|
||||
github.com/gdamore/tcell/v2 v2.8.1/go.mod h1:bj8ori1BG3OYMjmb3IklZVWfZUJ1UBQt9JXrOCOhGWw=
|
||||
github.com/gen2brain/beeep v0.11.0 h1:ScADjlllAwqUIdEgosHXRmS0OEBTDtfGvIuLj2G/mlU=
|
||||
github.com/gen2brain/beeep v0.11.0/go.mod h1:jQVvuwnLuwOcdctHn/uyh8horSBNJ8uGb9Cn2W4tvoc=
|
||||
github.com/gen2brain/beeep v0.11.1 h1:EbSIhrQZFDj1K2fzlMpAYlFOzV8YuNe721A58XcCTYI=
|
||||
github.com/gen2brain/beeep v0.11.1/go.mod h1:jQVvuwnLuwOcdctHn/uyh8horSBNJ8uGb9Cn2W4tvoc=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ import (
|
|||
"github.com/zalando/go-keyring"
|
||||
)
|
||||
|
||||
const (
|
||||
formPageName = "form"
|
||||
errorPageName = "error"
|
||||
)
|
||||
|
||||
type DoneFn = func(token string)
|
||||
|
||||
type Form struct {
|
||||
|
|
@ -19,9 +24,6 @@ type Form struct {
|
|||
cfg *config.Config
|
||||
form *tview.Form
|
||||
done DoneFn
|
||||
|
||||
formPage int
|
||||
errPage int
|
||||
}
|
||||
|
||||
func NewForm(cfg *config.Config, done DoneFn) *Form {
|
||||
|
|
@ -37,7 +39,7 @@ func NewForm(cfg *config.Config, done DoneFn) *Form {
|
|||
AddPasswordField("Password", "", 0, 0, nil).
|
||||
AddPasswordField("Code (optional)", "", 0, 0, nil).
|
||||
AddButton("Login", f.login)
|
||||
f.formPage = f.AddAndSwitchToPage(f.form, true)
|
||||
f.AddAndSwitchToPage(formPageName, f.form, true)
|
||||
return f
|
||||
}
|
||||
|
||||
|
|
@ -93,8 +95,11 @@ func (f *Form) onError(err error) {
|
|||
SetText(err.Error()).
|
||||
AddButtons([]string{"Close"}).
|
||||
SetDoneFunc(func(_ int, _ string) {
|
||||
f.RemovePage(f.errPage).SwitchToPage(f.formPage)
|
||||
f.
|
||||
RemovePage(errorPageName).
|
||||
SwitchToPage(formPageName)
|
||||
})
|
||||
f.errPage = f.AddAndSwitchToPage(ui.Centered(modal, 0, 0), true)
|
||||
f.ShowPage(f.formPage)
|
||||
f.
|
||||
AddAndSwitchToPage(errorPageName, ui.Centered(modal, 0, 0), true).
|
||||
ShowPage(formPageName)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue