aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-10 00:36:02 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-11 10:21:56 +0200
commit1300b2c81bf96ca143ded90a7f6af130006a516b (patch)
treeafb65be011e1c6bb454a3075313c36bb9110ac5b /main.go
parent34650131379a4542538da63751a89588d2f2cc85 (diff)
downloadaerc-1300b2c81bf96ca143ded90a7f6af130006a516b.tar.gz
ui: export global functions
There is no need for an UI object. The Aerc.ui field is unused. And there is a single instance of it anyway. Move the object's public fields as global variables and change methods to public functions. This makes the code cleaner and removes boilerplate. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'main.go')
-rw-r--r--main.go21
1 files changed, 7 insertions, 14 deletions
diff --git a/main.go b/main.go
index 8e449aea..fe3a2e7b 100644
--- a/main.go
+++ b/main.go
@@ -27,13 +27,13 @@ import (
"git.sr.ht/~rjarry/aerc/lib/hooks"
"git.sr.ht/~rjarry/aerc/lib/ipc"
"git.sr.ht/~rjarry/aerc/lib/templates"
- libui "git.sr.ht/~rjarry/aerc/lib/ui"
+ "git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
)
-func getCommands(selected libui.Drawable) []*commands.Commands {
+func getCommands(selected ui.Drawable) []*commands.Commands {
switch selected.(type) {
case *app.AccountView:
return []*commands.Commands{
@@ -104,7 +104,7 @@ func expandAbbreviations(cmd []string, sets []*commands.Commands) []string {
}
func execCommand(
- ui *libui.UI, cmd []string,
+ cmd []string,
acct *config.AccountConfig, msg *models.MessageInfo,
) error {
cmds := getCommands(app.SelectedTabContent())
@@ -228,8 +228,6 @@ func main() {
log.Infof("Starting up version %s", log.BuildInfo)
- var ui *libui.UI
-
deferLoop := make(chan struct{})
c := crypto.New()
@@ -239,14 +237,9 @@ func main() {
}
defer c.Close()
- app.Init(c, func(
- cmd []string, acct *config.AccountConfig,
- msg *models.MessageInfo,
- ) error {
- return execCommand(ui, cmd, acct, msg)
- }, getCompletions, &commands.CmdHistory, deferLoop)
+ app.Init(c, execCommand, getCompletions, &commands.CmdHistory, deferLoop)
- ui, err = libui.Initialize(app.Drawable())
+ err = ui.Initialize(app.Drawable())
if err != nil {
panic(err)
}
@@ -310,9 +303,9 @@ loop:
ui.HandleEvent(event)
case msg := <-types.WorkerMessages:
app.HandleMessage(msg)
- case callback := <-libui.Callbacks:
+ case callback := <-ui.Callbacks:
callback()
- case <-libui.Redraw:
+ case <-ui.Redraw:
ui.Render()
case <-ui.Quit:
err = app.CloseBackends()