Move status line into account, update behavior

This commit is contained in:
Drew DeVault 2019-01-13 13:25:56 -05:00
parent 0fee2d6f97
commit b76deea963
2 changed files with 44 additions and 15 deletions

View File

@ -2,6 +2,9 @@ package widgets
import ( import (
"log" "log"
"time"
"github.com/gdamore/tcell"
"git.sr.ht/~sircmpwn/aerc2/config" "git.sr.ht/~sircmpwn/aerc2/config"
"git.sr.ht/~sircmpwn/aerc2/lib/ui" "git.sr.ht/~sircmpwn/aerc2/lib/ui"
@ -14,16 +17,14 @@ type AccountView struct {
grid *ui.Grid grid *ui.Grid
logger *log.Logger logger *log.Logger
onInvalidate func(d ui.Drawable) onInvalidate func(d ui.Drawable)
status *StatusLine
worker *types.Worker worker *types.Worker
} }
func NewAccountView(conf *config.AccountConfig, func NewAccountView(conf *config.AccountConfig,
logger *log.Logger, statusbar ui.Drawable) (*AccountView, error) { logger *log.Logger, statusbar ui.Drawable) *AccountView {
worker, err := worker.NewWorker(conf.Source, logger) status := NewStatusLine()
if err != nil {
return nil, err
}
grid := ui.NewGrid().Rows([]ui.GridSpec{ grid := ui.NewGrid().Rows([]ui.GridSpec{
{ui.SIZE_WEIGHT, 1}, {ui.SIZE_WEIGHT, 1},
@ -35,14 +36,28 @@ func NewAccountView(conf *config.AccountConfig,
grid.AddChild(ui.NewBordered( grid.AddChild(ui.NewBordered(
ui.NewFill('s'), ui.BORDER_RIGHT)).Span(2, 1) ui.NewFill('s'), ui.BORDER_RIGHT)).Span(2, 1)
grid.AddChild(ui.NewFill('.')).At(0, 1) grid.AddChild(ui.NewFill('.')).At(0, 1)
grid.AddChild(statusbar).At(1, 1) grid.AddChild(status).At(1, 1)
worker, err := worker.NewWorker(conf.Source, logger)
if err != nil {
acct := &AccountView{
conf: conf,
grid: grid,
logger: logger,
status: status,
}
// TODO: Update status line with error
return acct
}
acct := &AccountView{ acct := &AccountView{
conf: conf, conf: conf,
grid: grid, grid: grid,
logger: logger, logger: logger,
status: status,
worker: worker, worker: worker,
} }
logger.Printf("My grid is %p; status %p", grid, status)
go worker.Backend.Run() go worker.Backend.Run()
go func() { go func() {
@ -56,28 +71,39 @@ func NewAccountView(conf *config.AccountConfig,
worker.PostAction(&types.Configure{Config: conf}, nil) worker.PostAction(&types.Configure{Config: conf}, nil)
worker.PostAction(&types.Connect{}, acct.connected) worker.PostAction(&types.Connect{}, acct.connected)
return acct, nil go func() {
time.Sleep(10 * time.Second)
status.Set("Test")
}()
return acct
} }
func (acct *AccountView) connected(msg types.WorkerMessage) { func (acct *AccountView) connected(msg types.WorkerMessage) {
switch msg := msg.(type) { switch msg := msg.(type) {
case *types.Done: case *types.Done:
acct.status.Set("Connected.")
acct.logger.Println("Connected.") acct.logger.Println("Connected.")
acct.worker.PostAction(&types.ListDirectories{}, nil) acct.worker.PostAction(&types.ListDirectories{}, nil)
case *types.CertificateApprovalRequest: case *types.CertificateApprovalRequest:
// TODO: Ask the user // TODO: Ask the user
acct.logger.Println("Approving certificate") acct.logger.Println("Approved unknown certificate.")
acct.status.Push("Approved unknown certificate.", 5*time.Second)
acct.worker.PostAction(&types.ApproveCertificate{ acct.worker.PostAction(&types.ApproveCertificate{
Message: types.RespondTo(msg), Message: types.RespondTo(msg),
Approved: true, Approved: true,
}, acct.connected) }, acct.connected)
default: default:
acct.logger.Println("Connection failed.") acct.logger.Println("Connection failed.")
acct.status.Set("Connection failed.").
Color(tcell.ColorRed, tcell.ColorDefault)
} }
} }
func (acct *AccountView) OnInvalidate(onInvalidate func(d ui.Drawable)) { func (acct *AccountView) OnInvalidate(onInvalidate func(d ui.Drawable)) {
acct.grid.OnInvalidate(onInvalidate) acct.grid.OnInvalidate(func(_ ui.Drawable) {
onInvalidate(acct)
})
} }
func (acct *AccountView) Invalidate() { func (acct *AccountView) Invalidate() {

View File

@ -12,6 +12,7 @@ import (
) )
type Aerc struct { type Aerc struct {
accounts map[string]*AccountView
grid *libui.Grid grid *libui.Grid
tabs *libui.Tabs tabs *libui.Tabs
statusbar *libui.Stack statusbar *libui.Stack
@ -41,16 +42,16 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger) *Aerc {
mainGrid.AddChild(tabs.TabStrip).At(0, 1) mainGrid.AddChild(tabs.TabStrip).At(0, 1)
mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2) mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)
accts := make(map[string]*AccountView)
for _, acct := range conf.Accounts { for _, acct := range conf.Accounts {
view, err := NewAccountView(&acct, logger, statusbar) view := NewAccountView(&acct, logger, statusbar)
if err != nil { accts[acct.Name] = view
// TODO: something useful (update statusline?)
panic(err)
}
tabs.Add(view, acct.Name) tabs.Add(view, acct.Name)
} }
return &Aerc{ return &Aerc{
accounts: accts,
grid: mainGrid, grid: mainGrid,
statusbar: statusbar, statusbar: statusbar,
statusline: statusline, statusline: statusline,
@ -59,7 +60,9 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger) *Aerc {
} }
func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) { func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) {
aerc.grid.OnInvalidate(onInvalidate) aerc.grid.OnInvalidate(func(_ libui.Drawable) {
onInvalidate(aerc)
})
} }
func (aerc *Aerc) Invalidate() { func (aerc *Aerc) Invalidate() {