2018-02-28 03:17:26 +01:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
2018-02-28 03:29:50 +01:00
|
|
|
"fmt"
|
2018-02-28 03:17:26 +01:00
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2018-06-01 09:58:00 +02:00
|
|
|
"github.com/gdamore/tcell"
|
2018-02-28 03:17:26 +01:00
|
|
|
|
|
|
|
libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Aerc struct {
|
|
|
|
grid *libui.Grid
|
|
|
|
tabs *libui.Tabs
|
|
|
|
statusbar *libui.Stack
|
|
|
|
statusline *StatusLine
|
|
|
|
interactive libui.Interactive
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAerc(logger *log.Logger) *Aerc {
|
|
|
|
tabs := libui.NewTabs()
|
|
|
|
|
2018-06-12 01:23:09 +02:00
|
|
|
mainGrid := libui.NewGrid().Rows([]libui.GridSpec{
|
2018-02-28 03:17:26 +01:00
|
|
|
libui.GridSpec{libui.SIZE_EXACT, 1},
|
|
|
|
libui.GridSpec{libui.SIZE_WEIGHT, 1},
|
|
|
|
}).Columns([]libui.GridSpec{
|
|
|
|
libui.GridSpec{libui.SIZE_EXACT, 20},
|
|
|
|
libui.GridSpec{libui.SIZE_WEIGHT, 1},
|
|
|
|
})
|
|
|
|
|
2018-06-12 01:23:09 +02:00
|
|
|
statusbar := libui.NewStack()
|
|
|
|
statusline := NewStatusLine()
|
|
|
|
statusbar.Push(statusline)
|
|
|
|
|
|
|
|
// TODO: Grab sidebar size from config and via :set command
|
|
|
|
mainGrid.AddChild(libui.NewText("aerc").
|
2018-02-28 03:17:26 +01:00
|
|
|
Strategy(libui.TEXT_CENTER).
|
2018-06-01 09:58:00 +02:00
|
|
|
Color(tcell.ColorBlack, tcell.ColorWhite))
|
2018-06-12 01:23:09 +02:00
|
|
|
mainGrid.AddChild(tabs.TabStrip).At(0, 1)
|
|
|
|
mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)
|
2018-02-28 03:17:26 +01:00
|
|
|
|
2018-06-12 01:23:09 +02:00
|
|
|
acctPlaceholder := func(sidebar, body rune, name string) {
|
|
|
|
accountGrid := libui.NewGrid().Rows([]libui.GridSpec{
|
|
|
|
libui.GridSpec{libui.SIZE_WEIGHT, 1},
|
|
|
|
libui.GridSpec{libui.SIZE_EXACT, 1},
|
|
|
|
}).Columns([]libui.GridSpec{
|
|
|
|
libui.GridSpec{libui.SIZE_EXACT, 20},
|
|
|
|
libui.GridSpec{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)
|
|
|
|
}
|
2018-02-28 03:17:26 +01:00
|
|
|
|
2018-06-12 01:23:09 +02:00
|
|
|
acctPlaceholder('.', '★', "白い星")
|
|
|
|
acctPlaceholder(',', '☆', "empty stars")
|
2018-02-28 03:17:26 +01:00
|
|
|
|
|
|
|
go (func() {
|
|
|
|
for {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
tabs.Select((tabs.Selected + 1) % 2)
|
|
|
|
}
|
|
|
|
})()
|
|
|
|
|
|
|
|
return &Aerc{
|
2018-06-12 02:04:21 +02:00
|
|
|
grid: mainGrid,
|
|
|
|
statusbar: statusbar,
|
|
|
|
statusline: statusline,
|
|
|
|
tabs: tabs,
|
2018-02-28 03:17:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) {
|
|
|
|
aerc.grid.OnInvalidate(onInvalidate)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (aerc *Aerc) Invalidate() {
|
|
|
|
aerc.grid.Invalidate()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (aerc *Aerc) Draw(ctx *libui.Context) {
|
|
|
|
aerc.grid.Draw(ctx)
|
|
|
|
}
|
|
|
|
|
2018-06-01 09:58:00 +02:00
|
|
|
func (aerc *Aerc) Event(event tcell.Event) bool {
|
|
|
|
switch event := event.(type) {
|
|
|
|
case *tcell.EventKey:
|
|
|
|
if event.Rune() == ':' {
|
2018-02-28 03:33:47 +01:00
|
|
|
exline := NewExLine(func(command string) {
|
|
|
|
aerc.statusline.Push(fmt.Sprintf("TODO: execute %s", command),
|
2018-06-12 02:04:21 +02:00
|
|
|
3*time.Second)
|
2018-02-28 03:33:47 +01:00
|
|
|
aerc.statusbar.Pop()
|
|
|
|
aerc.interactive = nil
|
|
|
|
}, func() {
|
|
|
|
aerc.statusbar.Pop()
|
|
|
|
aerc.interactive = nil
|
|
|
|
})
|
|
|
|
aerc.interactive = exline
|
|
|
|
aerc.statusbar.Push(exline)
|
|
|
|
return true
|
|
|
|
}
|
2018-06-01 09:58:00 +02:00
|
|
|
}
|
|
|
|
if aerc.interactive != nil {
|
|
|
|
return aerc.interactive.Event(event)
|
|
|
|
} else {
|
|
|
|
return false
|
2018-02-28 03:33:47 +01:00
|
|
|
}
|
2018-02-28 03:17:26 +01:00
|
|
|
}
|