diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-01-13 13:25:56 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-01-13 13:25:56 -0500 |
commit | b76deea9635d56bfa740127683e43bf817f5e3be (patch) | |
tree | 1f441196e2a1bb96a7fabbad2d19472c5d4d2905 /widgets/account.go | |
parent | 0fee2d6f971b59844830d7b27719322661de8d15 (diff) | |
download | aerc-b76deea9635d56bfa740127683e43bf817f5e3be.zip |
Move status line into account, update behavior
Diffstat (limited to 'widgets/account.go')
-rw-r--r-- | widgets/account.go | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/widgets/account.go b/widgets/account.go index 1f0cc6a..dd7b068 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -2,6 +2,9 @@ package widgets import ( "log" + "time" + + "github.com/gdamore/tcell" "git.sr.ht/~sircmpwn/aerc2/config" "git.sr.ht/~sircmpwn/aerc2/lib/ui" @@ -14,16 +17,14 @@ type AccountView struct { grid *ui.Grid logger *log.Logger onInvalidate func(d ui.Drawable) + status *StatusLine worker *types.Worker } 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) - if err != nil { - return nil, err - } + status := NewStatusLine() grid := ui.NewGrid().Rows([]ui.GridSpec{ {ui.SIZE_WEIGHT, 1}, @@ -35,14 +36,28 @@ func NewAccountView(conf *config.AccountConfig, grid.AddChild(ui.NewBordered( ui.NewFill('s'), ui.BORDER_RIGHT)).Span(2, 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{ conf: conf, grid: grid, logger: logger, + status: status, worker: worker, } + logger.Printf("My grid is %p; status %p", grid, status) go worker.Backend.Run() go func() { @@ -56,28 +71,39 @@ func NewAccountView(conf *config.AccountConfig, worker.PostAction(&types.Configure{Config: conf}, nil) 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) { switch msg := msg.(type) { case *types.Done: + acct.status.Set("Connected.") acct.logger.Println("Connected.") acct.worker.PostAction(&types.ListDirectories{}, nil) case *types.CertificateApprovalRequest: // 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{ Message: types.RespondTo(msg), Approved: true, }, acct.connected) default: acct.logger.Println("Connection failed.") + acct.status.Set("Connection failed."). + Color(tcell.ColorRed, tcell.ColorDefault) } } 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() { |