Browse Source

Use `phony.Inbox` instead of `update chan bool`

pull/288/head
iacore 5 months ago
parent
commit
be5bf17592
No known key found for this signature in database
  1. 1
      go.mod
  2. 2
      go.sum
  3. 6
      ui/commands.go
  4. 26
      ui/mainview.go
  5. 14
      ui/timeline.go
  6. 12
      ui/tutview.go

1
go.mod

@ -3,6 +3,7 @@ module github.com/RasmusLindroth/tut
go 1.18
require (
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d
github.com/RasmusLindroth/go-mastodon v0.0.21
github.com/adrg/xdg v0.4.0
github.com/atotto/clipboard v0.1.4

2
go.sum

@ -1,3 +1,5 @@
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d h1:UK9fsWbWqwIQkMCz1CP+v5pGbsGoWAw6g4AyvMpm1EM=
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q=
github.com/RasmusLindroth/go-mastodon v0.0.21 h1:ETr7xxrjQKbGvPlcI9hW7Or/pH2gLTZ6R/IBkQ1vwws=
github.com/RasmusLindroth/go-mastodon v0.0.21/go.mod h1:Lr6n8V1U2b+9P89YZKsICkNc+oNeJXkygY7raei9SXE=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=

6
ui/commands.go

@ -302,12 +302,12 @@ func (tv *TutView) PreferencesCommand() {
func (tv *TutView) ListPlacementCommand(lp config.ListPlacement) {
tv.tut.Config.General.ListPlacement = lp
tv.MainView.ForceUpdate()
tv.MainView.be_ForceUpdate(tv)
}
func (tv *TutView) ListSplitCommand(ls config.ListSplit) {
tv.tut.Config.General.ListSplit = ls
tv.MainView.ForceUpdate()
tv.MainView.be_ForceUpdate(tv)
}
func (tv *TutView) ProportionsCommand(lp string, cp string) {
@ -323,7 +323,7 @@ func (tv *TutView) ProportionsCommand(lp string, cp string) {
}
tv.tut.Config.General.ListProportion = lpi
tv.tut.Config.General.ContentProportion = cpi
tv.MainView.ForceUpdate()
tv.MainView.be_ForceUpdate(tv)
}
func (tv *TutView) LoadNewerCommand() {

26
ui/mainview.go

@ -3,35 +3,35 @@ package ui
import (
"fmt"
"github.com/Arceliar/phony"
"github.com/RasmusLindroth/tut/config"
"github.com/rivo/tview"
)
type MainView struct {
phony.Inbox
tv *TutView
View *tview.Flex
accView *tview.Flex
update chan bool
}
func NewMainView(tv *TutView, update chan bool) *MainView {
func NewMainView(tv *TutView) *MainView {
mv := &MainView{
update: update,
tv: tv,
accView: NewControlView(tv.tut.Config),
}
mv.View = mv.mainViewUI(tv)
go func() {
for range mv.update {
tv.tut.App.QueueUpdateDraw(func() {
*tv.MainView.View = *mv.mainViewUI(tv)
tv.ShouldSync()
})
}
}()
return mv
}
func (mv *MainView) ForceUpdate() {
mv.update <- true
func (mv *MainView) be_ForceUpdate(from phony.Actor) {
mv.Act(from, func() {
tv := mv.tv
tv.tut.App.QueueUpdateDraw(func() {
tv.MainView.View = mv.mainViewUI(tv)
tv.ShouldSync()
})
})
}
func feedList(mv *TutView, fh *FeedHolder) *tview.Flex {

14
ui/timeline.go

@ -16,7 +16,6 @@ type Timeline struct {
tutView *TutView
Feeds []*FeedHolder
FeedFocusIndex int
update chan bool
scrollSleep *scrollSleep
}
@ -68,11 +67,10 @@ func CreateFeed(tv *TutView, f *config.Timeline) *Feed {
return nf
}
func NewTimeline(tv *TutView, update chan bool) *Timeline {
func NewTimeline(tv *TutView) *Timeline {
tl := &Timeline{
tutView: tv,
Feeds: []*FeedHolder{},
update: update,
}
tl.scrollSleep = NewScrollSleep(tl.NextItemFeed, tl.PrevItemFeed)
for _, f := range tv.tut.Config.General.Timelines {
@ -163,7 +161,7 @@ func (tl *Timeline) AddFeed(f *Feed, newPane bool) {
fh.FeedIndex = fh.FeedIndex + 1
}
tl.tutView.Shared.Top.SetText(tl.GetTitle())
tl.update <- true
tl.tutView.MainView.be_ForceUpdate(tl.tutView)
}
func (tl *Timeline) RemoveCurrent(quit bool) bool {
@ -184,7 +182,7 @@ func (tl *Timeline) RemoveCurrent(quit bool) bool {
}
f.FeedIndex = ni
tl.tutView.Shared.Top.SetText(tl.GetTitle())
tl.update <- true
tl.tutView.MainView.be_ForceUpdate(tl.tutView)
return false
}
@ -259,7 +257,7 @@ func (tl *Timeline) NextFeed() {
}
f.FeedIndex = ni
tl.tutView.Shared.Top.SetText(tl.GetTitle())
tl.update <- true
tl.tutView.MainView.be_ForceUpdate(tl.tutView)
}
func (tl *Timeline) PrevFeed() {
@ -270,7 +268,7 @@ func (tl *Timeline) PrevFeed() {
}
f.FeedIndex = ni
tl.tutView.Shared.Top.SetText(tl.GetTitle())
tl.update <- true
tl.tutView.MainView.be_ForceUpdate(tl.tutView)
}
func (tl *Timeline) FindAndGoTo(ft config.FeedType, data string, hideBoosts, hideReplies bool) bool {
@ -283,7 +281,7 @@ func (tl *Timeline) FindAndGoTo(ft config.FeedType, data string, hideBoosts, hid
tl.tutView.FocusFeed(i, nil)
fh.FeedIndex = j
tl.tutView.Shared.Top.SetText(tl.GetTitle())
tl.update <- true
tl.tutView.MainView.be_ForceUpdate(tl.tutView)
return true
}
}

12
ui/tutview.go

@ -8,6 +8,7 @@ import (
"strings"
"time"
"github.com/Arceliar/phony"
"github.com/RasmusLindroth/go-mastodon"
"github.com/RasmusLindroth/tut/api"
"github.com/RasmusLindroth/tut/auth"
@ -52,6 +53,8 @@ func SetVars(config *config.Config, app *tview.Application, accounts *auth.Accou
}
type TutView struct {
phony.Inbox
tut *Tut
Timeline *Timeline
PageFocus PageFocusAt
@ -176,7 +179,7 @@ func (tvh *TutViewsHolder) SetFocusedTutView(index int) {
App.SetMouseCapture(curr.MouseInput)
}
if curr.MainView != nil {
curr.MainView.ForceUpdate()
curr.MainView.be_ForceUpdate(curr)
}
}
@ -245,11 +248,10 @@ func (tv *TutView) loggedIn(acc auth.Account) {
}
tv.tut.Client = ac
update := make(chan bool, 1)
tv.SubFocus = ListFocus
tv.LinkView = NewLinkView(tv)
tv.Timeline = NewTimeline(tv, update)
tv.MainView = NewMainView(tv, update)
tv.Timeline = NewTimeline(tv)
tv.MainView = NewMainView(tv)
tv.ComposeView = NewComposeView(tv)
tv.VoteView = NewVoteView(tv)
tv.PollView = NewPollView(tv)
@ -293,7 +295,7 @@ func (tv *TutView) FocusFeed(index int, ct *config.Timeline) {
}
}
tv.Shared.Top.SetText(tv.Timeline.GetTitle())
tv.Timeline.update <- true
tv.MainView.be_ForceUpdate(tv)
}
func (tv *TutView) NextFeed() {

Loading…
Cancel
Save