From 1170893e395ff5e3e7bee7ff51224b4a572f01cf Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 17 Mar 2019 14:02:33 -0400 Subject: Add basic terminal widget --- widgets/account.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'widgets/account.go') diff --git a/widgets/account.go b/widgets/account.go index 6919c0e..b6ba595 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -20,7 +20,7 @@ type AccountView struct { dirlist *DirectoryList grid *ui.Grid logger *log.Logger - interactive ui.Interactive + interactive []ui.Interactive onInvalidate func(d ui.Drawable) runCmd func(cmd string) error msglist *MessageList @@ -116,6 +116,21 @@ func (acct *AccountView) Draw(ctx *ui.Context) { acct.grid.Draw(ctx) } +func (acct *AccountView) popInteractive() { + acct.interactive = acct.interactive[:len(acct.interactive)-1] + if len(acct.interactive) != 0 { + acct.interactive[len(acct.interactive)-1].Focus(true) + } +} + +func (acct *AccountView) pushInteractive(item ui.Interactive) { + if len(acct.interactive) != 0 { + acct.interactive[len(acct.interactive)-1].Focus(false) + } + acct.interactive = append(acct.interactive, item) + item.Focus(true) +} + func (acct *AccountView) beginExCommand() { exline := NewExLine(func(command string) { err := acct.runCmd(command) @@ -124,18 +139,18 @@ func (acct *AccountView) beginExCommand() { Color(tcell.ColorRed, tcell.ColorWhite) } acct.statusbar.Pop() - acct.interactive = nil + acct.popInteractive() }, func() { acct.statusbar.Pop() - acct.interactive = nil + acct.popInteractive() }) - acct.interactive = exline + acct.pushInteractive(exline) acct.statusbar.Push(exline) } func (acct *AccountView) Event(event tcell.Event) bool { - if acct.interactive != nil { - return acct.interactive.Event(event) + if len(acct.interactive) != 0 { + return acct.interactive[len(acct.interactive)-1].Event(event) } switch event := event.(type) { -- cgit v1.2.3