diff options
-rw-r--r-- | aerc.go | 8 | ||||
-rw-r--r-- | go.sum | 11 | ||||
-rw-r--r-- | widgets/account.go | 41 | ||||
-rw-r--r-- | widgets/aerc.go | 31 |
4 files changed, 61 insertions, 30 deletions
@@ -15,8 +15,10 @@ import ( ) func main() { - var logOut io.Writer - var logger *log.Logger + var ( + logOut io.Writer + logger *log.Logger + ) if !isatty.IsTerminal(os.Stdout.Fd()) { logOut = os.Stdout } else { @@ -30,7 +32,7 @@ func main() { panic(err) } - ui, err := libui.Initialize(conf, widgets.NewAerc(logger)) + ui, err := libui.Initialize(conf, widgets.NewAerc(conf, logger)) if err != nil { panic(err) } @@ -0,0 +1,11 @@ +github.com/gdamore/encoding v0.0.0-20151215212835-b23993cbb635/go.mod h1:yrQYJKKDTrHmbYxI7CYi+/hbdiDT2m4Hj+t0ikCjsrQ= +github.com/gdamore/tcell v1.0.0/go.mod h1:tqyG50u7+Ctv1w5VX67kLzKcj9YXR/JSBZQq/+mLl1A= +github.com/go-ini/ini v1.32.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= +github.com/kyoh86/xdg v0.0.0-20171127140545-8db68a8ea76a/go.mod h1:Z5mDqe0fxyxn3W2yTxsBAOQqIrXADQIh02wrTnaRM38= +github.com/lucasb-eyer/go-colorful v0.0.0-20180531031333-d9cec903b20c/go.mod h1:NXg0ArsFk0Y01623LgUqoqcouGDB+PwCCQlrwrG6xJ4= +github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/nsf/termbox-go v0.0.0-20180129072728-88b7b944be8b/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/widgets/account.go b/widgets/account.go new file mode 100644 index 0000000..a2c5ce7 --- /dev/null +++ b/widgets/account.go @@ -0,0 +1,41 @@ +package widgets + +import ( + "git.sr.ht/~sircmpwn/aerc2/config" + "git.sr.ht/~sircmpwn/aerc2/lib/ui" +) + +type AccountView struct { + conf *config.AccountConfig + grid *ui.Grid + onInvalidate func(d ui.Drawable) +} + +func NewAccountView(conf *config.AccountConfig, + statusbar ui.Drawable) *AccountView { + + grid := ui.NewGrid().Rows([]ui.GridSpec{ + {ui.SIZE_WEIGHT, 1}, + {ui.SIZE_EXACT, 1}, + }).Columns([]ui.GridSpec{ + {ui.SIZE_EXACT, 20}, + {ui.SIZE_WEIGHT, 1}, + }) + 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) + return &AccountView{conf: conf, grid: grid} +} + +func (acct *AccountView) OnInvalidate(onInvalidate func(d ui.Drawable)) { + acct.grid.OnInvalidate(onInvalidate) +} + +func (acct *AccountView) Invalidate() { + acct.grid.Invalidate() +} + +func (acct *AccountView) Draw(ctx *ui.Context) { + acct.grid.Draw(ctx) +} diff --git a/widgets/aerc.go b/widgets/aerc.go index 53f53f7..3bd082e 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -7,6 +7,7 @@ import ( "github.com/gdamore/tcell" + "git.sr.ht/~sircmpwn/aerc2/config" libui "git.sr.ht/~sircmpwn/aerc2/lib/ui" ) @@ -18,7 +19,7 @@ type Aerc struct { interactive libui.Interactive } -func NewAerc(logger *log.Logger) *Aerc { +func NewAerc(conf *config.AercConfig, logger *log.Logger) *Aerc { tabs := libui.NewTabs() mainGrid := libui.NewGrid().Rows([]libui.GridSpec{ @@ -40,34 +41,10 @@ func NewAerc(logger *log.Logger) *Aerc { mainGrid.AddChild(tabs.TabStrip).At(0, 1) mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2) - acctPlaceholder := func(sidebar, body rune, name string) { - accountGrid := libui.NewGrid().Rows([]libui.GridSpec{ - {libui.SIZE_WEIGHT, 1}, - {libui.SIZE_EXACT, 1}, - }).Columns([]libui.GridSpec{ - {libui.SIZE_EXACT, 20}, - {libui.SIZE_WEIGHT, 1}, - }) - // Sidebar placeholder - accountGrid.AddChild(libui.NewBordered( - libui.NewFill(sidebar), libui.BORDER_RIGHT)).Span(2, 1) - // Message list placeholder - accountGrid.AddChild(libui.NewFill(body)).At(0, 1) - // Statusbar - accountGrid.AddChild(statusbar).At(1, 1) - tabs.Add(accountGrid, name) + for _, acct := range conf.Accounts { + tabs.Add(NewAccountView(&acct, statusbar), acct.Name) } - acctPlaceholder('.', '★', "白い星") - acctPlaceholder(',', '☆', "empty stars") - - go (func() { - for { - time.Sleep(1 * time.Second) - tabs.Select((tabs.Selected + 1) % 2) - } - })() - return &Aerc{ grid: mainGrid, statusbar: statusbar, |