boltbrowser/screen.go

48 lines
1010 B
Go
Raw Normal View History

2015-05-18 14:47:08 +00:00
package main
import "github.com/nsf/termbox-go"
2015-09-17 16:49:57 +00:00
// Screen is a basic structure for all of the applications screens
2015-05-18 14:47:08 +00:00
type Screen interface {
handleKeyEvent(event termbox.Event) int
performLayout()
drawScreen(style Style)
}
const (
2015-09-17 16:49:57 +00:00
// BrowserScreenIndex is the index
BrowserScreenIndex = iota
// AboutScreenIndex The idx number for the 'About' Screen
AboutScreenIndex
// ExitScreenIndex The idx number for Exiting
ExitScreenIndex
2015-05-18 14:47:08 +00:00
)
func defaultScreensForData(db *BoltDB) []Screen {
browserScreen := BrowserScreen{db: db, rightViewPort: ViewPort{}, leftViewPort: ViewPort{}}
2015-09-17 16:49:57 +00:00
aboutScreen := AboutScreen(0)
2015-05-18 14:47:08 +00:00
screens := [...]Screen{
2015-09-17 16:49:57 +00:00
&browserScreen,
&aboutScreen,
2015-05-18 14:47:08 +00:00
}
return screens[:]
}
func drawBackground(bg termbox.Attribute) {
termbox.Clear(0, bg)
}
func layoutAndDrawScreen(screen Screen, style Style) {
screen.performLayout()
2015-09-17 16:49:57 +00:00
drawBackground(style.defaultBg)
2015-05-18 14:47:08 +00:00
screen.drawScreen(style)
termbox.Flush()
}
type Line struct {
Text string
Fg termbox.Attribute
Bg termbox.Attribute
}