2022-04-14 16:32:39 +00:00
|
|
|
package ui
|
2015-05-18 14:47:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-09-17 16:49:57 +00:00
|
|
|
|
2022-04-14 16:32:39 +00:00
|
|
|
"git.bullercodeworks.com/brian/wandle"
|
2015-05-18 14:47:08 +00:00
|
|
|
"github.com/nsf/termbox-go"
|
2022-04-14 16:32:39 +00:00
|
|
|
"github.com/spf13/viper"
|
2015-05-18 14:47:08 +00:00
|
|
|
)
|
|
|
|
|
2022-04-14 16:32:39 +00:00
|
|
|
const (
|
|
|
|
ABT_CmdGotoBrowse = AboutId | iota
|
|
|
|
)
|
|
|
|
|
|
|
|
type AboutMsg struct {
|
|
|
|
source int
|
|
|
|
data interface{}
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
type aboutScreen struct {
|
|
|
|
ui *Ui
|
|
|
|
|
|
|
|
commands1 []Command
|
|
|
|
commands2 []Command
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:47:08 +00:00
|
|
|
type Command struct {
|
|
|
|
key string
|
|
|
|
description string
|
|
|
|
}
|
|
|
|
|
2022-04-14 16:32:39 +00:00
|
|
|
func NewAboutScreen(u *Ui) *aboutScreen { return &aboutScreen{ui: u} }
|
|
|
|
|
|
|
|
func (s *aboutScreen) Init() wandle.Cmd {
|
|
|
|
s.commands1 = []Command{
|
|
|
|
{"h,←", "close parent"},
|
|
|
|
{"j,↓", "down"},
|
|
|
|
{"k,↑", "up"},
|
|
|
|
{"l,→", "open item"},
|
|
|
|
{"J", "scroll right pane down"},
|
|
|
|
{"K", "scroll right pane up"},
|
|
|
|
{"", ""},
|
|
|
|
{"g", "goto top"},
|
|
|
|
{"G", "goto bottom"},
|
|
|
|
{"", ""},
|
|
|
|
{"ctrl+f", "jump down"},
|
|
|
|
{"ctrl+b", "jump up"},
|
|
|
|
}
|
|
|
|
|
|
|
|
s.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"},
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2015-05-18 14:47:08 +00:00
|
|
|
|
2022-04-14 16:32:39 +00:00
|
|
|
func (s *aboutScreen) Update(msg wandle.Msg) wandle.Cmd {
|
|
|
|
switch msg := msg.(type) {
|
|
|
|
case AboutMsg:
|
|
|
|
return s.handleAboutMsg(msg)
|
|
|
|
case termbox.Event:
|
|
|
|
return s.handleTermboxEvent(msg)
|
|
|
|
}
|
|
|
|
return nil
|
2015-05-18 14:47:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 16:32:39 +00:00
|
|
|
func (s *aboutScreen) handleAboutMsg(msg AboutMsg) wandle.Cmd {
|
|
|
|
switch msg.source {
|
|
|
|
case ABT_CmdGotoBrowse:
|
|
|
|
return wandle.SwitchScreenCmd(s.ui.browseScreen)
|
|
|
|
}
|
|
|
|
return nil
|
2015-05-18 14:47:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 16:32:39 +00:00
|
|
|
func (s *aboutScreen) handleTermboxEvent(msg termbox.Event) wandle.Cmd {
|
2022-04-20 21:22:43 +00:00
|
|
|
if msg.Type == termbox.EventKey {
|
|
|
|
return wandle.SwitchScreenCmd(s.ui.browseScreen)
|
|
|
|
}
|
2022-04-14 16:32:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *aboutScreen) View(style wandle.Style) {
|
2015-05-18 14:47:08 +00:00
|
|
|
width, height := termbox.Size()
|
|
|
|
template := [...]string{
|
|
|
|
" _______ _______ ___ _______ _______ ______ _______ _ _ _______ _______ ______ ",
|
|
|
|
"| _ || || | | || _ || _ | | || | _ | || || || _ | ",
|
|
|
|
"| |_| || _ || | |_ _|| |_| || | || | _ || || || || _____|| ___|| | || ",
|
|
|
|
"| || | | || | | | | || |_||_ | | | || || |_____ | |___ | |_||_ ",
|
|
|
|
"| _ | | |_| || |___ | | | _ | | __ || |_| || ||_____ || ___|| __ |",
|
|
|
|
"| |_| || || || | | |_| || | | || || _ | _____| || |___ | | | |",
|
|
|
|
"|_______||_______||_______||___| |_______||___| |_||_______||__| |__||_______||_______||___| |_|",
|
|
|
|
}
|
2015-09-17 16:49:57 +00:00
|
|
|
if width < 100 {
|
|
|
|
template = [...]string{
|
|
|
|
" ____ ____ _ _____ ____ ____ ____ _ _ ____ ___ ____ ",
|
|
|
|
"| _ || || | | || _ || _ | | || | _ | || || || _ | ",
|
|
|
|
"| |_||| _ || | |_ _|| |_||| | || | _ || || || || ___|| _|| | || ",
|
|
|
|
"| ||| | || | | | | || |_|| || | || |||___ | |_ | |_||_ ",
|
|
|
|
"| _ |||_| || |___| | | _ || _ |||_| || ||__ || _|| __ |",
|
|
|
|
"| |_||| || | | | |_||| | | || || _ | __| || |_ | | | |",
|
|
|
|
"|____||____||_____|_| |____||_| |_||____||__| |__||____||___||_| |_|",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
firstLine := template[0]
|
|
|
|
startX := (width - len(firstLine)) / 2
|
|
|
|
//startX := (width - len(firstLine)) / 2
|
|
|
|
startY := ((height - 2*len(template)) / 2) - 2
|
|
|
|
xPos := startX
|
|
|
|
yPos := startY
|
2015-05-18 14:47:08 +00:00
|
|
|
if height <= 20 {
|
|
|
|
title := "BoltBrowser"
|
2015-09-17 16:49:57 +00:00
|
|
|
startY = 0
|
|
|
|
yPos = 0
|
2022-04-14 16:32:39 +00:00
|
|
|
wandle.Print((width-len(title))/2, startY, style, title)
|
2015-05-18 14:47:08 +00:00
|
|
|
} else {
|
|
|
|
if height < 25 {
|
2015-09-17 16:49:57 +00:00
|
|
|
startY = 0
|
|
|
|
yPos = 0
|
2015-05-18 14:47:08 +00:00
|
|
|
}
|
|
|
|
for _, line := range template {
|
2015-09-17 16:49:57 +00:00
|
|
|
xPos = startX
|
2015-05-18 14:47:08 +00:00
|
|
|
for _, runeValue := range line {
|
|
|
|
displayRune := ' '
|
|
|
|
if runeValue != ' ' {
|
|
|
|
displayRune = runeValue
|
2022-04-14 16:32:39 +00:00
|
|
|
termbox.SetCell(xPos, yPos, displayRune, style.Foreground, style.Background)
|
2015-05-18 14:47:08 +00:00
|
|
|
}
|
2015-09-17 16:49:57 +00:00
|
|
|
xPos++
|
2015-05-18 14:47:08 +00:00
|
|
|
}
|
2015-09-17 16:49:57 +00:00
|
|
|
yPos++
|
2015-05-18 14:47:08 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-18 14:55:48 +00:00
|
|
|
yPos++
|
2022-04-14 16:32:39 +00:00
|
|
|
versionString := fmt.Sprintf("Version: %0.1f", viper.GetFloat64("version"))
|
|
|
|
wandle.Print((width-len(versionString))/2, yPos, style, versionString)
|
2019-10-16 22:41:29 +00:00
|
|
|
var maxCmd1 int
|
2022-04-14 16:32:39 +00:00
|
|
|
for k := range s.commands1 {
|
|
|
|
tst := len(s.commands1[k].key) + 1 + len(s.commands1[k].description)
|
2019-10-16 22:41:29 +00:00
|
|
|
if tst > maxCmd1 {
|
|
|
|
maxCmd1 = tst
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var maxCmd2 int
|
2022-04-14 16:32:39 +00:00
|
|
|
for k := range s.commands2 {
|
|
|
|
tst := len(s.commands2[k].key) + 1 + len(s.commands2[k].description)
|
2019-10-16 22:41:29 +00:00
|
|
|
if tst > maxCmd2 {
|
|
|
|
maxCmd2 = tst
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xPos = (width / 2) - ((maxCmd1 + maxCmd2) / 2)
|
2015-09-17 16:49:57 +00:00
|
|
|
yPos++
|
2015-05-18 14:47:08 +00:00
|
|
|
|
2022-04-14 16:32:39 +00:00
|
|
|
for k, cmd := range s.commands1 {
|
|
|
|
wandle.Print(xPos, yPos+1+k, style, fmt.Sprintf("%6s %s", cmd.key, cmd.description))
|
2019-10-16 22:41:29 +00:00
|
|
|
}
|
2022-04-14 16:32:39 +00:00
|
|
|
for k, cmd := range s.commands2 {
|
|
|
|
wandle.Print(xPos+40, yPos+1+k, style, fmt.Sprintf("%6s %s", cmd.key, cmd.description))
|
2019-10-16 22:41:29 +00:00
|
|
|
}
|
2015-09-17 16:49:57 +00:00
|
|
|
exitTxt := "Press any key to return to browser"
|
2022-04-14 16:32:39 +00:00
|
|
|
st := style.Bold(true)
|
|
|
|
wandle.Print((width-len(exitTxt))/2, height-1, st, exitTxt)
|
2015-05-18 14:47:08 +00:00
|
|
|
}
|