diff options
author | Robin Jarry <robin@jarry.cc> | 2023-10-10 00:08:31 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-10-10 11:38:01 +0200 |
commit | bc176bd61ba726351a489cabf4da16a47dc5ec3b (patch) | |
tree | bbf06f731592d072f3d6f76f1648d61989375f2e /app/msglist.go | |
parent | 598e4a5803578ab3e291f232d6aad31b4efd8ea4 (diff) | |
download | aerc-bc176bd61ba726351a489cabf4da16a47dc5ec3b.tar.gz |
app: export global functions
The single Aerc object is passed around in almost all command functions.
This hinders readability.
Store the single Aerc instance as a global variable. Export public
functions from the app package to access methods of that object. Remove
all explicit references to *app.Aerc and replace them with calls to
these functions. For references to private/unexported fields and
functions from within the app package, directly access the global aerc
object.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'app/msglist.go')
-rw-r--r-- | app/msglist.go | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/app/msglist.go b/app/msglist.go index 57771ae8..b60ae148 100644 --- a/app/msglist.go +++ b/app/msglist.go @@ -27,14 +27,12 @@ type MessageList struct { spinner *Spinner store *lib.MessageStore isInitalizing bool - aerc *Aerc } -func NewMessageList(aerc *Aerc, account *AccountView) *MessageList { +func NewMessageList(account *AccountView) *MessageList { ml := &MessageList{ spinner: NewSpinner(account.uiConf), isInitalizing: true, - aerc: aerc, } // TODO: stop spinner, probably ml.spinner.Start() @@ -56,11 +54,11 @@ type messageRowParams struct { func (ml *MessageList) Draw(ctx *ui.Context) { ml.height = ctx.Height() ml.width = ctx.Width() - uiConfig := ml.aerc.SelectedAccountUiConfig() + uiConfig := SelectedAccountUiConfig() ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', uiConfig.GetStyle(config.STYLE_MSGLIST_DEFAULT)) - acct := ml.aerc.SelectedAccount() + acct := SelectedAccount() store := ml.Store() if store == nil || acct == nil || len(store.Uids()) == 0 { if ml.isInitalizing { @@ -242,7 +240,7 @@ func addMessage( } func (ml *MessageList) drawScrollbar(ctx *ui.Context) { - uiConfig := ml.aerc.SelectedAccountUiConfig() + uiConfig := SelectedAccountUiConfig() gutterStyle := uiConfig.GetStyle(config.STYLE_MSGLIST_GUTTER) pillStyle := uiConfig.GetStyle(config.STYLE_MSGLIST_PILL) @@ -259,13 +257,13 @@ func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) { if event, ok := event.(*tcell.EventMouse); ok { switch event.Buttons() { case tcell.Button1: - if ml.aerc == nil { + if aerc == nil { return } selectedMsg, ok := ml.Clicked(localX, localY) if ok { ml.Select(selectedMsg) - acct := ml.aerc.SelectedAccount() + acct := SelectedAccount() if acct == nil || acct.Messages().Empty() { return } @@ -275,14 +273,14 @@ func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) { return } lib.NewMessageStoreView(msg, acct.UiConfig().AutoMarkRead, - store, ml.aerc.Crypto, ml.aerc.DecryptKeys, + store, CryptoProvider(), DecryptKeys, func(view lib.MessageView, err error) { if err != nil { - ml.aerc.PushError(err.Error()) + PushError(err.Error()) return } viewer := NewMessageViewer(acct, view) - ml.aerc.NewTab(viewer, msg.Envelope.Subject) + NewTab(viewer, msg.Envelope.Subject) }) } case tcell.WheelDown: @@ -391,7 +389,7 @@ func (ml *MessageList) Select(index int) { } func (ml *MessageList) drawEmptyMessage(ctx *ui.Context) { - uiConfig := ml.aerc.SelectedAccountUiConfig() + uiConfig := SelectedAccountUiConfig() msg := uiConfig.EmptyMessage ctx.Printf((ctx.Width()/2)-(len(msg)/2), 0, uiConfig.GetStyle(config.STYLE_MSGLIST_DEFAULT), "%s", msg) |