package widgets import ( "log" "time" "github.com/gdamore/tcell" "git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/lib/ui" libui "git.sr.ht/~sircmpwn/aerc/lib/ui" ) type Aerc struct { accounts map[string]*AccountView cmd func(cmd string) error conf *config.AercConfig focused libui.Interactive grid *libui.Grid logger *log.Logger simulating int statusbar *libui.Stack statusline *StatusLine pendingKeys []config.KeyStroke tabs *libui.Tabs } func NewAerc(conf *config.AercConfig, logger *log.Logger, cmd func(cmd string) error) *Aerc { tabs := libui.NewTabs() statusbar := ui.NewStack() statusline := NewStatusLine() statusbar.Push(statusline) grid := libui.NewGrid().Rows([]libui.GridSpec{ {libui.SIZE_EXACT, 1}, {libui.SIZE_WEIGHT, 1}, {libui.SIZE_EXACT, 1}, }).Columns([]libui.GridSpec{ {libui.SIZE_WEIGHT, 1}, }) grid.AddChild(tabs.TabStrip) grid.AddChild(tabs.TabContent).At(1, 0) grid.AddChild(statusbar).At(2, 0) aerc := &Aerc{ accounts: make(map[string]*AccountView), conf: conf, cmd: cmd, grid: grid, logger: logger, statusbar: statusbar, statusline: statusline, tabs: tabs, } for i, acct := range conf.Accounts { view := NewAccountView(conf, &conf.Accounts[i], logger, aerc) aerc.accounts[acct.Name] = view tabs.Add(view, acct.Name) } if len(conf.Accounts) == 0 { wizard := NewAccountWizard(aerc.Config(), aerc) wizard.Focus(true) aerc.NewTab(wizard, "New account") } return aerc } func (aerc *Aerc) Tick() bool { more := false for _, acct := range aerc.accounts { more = acct.Tick() || more } return more } func (aerc *Aerc) Children() []ui.Drawable { return aerc.grid.Children() } func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) { aerc.grid.OnInvalidate(func(_ libui.Drawable) { onInvalidate(aerc) }) } func (aerc *Aerc) Invalidate() { aerc.grid.Invalidate() } func (aerc *Aerc) Focus(focus bool) { // who cares } func (aerc *Aerc) Draw(ctx *libui.Context) { aerc.grid.Draw(ctx) } func (aerc *Aerc) getBindings() *config.KeyBindings { switch view := aerc.SelectedTab().(type) { case *AccountView: return aerc.conf.Bindings.MessageList case *AccountWizard: return aerc.conf.Bindings.AccountWizard case *Composer: switch view.Bindings() { case "compose::editor": return aerc.conf.Bindings.ComposeEditor case "compose::review": return aerc.conf.Bindings.ComposeReview default: return aerc.conf.Bindings.Compose } case *MessageViewer: return aerc.conf.Bindings.MessageView case *Terminal: return aerc.conf.Bindings.Terminal default: return aerc.conf.Bindings.Global } } func (aerc *Aerc) simulate(strokes []config.KeyStroke) { aerc.pendingKeys = []config.KeyStroke{} aerc.simulating += 1 for _, stroke := range strokes { simulated := tcell.NewEventKey( stroke.Key, stroke.Rune, tcell.ModNone) aerc.Event(simulated) } aerc.simulating -= 1 } func (aerc *Aerc) Event(event tcell.Event) bool { if aerc.focused != nil { return aerc.focused.Event(event) } switch event := event.(type) { case *tcell.EventKey: