aerc/cmd/aerc/main.go

98 lines
1.8 KiB
Go
Raw Normal View History

2018-01-10 00:30:46 +01:00
package main
import (
2018-02-01 03:18:21 +01:00
"io"
"io/ioutil"
"log"
"os"
2018-01-10 14:35:26 +01:00
"time"
2018-01-10 01:18:19 +01:00
2018-02-01 03:18:21 +01:00
"github.com/mattn/go-isatty"
tb "github.com/nsf/termbox-go"
2018-02-01 03:18:21 +01:00
2018-01-10 01:18:19 +01:00
"git.sr.ht/~sircmpwn/aerc2/config"
2018-01-11 04:03:56 +01:00
"git.sr.ht/~sircmpwn/aerc2/ui"
2018-01-10 00:30:46 +01:00
)
type fill rune
func (f fill) Draw(ctx *ui.Context) {
for x := 0; x < ctx.Width(); x += 1 {
for y := 0; y < ctx.Height(); y += 1 {
ctx.SetCell(x, y, rune(f), tb.ColorDefault, tb.ColorDefault)
}
}
}
func (f fill) OnInvalidate(callback func(d ui.Drawable)) {
// no-op
}
func (f fill) Invalidate() {
// no-op
}
2018-01-10 00:30:46 +01:00
func main() {
2018-02-01 03:18:21 +01:00
var logOut io.Writer
var logger *log.Logger
if !isatty.IsTerminal(os.Stdout.Fd()) {
logOut = os.Stdout
} else {
logOut = ioutil.Discard
}
2018-02-02 00:59:13 +01:00
logger = log.New(logOut, "", log.LstdFlags)
2018-02-01 03:18:21 +01:00
logger.Println("Starting up aerc")
2018-01-10 17:19:45 +01:00
conf, err := config.LoadConfig(nil)
if err != nil {
2018-01-10 01:18:19 +01:00
panic(err)
}
2018-02-18 01:42:29 +01:00
tabs := ui.NewTabs()
tabs.Add(fill('★'), "白い星")
tabs.Add(fill('☆'), "empty stars")
2018-02-18 02:11:58 +01:00
grid := ui.NewGrid().Rows([]ui.GridSpec{
ui.GridSpec{ui.SIZE_EXACT, 1},
ui.GridSpec{ui.SIZE_WEIGHT, 1},
ui.GridSpec{ui.SIZE_EXACT, 1},
}).Columns([]ui.GridSpec{
ui.GridSpec{ui.SIZE_EXACT, 20},
ui.GridSpec{ui.SIZE_WEIGHT, 1},
})
// TODO: move sidebar into tab content, probably
2018-02-18 02:21:33 +01:00
grid.AddChild(ui.NewText("aerc").
Strategy(ui.TEXT_CENTER).
Color(tb.ColorBlack, tb.ColorWhite))
2018-02-18 02:11:58 +01:00
// sidebar placeholder:
grid.AddChild(ui.NewBordered(
fill('.'), ui.BORDER_RIGHT)).At(1, 0).Span(2, 1)
grid.AddChild(tabs.TabStrip).At(0, 1)
grid.AddChild(tabs.TabContent).At(1, 1)
exline := ui.NewExLine()
grid.AddChild(exline).At(2, 1)
_ui, err := ui.Initialize(conf, grid)
2018-01-11 04:41:15 +01:00
if err != nil {
panic(err)
}
defer _ui.Close()
_ui.AddInteractive(exline)
2018-02-18 01:42:29 +01:00
go (func() {
2018-02-18 01:43:44 +01:00
for {
time.Sleep(1 * time.Second)
tabs.Select((tabs.Selected + 1) % 2)
}
2018-02-18 01:42:29 +01:00
})()
2018-01-11 04:03:56 +01:00
for !_ui.Exit {
2018-01-11 15:04:18 +01:00
if !_ui.Tick() {
// ~60 FPS
time.Sleep(16 * time.Millisecond)
2018-01-10 14:35:26 +01:00
}
}
2018-01-10 00:30:46 +01:00
}