aerc/widgets/aerc.go

75 lines
1.6 KiB
Go
Raw Normal View History

2018-02-28 02:17:26 +00:00
package widgets
import (
"fmt"
2018-02-28 02:17:26 +00:00
"log"
"github.com/gdamore/tcell"
2018-02-28 02:17:26 +00:00
"git.sr.ht/~sircmpwn/aerc2/config"
2018-02-28 02:17:26 +00:00
libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
)
type Aerc struct {
2019-01-13 18:33:43 +00:00
accounts map[string]*AccountView
grid *libui.Grid
tabs *libui.Tabs
2018-02-28 02:17:26 +00:00
}
func NewAerc(conf *config.AercConfig, logger *log.Logger) *Aerc {
2018-02-28 02:17:26 +00:00
tabs := libui.NewTabs()
mainGrid := libui.NewGrid().Rows([]libui.GridSpec{
2018-06-12 13:50:46 +00:00
{libui.SIZE_EXACT, 1},
{libui.SIZE_WEIGHT, 1},
2018-02-28 02:17:26 +00:00
}).Columns([]libui.GridSpec{
2018-06-12 13:50:46 +00:00
{libui.SIZE_EXACT, 20},
{libui.SIZE_WEIGHT, 1},
2018-02-28 02:17:26 +00:00
})
// TODO: Grab sidebar size from config and via :set command
mainGrid.AddChild(libui.NewText("aerc").
2018-02-28 02:17:26 +00:00
Strategy(libui.TEXT_CENTER).
Color(tcell.ColorBlack, tcell.ColorWhite))
mainGrid.AddChild(tabs.TabStrip).At(0, 1)
mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)
2018-02-28 02:17:26 +00:00
aerc := &Aerc{
accounts: make(map[string]*AccountView),
grid: mainGrid,
tabs: tabs,
}
for _, acct := range conf.Accounts {
view := NewAccountView(&acct, logger, aerc.RunCommand)
aerc.accounts[acct.Name] = view
2019-01-13 18:03:28 +00:00
tabs.Add(view, acct.Name)
}
2018-02-28 02:17:26 +00:00
return aerc
2018-02-28 02:17:26 +00:00
}
func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) {
aerc.grid.OnInvalidate(func(_ libui.Drawable) {
onInvalidate(aerc)
})
2018-02-28 02:17:26 +00:00
}
func (aerc *Aerc) Invalidate() {
aerc.grid.Invalidate()
}
func (aerc *Aerc) Draw(ctx *libui.Context) {
aerc.grid.Draw(ctx)
}
func (aerc *Aerc) Event(event tcell.Event) bool {
2019-01-13 18:33:43 +00:00
acct, _ := aerc.tabs.Tabs[aerc.tabs.Selected].Content.(*AccountView)
return acct.Event(event)
2018-02-28 02:17:26 +00:00
}
func (aerc *Aerc) RunCommand(cmd string) error {
// TODO
return fmt.Errorf("TODO: execute '%s'", cmd)
}