aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-13 13:25:56 -0500
committerDrew DeVault <sir@cmpwn.com>2019-01-13 13:25:56 -0500
commitb76deea9635d56bfa740127683e43bf817f5e3be (patch)
tree1f441196e2a1bb96a7fabbad2d19472c5d4d2905 /widgets
parent0fee2d6f971b59844830d7b27719322661de8d15 (diff)
downloadaerc-b76deea9635d56bfa740127683e43bf817f5e3be.tar.gz
Move status line into account, update behavior
Diffstat (limited to 'widgets')
-rw-r--r--widgets/account.go44
-rw-r--r--widgets/aerc.go15
2 files changed, 44 insertions, 15 deletions
diff --git a/widgets/account.go b/widgets/account.go
index 1f0cc6ac..dd7b068a 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() {
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 4351f3ba..58e8972e 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -12,6 +12,7 @@ import (
)
type Aerc struct {
+ accounts map[string]*AccountView
grid *libui.Grid
tabs *libui.Tabs
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.TabContent).At(1, 0).Span(1, 2)
+ accts := make(map[string]*AccountView)
+
for _, acct := range conf.Accounts {
- view, err := NewAccountView(&acct, logger, statusbar)
- if err != nil {
- // TODO: something useful (update statusline?)
- panic(err)
- }
+ view := NewAccountView(&acct, logger, statusbar)
+ accts[acct.Name] = view
tabs.Add(view, acct.Name)
}
return &Aerc{
+ accounts: accts,
grid: mainGrid,
statusbar: statusbar,
statusline: statusline,
@@ -59,7 +60,9 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger) *Aerc {
}
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() {