Renderer scaffolding

This commit is contained in:
Drew DeVault 2018-01-10 22:03:56 -05:00
parent a0be5e8025
commit db1b2cd53f
4 changed files with 100 additions and 6 deletions

View File

@ -1,10 +1,10 @@
package main
import (
"fmt"
"time"
"git.sr.ht/~sircmpwn/aerc2/config"
"git.sr.ht/~sircmpwn/aerc2/ui"
"git.sr.ht/~sircmpwn/aerc2/worker"
"git.sr.ht/~sircmpwn/aerc2/worker/types"
)
@ -20,19 +20,23 @@ func main() {
if err != nil {
panic(err)
}
fmt.Printf("Initializing worker %s\n", account.Name)
go work.Run()
work.PostAction(types.Configure{Config: account})
workers = append(workers, work)
}
for {
_ui, err := ui.Initialize(conf)
if err != nil {
panic(err)
}
defer _ui.Close()
for !_ui.Exit {
activity := false
for _, worker := range workers {
if msg := worker.GetMessage(); msg != nil {
activity = true
fmt.Printf("<- %T\n", msg)
}
}
activity = _ui.Tick() || activity
if !activity {
time.Sleep(100 * time.Millisecond)
}

45
ui/render.go Normal file
View File

@ -0,0 +1,45 @@
package ui
import (
tb "github.com/nsf/termbox-go"
"git.sr.ht/~sircmpwn/aerc2/config"
)
func Initialize(conf *config.AercConfig) (*UIState, error) {
state := UIState{
InvalidPanes: InvalidateAll,
Tabs: make([]AercTab, len(conf.Accounts)),
}
// TODO: Initialize each tab to a mailbox tab
if err := tb.Init(); err != nil {
return nil, err
}
tb.SetInputMode(tb.InputEsc | tb.InputMouse)
tb.SetOutputMode(tb.Output256)
return &state, nil
}
func (state *UIState) Close() {
tb.Close()
}
func (state *UIState) Invalidate(what uint) {
state.InvalidPanes |= what
}
func (state *UIState) Tick() bool {
switch e := tb.PollEvent(); e.Type {
case tb.EventKey:
if e.Key == tb.KeyEsc {
state.Exit = true
}
case tb.EventResize:
state.Invalidate(InvalidateAll)
}
if state.InvalidPanes != 0 {
// TODO: re-render
state.InvalidPanes = 0
}
return true
}

47
ui/types.go Normal file
View File

@ -0,0 +1,47 @@
package ui
const (
Valid = 0
InvalidateTabs = 1 << iota
InvalidateSidebar
InvalidateStatusBar
)
const (
InvalidateAll = InvalidateTabs | InvalidateSidebar | InvalidateStatusBar
)
type Geometry struct {
row int
col int
width int
height int
}
type AercTab interface {
Name() string
Invalid() bool
Render(at Geometry)
}
type UIState struct {
Exit bool
InvalidPanes uint
Panes struct {
TabList Geometry
TabView Geometry
Sidebar Geometry
StatusBar Geometry
}
Tabs []AercTab
SelectedTab int
Prompt struct {
Prompt *string
Text *string
Index int
Scroll int
}
}

View File

@ -1,7 +1,6 @@
package imap
import (
"fmt"
"time"
"git.sr.ht/~sircmpwn/aerc2/worker/types"
@ -50,7 +49,6 @@ func (w *IMAPWorker) Run() {
for {
select {
case msg := <-w.actions:
fmt.Printf("<= %T\n", msg)
w.handleMessage(msg)
default:
time.Sleep(100 * time.Millisecond)