Send commands up to the top-level aerc widget

This commit is contained in:
Drew DeVault 2019-01-14 08:14:03 -05:00
parent d35213eaab
commit 8492a21a51
2 changed files with 26 additions and 14 deletions

View File

@ -20,13 +20,14 @@ type AccountView struct {
logger *log.Logger logger *log.Logger
interactive ui.Interactive interactive ui.Interactive
onInvalidate func(d ui.Drawable) onInvalidate func(d ui.Drawable)
runCmd func(cmd string) error
statusline *StatusLine statusline *StatusLine
statusbar *ui.Stack statusbar *ui.Stack
worker *types.Worker worker *types.Worker
} }
func NewAccountView( func NewAccountView(conf *config.AccountConfig,
conf *config.AccountConfig, logger *log.Logger) *AccountView { logger *log.Logger, runCmd func(cmd string) error) *AccountView {
statusbar := ui.NewStack() statusbar := ui.NewStack()
statusline := NewStatusLine() statusline := NewStatusLine()
@ -63,6 +64,7 @@ func NewAccountView(
dirlist: dirlist, dirlist: dirlist,
grid: grid, grid: grid,
logger: logger, logger: logger,
runCmd: runCmd,
statusline: statusline, statusline: statusline,
statusbar: statusbar, statusbar: statusbar,
worker: worker, worker: worker,
@ -106,8 +108,12 @@ func (acct *AccountView) Event(event tcell.Event) bool {
case *tcell.EventKey: case *tcell.EventKey:
if event.Rune() == ':' { if event.Rune() == ':' {
exline := NewExLine(func(command string) { exline := NewExLine(func(command string) {
acct.statusline.Push( err := acct.runCmd(command)
fmt.Sprintf("TODO: execute %s", command), 3*time.Second) if err != nil {
acct.statusline.Push(
fmt.Sprintf("Error: %v", err), 3*time.Second).
Color(tcell.ColorRed, tcell.ColorDefault)
}
acct.statusbar.Pop() acct.statusbar.Pop()
acct.interactive = nil acct.interactive = nil
}, func() { }, func() {

View File

@ -1,6 +1,7 @@
package widgets package widgets
import ( import (
"fmt"
"log" "log"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
@ -33,19 +34,19 @@ 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) aerc := &Aerc{
accounts: make(map[string]*AccountView),
for _, acct := range conf.Accounts {
view := NewAccountView(&acct, logger)
accts[acct.Name] = view
tabs.Add(view, acct.Name)
}
return &Aerc{
accounts: accts,
grid: mainGrid, grid: mainGrid,
tabs: tabs, tabs: tabs,
} }
for _, acct := range conf.Accounts {
view := NewAccountView(&acct, logger, aerc.RunCommand)
aerc.accounts[acct.Name] = view
tabs.Add(view, acct.Name)
}
return aerc
} }
func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) { func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) {
@ -66,3 +67,8 @@ func (aerc *Aerc) Event(event tcell.Event) bool {
acct, _ := aerc.tabs.Tabs[aerc.tabs.Selected].Content.(*AccountView) acct, _ := aerc.tabs.Tabs[aerc.tabs.Selected].Content.(*AccountView)
return acct.Event(event) return acct.Event(event)
} }
func (aerc *Aerc) RunCommand(cmd string) error {
// TODO
return fmt.Errorf("TODO: execute '%s'", cmd)
}