43 lines
952 B
Go
43 lines
952 B
Go
package main
|
|
|
|
import "github.com/nsf/termbox-go"
|
|
|
|
// Screen is a basic structure for all of the applications screens
|
|
type Screen interface {
|
|
handleKeyEvent(event termbox.Event) int
|
|
performLayout(style Style)
|
|
drawScreen(style Style)
|
|
}
|
|
|
|
func drawBackground(bg termbox.Attribute) {
|
|
termbox.Clear(0, bg)
|
|
}
|
|
|
|
func layoutAndDrawScreen(screen Screen, style Style) {
|
|
screen.performLayout(style)
|
|
drawBackground(style.defaultBg)
|
|
screen.drawScreen(style)
|
|
termbox.Flush()
|
|
}
|
|
|
|
// Style defines style for a screen
|
|
type Style struct {
|
|
defaultBg termbox.Attribute
|
|
defaultFg termbox.Attribute
|
|
titleFg termbox.Attribute
|
|
titleBg termbox.Attribute
|
|
cursorFg termbox.Attribute
|
|
cursorBg termbox.Attribute
|
|
}
|
|
|
|
func getDefaultStyle() Style {
|
|
return Style{
|
|
defaultBg: termbox.ColorBlack,
|
|
defaultFg: termbox.ColorWhite,
|
|
titleBg: termbox.ColorBlack,
|
|
titleFg: termbox.ColorGreen,
|
|
cursorBg: termbox.ColorWhite,
|
|
cursorFg: termbox.ColorBlack,
|
|
}
|
|
}
|