summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-14 08:14:03 -0500
committerDrew DeVault <sir@cmpwn.com>2019-01-14 08:14:03 -0500
commit8492a21a51c107f743a32231746bf5d38e9b1ccd (patch)
treeb0ed6d96dbc664c57bb9a0d1488ab4fec2e12f37
parentd35213eaabeda8749cd0aab103e5895cfcd96e94 (diff)
downloadaerc-8492a21a51c107f743a32231746bf5d38e9b1ccd.tar.gz
Send commands up to the top-level aerc widget
-rw-r--r--widgets/account.go14
-rw-r--r--widgets/aerc.go22
2 files changed, 24 insertions, 12 deletions
diff --git a/widgets/account.go b/widgets/account.go
index 8662c0c..54eb9e9 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -20,13 +20,14 @@ type AccountView struct {
 	logger       *log.Logger
 	interactive  ui.Interactive
 	onInvalidate func(d ui.Drawable)
+	runCmd       func(cmd string) error
 	statusline   *StatusLine
 	statusbar    *ui.Stack
 	worker       *types.Worker
 }
 
-func NewAccountView(
-	conf *config.AccountConfig, logger *log.Logger) *AccountView {
+func NewAccountView(conf *config.AccountConfig,
+	logger *log.Logger, runCmd func(cmd string) error) *AccountView {
 
 	statusbar := ui.NewStack()
 	statusline := NewStatusLine()
@@ -63,6 +64,7 @@ func NewAccountView(
 		dirlist:    dirlist,
 		grid:       grid,
 		logger:     logger,
+		runCmd:     runCmd,
 		statusline: statusline,
 		statusbar:  statusbar,
 		worker:     worker,
@@ -106,8 +108,12 @@ func (acct *AccountView) Event(event tcell.Event) bool {
 	case *tcell.EventKey:
 		if event.Rune() == ':' {
 			exline := NewExLine(func(command string) {
-				acct.statusline.Push(
-					fmt.Sprintf("TODO: execute %s", command), 3*time.Second)
+				err := acct.runCmd(command)
+				if err != nil {
+					acct.statusline.Push(
+						fmt.Sprintf("Error: %v", err), 3*time.Second).
+						Color(tcell.ColorRed, tcell.ColorDefault)
+				}
 				acct.statusbar.Pop()
 				acct.interactive = nil
 			}, func() {
diff --git a/widgets/aerc.go b/widgets/aerc.go
index cd4b773..9444c9f 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -1,6 +1,7 @@
 package widgets
 
 import (
+	"fmt"
 	"log"
 
 	"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.TabContent).At(1, 0).Span(1, 2)
 
-	accts := make(map[string]*AccountView)
+	aerc := &Aerc{
+		accounts: make(map[string]*AccountView),
+		grid:     mainGrid,
+		tabs:     tabs,
+	}
 
 	for _, acct := range conf.Accounts {
-		view := NewAccountView(&acct, logger)
-		accts[acct.Name] = view
+		view := NewAccountView(&acct, logger, aerc.RunCommand)
+		aerc.accounts[acct.Name] = view
 		tabs.Add(view, acct.Name)
 	}
 
-	return &Aerc{
-		accounts: accts,
-		grid:     mainGrid,
-		tabs:     tabs,
-	}
+	return aerc
 }
 
 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)
 	return acct.Event(event)
 }
+
+func (aerc *Aerc) RunCommand(cmd string) error {
+	// TODO
+	return fmt.Errorf("TODO: execute '%s'", cmd)
+}
d='n265' href='#n265'>265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348