boltbrowser/screen.go

44 lines
918 B
Go
Raw Normal View History

2015-04-24 22:53:33 +00:00
package main
import "github.com/nsf/termbox-go"
2015-09-17 16:52:02 +00:00
// Screen is a basic structure for all of the applications screens
2015-04-24 22:53:33 +00:00
type Screen interface {
handleKeyEvent(event termbox.Event) int
performLayout()
drawScreen(style Style)
}
const (
2015-09-17 16:52:02 +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-04-24 22:53:33 +00:00
)
func defaultScreensForData(db *BoltDB) []Screen {
2015-09-17 16:52:02 +00:00
var viewPort ViewPort
2015-04-24 22:53:33 +00:00
2015-09-17 16:52:02 +00:00
browserScreen := BrowserScreen{db: db, viewPort: viewPort}
aboutScreen := AboutScreen(0)
2015-04-24 22:53:33 +00:00
screens := [...]Screen{
2015-09-17 16:52:02 +00:00
&browserScreen,
&aboutScreen,
2015-04-24 22:53:33 +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:52:02 +00:00
drawBackground(style.defaultBg)
2015-04-24 22:53:33 +00:00
screen.drawScreen(style)
termbox.Flush()
}