143 lines
3.3 KiB
Go
143 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/br0xen/termbox-util"
|
|
"github.com/nsf/termbox-go"
|
|
)
|
|
|
|
/*
|
|
Command is a struct for associating descriptions to keys
|
|
*/
|
|
type Command struct {
|
|
key string
|
|
description string
|
|
}
|
|
|
|
// AboutScreen is just a basic 'int' type that we can extend to make this screen
|
|
type AboutScreen struct {
|
|
titleArt []string
|
|
commands [][]Command
|
|
}
|
|
|
|
func CreateAboutScreen() *AboutScreen {
|
|
var err error
|
|
s := new(AboutScreen)
|
|
s.titleArt = []string{
|
|
" __ _ ",
|
|
" ___ ____ / /_(_)_ _ ___ ",
|
|
" / _ `/ _ \\/ __/ / ' \\/ -_)",
|
|
" \\_, /\\___/\\__/_/_/_/_/\\__/ ",
|
|
"/___/ ",
|
|
}
|
|
s.commands = append(s.commands, []Command{
|
|
{"h,←", "close parent"},
|
|
{"j,↓", "down"},
|
|
{"k,↑", "up"},
|
|
{"l,→", "open item"},
|
|
|
|
{"g", "goto top"},
|
|
{"G", "goto bottom"},
|
|
{"ctrl+f", "jump down"},
|
|
{"ctrl+b", "jump up"},
|
|
})
|
|
s.commands = append(s.commands, []Command{
|
|
{"p,P", "create pair/at parent"},
|
|
{"b,B", "create bucket/at parent"},
|
|
{"e", "edit value of pair"},
|
|
{"r", "rename pair/bucket"},
|
|
{"D", "delete item"},
|
|
{"x,X", "export as string/json to file"},
|
|
{"?", "this screen"},
|
|
{"q", "quit program"},
|
|
})
|
|
}
|
|
|
|
func (screen *AboutScreen) drawCommandsAtPoint(x int, y int, style Style) {
|
|
xPos, yPos := x, y
|
|
for _, cmds := range screen.commands {
|
|
for index, cmd := range commands {
|
|
termboxUtil.DrawStringAtPoint(fmt.Sprintf("%6s", cmd.key), xPos, yPos, style.defaultFg, style.defaultBg)
|
|
termboxUtil.DrawStringAtPoint(cmd.description, xPos+8, yPos, style.defaultFg, style.defaultBg)
|
|
yPos++
|
|
if index > 2 && index%2 == 1 {
|
|
yPos++
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (screen *AboutScreen) handleKeyEvent(event termbox.Event) int {
|
|
return MainScreenIndex
|
|
}
|
|
|
|
func (screen *AboutScreen) performLayout() {}
|
|
|
|
func (screen *AboutScreen) drawScreen(style Style) {
|
|
defaultFg := style.defaultFg
|
|
defaultBg := style.defaultBg
|
|
width, height := termbox.Size()
|
|
|
|
firstLine := screen.titleArt[0]
|
|
startX := (width - len(firstLine)) / 2
|
|
startY := ((height - 2*len(template)) / 2) - 2
|
|
xPos := startX
|
|
yPos := startY
|
|
if height <= 20 {
|
|
title := AppName
|
|
startY = 0
|
|
yPos = 0
|
|
termboxUtil.DrawStringAtPoint(title, (width-len(title))/2, startY, style.titleFg, style.titleBg)
|
|
} else {
|
|
if height < 25 {
|
|
startY = 0
|
|
yPos = 0
|
|
}
|
|
for _, line := range template {
|
|
xPos = startX
|
|
for _, runeValue := range line {
|
|
bg := defaultBg
|
|
displayRune := ' '
|
|
if runeValue != ' ' {
|
|
displayRune = runeValue
|
|
termbox.SetCell(xPos, yPos, displayRune, defaultFg, bg)
|
|
}
|
|
xPos++
|
|
}
|
|
yPos++
|
|
}
|
|
}
|
|
|
|
commands1 := [...]Command{
|
|
{"h,←", "close parent"},
|
|
{"j,↓", "down"},
|
|
{"k,↑", "up"},
|
|
{"l,→", "open item"},
|
|
|
|
{"g", "goto top"},
|
|
{"G", "goto bottom"},
|
|
{"ctrl+f", "jump down"},
|
|
{"ctrl+b", "jump up"},
|
|
}
|
|
|
|
commands2 := [...]Command{
|
|
{"p,P", "create pair/at parent"},
|
|
{"b,B", "create bucket/at parent"},
|
|
{"e", "edit value of pair"},
|
|
{"r", "rename pair/bucket"},
|
|
{"D", "delete item"},
|
|
{"x,X", "export as string/json to file"},
|
|
|
|
{"?", "this screen"},
|
|
{"q", "quit program"},
|
|
}
|
|
xPos = startX // + 20
|
|
yPos++
|
|
|
|
drawCommandsAtPoint(commands1[:], xPos, yPos+1, style)
|
|
drawCommandsAtPoint(commands2[:], xPos+20, yPos+1, style)
|
|
exitTxt := "Press any key to return to browser"
|
|
termboxUtil.DrawStringAtPoint(exitTxt, (width-len(exitTxt))/2, height-1, style.titleFg, style.titleBg)
|
|
}
|