diff options
author | Robin Jarry <robin@jarry.cc> | 2023-10-10 00:36:02 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-10-11 10:21:56 +0200 |
commit | 1300b2c81bf96ca143ded90a7f6af130006a516b (patch) | |
tree | afb65be011e1c6bb454a3075313c36bb9110ac5b /main.go | |
parent | 34650131379a4542538da63751a89588d2f2cc85 (diff) | |
download | aerc-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.go | 21 |
1 files changed, 7 insertions, 14 deletions
@@ -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() |