From db1b2cd53f5dc7bfbfb6ee54ad0bb0882ea2cc03 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 10 Jan 2018 22:03:56 -0500 Subject: Renderer scaffolding --- ui/render.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ ui/types.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 ui/render.go create mode 100644 ui/types.go (limited to 'ui') diff --git a/ui/render.go b/ui/render.go new file mode 100644 index 0000000..bca0cf6 --- /dev/null +++ b/ui/render.go @@ -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 +} diff --git a/ui/types.go b/ui/types.go new file mode 100644 index 0000000..a7918b5 --- /dev/null +++ b/ui/types.go @@ -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 + } +} -- cgit v1.2.3