2019-02-15 17:15:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-02-21 16:47:08 +00:00
|
|
|
"fmt"
|
2019-02-15 17:15:26 +00:00
|
|
|
"time"
|
|
|
|
|
2019-02-28 13:44:03 +00:00
|
|
|
"github.com/br0xen/termbox-screen"
|
2019-02-15 17:15:26 +00:00
|
|
|
"github.com/br0xen/termbox-util"
|
|
|
|
termbox "github.com/nsf/termbox-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AboutScreen holds all that's going on
|
|
|
|
type AboutScreen struct {
|
|
|
|
message string
|
|
|
|
messageTimeout time.Duration
|
|
|
|
messageTime time.Time
|
2019-02-21 16:47:08 +00:00
|
|
|
|
|
|
|
titleTemplate []string
|
|
|
|
commandsCol1 []Command
|
|
|
|
commandsCol2 []Command
|
|
|
|
}
|
|
|
|
|
|
|
|
type Command struct {
|
|
|
|
key string
|
|
|
|
description string
|
2019-02-15 17:15:26 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 15:29:33 +00:00
|
|
|
func (screen *AboutScreen) Id() int { return ScreenIdAbout }
|
2019-02-28 13:44:03 +00:00
|
|
|
|
|
|
|
func (screen *AboutScreen) Initialize(bundle termboxScreen.Bundle) error {
|
2019-02-21 16:47:08 +00:00
|
|
|
screen.titleTemplate = []string{
|
|
|
|
" __ ",
|
|
|
|
" _________ _____| | __",
|
|
|
|
" / ___\\__ \\ / ___/ |/ /",
|
|
|
|
" / /_/ > __ \\_\\___ \\| < ",
|
|
|
|
" \\___ (____ /____ >__|_ \\",
|
|
|
|
"/_____/ \\/ \\/ \\/",
|
|
|
|
}
|
|
|
|
|
|
|
|
screen.commandsCol1 = []Command{
|
|
|
|
Command{"j,↓", "down"},
|
|
|
|
Command{"k,↑", "up"},
|
|
|
|
Command{"l,→", "open task"},
|
2019-02-22 23:29:23 +00:00
|
|
|
Command{"[space]", "toggle task complete"},
|
2019-02-21 16:47:08 +00:00
|
|
|
Command{"g", "goto top"},
|
|
|
|
Command{"G", "goto bottom"},
|
|
|
|
Command{"ctrl+f", "jump down"},
|
|
|
|
Command{"ctrl+b", "jump up"},
|
|
|
|
}
|
|
|
|
screen.commandsCol2 = []Command{
|
|
|
|
Command{"D", "move task to done.txt"},
|
|
|
|
Command{"?", "this screen"},
|
|
|
|
Command{"q", "quit program"},
|
|
|
|
}
|
|
|
|
|
2019-02-15 17:15:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-02-28 13:44:03 +00:00
|
|
|
func (screen *AboutScreen) ResizeScreen() { screen.Initialize(nil) }
|
2019-02-15 17:15:26 +00:00
|
|
|
|
2019-02-28 13:44:03 +00:00
|
|
|
func (screen *AboutScreen) HandleKeyEvent(event termbox.Event) int {
|
2019-03-14 15:29:33 +00:00
|
|
|
return ScreenIdMain
|
2019-02-15 17:15:26 +00:00
|
|
|
}
|
2019-03-14 15:29:33 +00:00
|
|
|
func (screen *AboutScreen) HandleNoneEvent(event termbox.Event) int { return screen.Id() }
|
2019-02-15 17:15:26 +00:00
|
|
|
|
2019-02-28 13:44:03 +00:00
|
|
|
func (screen *AboutScreen) DrawScreen() {
|
2019-02-15 17:15:26 +00:00
|
|
|
width, height := termbox.Size()
|
2019-02-21 16:47:08 +00:00
|
|
|
xPos := (width - len(screen.titleTemplate[0])) / 2
|
|
|
|
yPos := 1
|
|
|
|
for _, line := range screen.titleTemplate {
|
|
|
|
termboxUtil.DrawStringAtPoint(line, xPos, yPos, DefaultFg, DefaultBg)
|
|
|
|
yPos++
|
|
|
|
}
|
|
|
|
|
|
|
|
numCols := 2
|
|
|
|
if width < 80 {
|
|
|
|
numCols = 1
|
|
|
|
}
|
|
|
|
col1XPos := (width - (width * 3 / 4))
|
|
|
|
col2XPos := (width - (width * 2 / 4))
|
|
|
|
if numCols == 1 {
|
|
|
|
col2XPos = col1XPos
|
|
|
|
}
|
|
|
|
screen.drawCommandsAtPoint(screen.commandsCol1, col1XPos, yPos)
|
|
|
|
screen.drawCommandsAtPoint(screen.commandsCol2, col2XPos, yPos)
|
2019-02-22 23:29:23 +00:00
|
|
|
exitTxt := "Press any key to return to tasks"
|
2019-02-15 17:15:26 +00:00
|
|
|
termboxUtil.DrawStringAtPoint(exitTxt, (width-len(exitTxt))/2, height-1, TitleFg, TitleBg)
|
|
|
|
}
|
2019-02-21 16:47:08 +00:00
|
|
|
|
|
|
|
func (screen *AboutScreen) drawCommandsAtPoint(commands []Command, x, y int) {
|
|
|
|
xPos, yPos := x, y
|
|
|
|
for index, cmd := range commands {
|
|
|
|
termboxUtil.DrawStringAtPoint(fmt.Sprintf("%6s", cmd.key), xPos, yPos, DefaultFg, DefaultBg)
|
|
|
|
termboxUtil.DrawStringAtPoint(cmd.description, xPos+8, yPos, DefaultFg, DefaultBg)
|
|
|
|
yPos++
|
|
|
|
if index > 2 && index%2 == 1 {
|
|
|
|
yPos++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|