Debian Codegraph @

app/app.go

raw
1 package app
2
3 import (
4 "context"
5 "time"
6
7 "git.sr.ht/~rjarry/aerc/config"
8 "git.sr.ht/~rjarry/aerc/lib"
9 "git.sr.ht/~rjarry/aerc/lib/crypto"
10 "git.sr.ht/~rjarry/aerc/lib/ipc"
11 "git.sr.ht/~rjarry/aerc/lib/log"
12 "git.sr.ht/~rjarry/aerc/lib/state"
13 "git.sr.ht/~rjarry/aerc/lib/ui"
14 "git.sr.ht/~rjarry/aerc/models"
15 "git.sr.ht/~rjarry/aerc/worker/types"
16 "git.sr.ht/~rjarry/go-opt/v2"
17 "github.com/ProtonMail/go-crypto/openpgp"
18 )
19
20 var aerc Aerc
21
22 func Init(
23 crypto crypto.Provider,
24 cmd func(string, *config.AccountConfig, *models.MessageInfo) error,
25 complete func(ctx context.Context, cmd string) ([]opt.Completion, string), history lib.History,
26 deferLoop chan struct{},
27 ) {
28 aerc.Init(crypto, cmd, complete, history, deferLoop)
29 }
30
31 func Drawable() ui.DrawableInteractive { return &aerc }
32 func IPCHandler() ipc.Handler { return &aerc }
33 func Command(args []string) error { return aerc.Command(args) }
34 func HandleMessage(msg types.WorkerMessage) { aerc.HandleMessage(msg) }
35
36 func CloseBackends() error { return aerc.CloseBackends() }
37
38 func AddDialog(d ui.DrawableInteractive) { aerc.AddDialog(d) }
39 func CloseDialog() { aerc.CloseDialog() }
40
41 func HumanReadableBindings() []string {
42 return aerc.HumanReadableBindings()
43 }
44
45 func Account(name string) (*AccountView, error) { return aerc.Account(name) }
46 func AccountNames() []string { return aerc.AccountNames() }
47 func NextAccount() (*AccountView, error) { return aerc.NextAccount() }
48 func PrevAccount() (*AccountView, error) { return aerc.PrevAccount() }
49 func SelectedAccount() *AccountView { return aerc.SelectedAccount() }
50 func SelectedAccountUiConfig() *config.UIConfig { return aerc.SelectedAccountUiConfig() }
51
52 func NextTab() { aerc.NextTab() }
53 func PrevTab() { aerc.PrevTab() }
54 func PinTab() { aerc.PinTab() }
55 func UnpinTab() { aerc.UnpinTab() }
56 func MoveTab(i int, relative bool) { aerc.MoveTab(i, relative) }
57 func TabNames() []string { return aerc.TabNames() }
58 func GetTab(i int) *ui.Tab { return aerc.tabs.Get(i) }
59 func SelectTab(name string) bool { return aerc.SelectTab(name) }
60 func SelectPreviousTab() bool { return aerc.SelectPreviousTab() }
61 func SelectedTab() *ui.Tab { return aerc.SelectedTab() }
62 func SelectedTabContent() ui.Drawable { return aerc.SelectedTabContent() }
63 func SelectTabIndex(index int) bool { return aerc.SelectTabIndex(index) }
64 func SelectTabAtOffset(offset int) { aerc.SelectTabAtOffset(offset) }
65 func RemoveTab(tab ui.Drawable, closeContent bool) { aerc.RemoveTab(tab, closeContent) }
66 func NewTab(clickable ui.Drawable, name string) *ui.Tab {
67 return aerc.NewTab(clickable, name, false)
68 }
69
70 func NewBackgroundTab(clickable ui.Drawable, name string) *ui.Tab {
71 return aerc.NewTab(clickable, name, true)
72 }
73
74 func ReplaceTab(tabSrc ui.Drawable, tabTarget ui.Drawable, name string, closeSrc bool) {
75 aerc.ReplaceTab(tabSrc, tabTarget, name, closeSrc)
76 }
77
78 func ExecuteLastCommand() error {
79 lastCommand := aerc.cmdHistory.Last()
80 log.Tracef("repeating last command: %s", lastCommand)
81 return aerc.DirectCommand(lastCommand)
82 }
83
84 func UpdateStatus() { aerc.UpdateStatus() }
85 func PushPrompt(prompt *ExLine) { aerc.PushPrompt(prompt) }
86 func SetError(text string) { aerc.SetError(text) }
87 func PushError(text string) *StatusMessage { return aerc.PushError(text) }
88 func PushWarning(text string) *StatusMessage { return aerc.PushWarning(text) }
89 func PushSuccess(text string) *StatusMessage { return aerc.PushSuccess(text) }
90 func PushStatus(text string, expiry time.Duration) *StatusMessage {
91 return aerc.PushStatus(text, expiry)
92 }
93
94 func RegisterChoices(choices []Choice) { aerc.RegisterChoices(choices) }
95 func RegisterPrompt(prompt string, cmd string) { aerc.RegisterPrompt(prompt, cmd) }
96
97 func CryptoProvider() crypto.Provider { return aerc.Crypto }
98 func DecryptKeys(keys []openpgp.Key, symmetric bool) (b []byte, err error) {
99 return aerc.DecryptKeys(keys, symmetric)
100 }
101
102 func SetKeyPassthrough(value bool) {
103 config.Viewer().KeyPassthrough = value
104 for _, name := range AccountNames() {
105 if acct, _ := Account(name); acct != nil {
106 acct.SetStatus(state.Passthrough(value))
107 }
108 }
109 }