Started Work on v3
This commit is contained in:
170
ui/screen_about.go
Normal file
170
ui/screen_about.go
Normal file
@@ -0,0 +1,170 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.bullercodeworks.com/brian/wandle"
|
||||
"github.com/nsf/termbox-go"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const (
|
||||
ABT_CmdGotoBrowse = AboutId | iota
|
||||
)
|
||||
|
||||
type AboutMsg struct {
|
||||
source int
|
||||
data interface{}
|
||||
err error
|
||||
}
|
||||
|
||||
type aboutScreen struct {
|
||||
ui *Ui
|
||||
|
||||
commands1 []Command
|
||||
commands2 []Command
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
key string
|
||||
description string
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (s *aboutScreen) handleAboutMsg(msg AboutMsg) wandle.Cmd {
|
||||
switch msg.source {
|
||||
case ABT_CmdGotoBrowse:
|
||||
return wandle.SwitchScreenCmd(s.ui.browseScreen)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *aboutScreen) handleTermboxEvent(msg termbox.Event) wandle.Cmd {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *aboutScreen) View(style wandle.Style) {
|
||||
width, height := termbox.Size()
|
||||
template := [...]string{
|
||||
" _______ _______ ___ _______ _______ ______ _______ _ _ _______ _______ ______ ",
|
||||
"| _ || || | | || _ || _ | | || | _ | || || || _ | ",
|
||||
"| |_| || _ || | |_ _|| |_| || | || | _ || || || || _____|| ___|| | || ",
|
||||
"| || | | || | | | | || |_||_ | | | || || |_____ | |___ | |_||_ ",
|
||||
"| _ | | |_| || |___ | | | _ | | __ || |_| || ||_____ || ___|| __ |",
|
||||
"| |_| || || || | | |_| || | | || || _ | _____| || |___ | | | |",
|
||||
"|_______||_______||_______||___| |_______||___| |_||_______||__| |__||_______||_______||___| |_|",
|
||||
}
|
||||
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
|
||||
if height <= 20 {
|
||||
title := "BoltBrowser"
|
||||
startY = 0
|
||||
yPos = 0
|
||||
wandle.Print((width-len(title))/2, startY, style, title)
|
||||
} else {
|
||||
if height < 25 {
|
||||
startY = 0
|
||||
yPos = 0
|
||||
}
|
||||
for _, line := range template {
|
||||
xPos = startX
|
||||
for _, runeValue := range line {
|
||||
displayRune := ' '
|
||||
if runeValue != ' ' {
|
||||
displayRune = runeValue
|
||||
termbox.SetCell(xPos, yPos, displayRune, style.Foreground, style.Background)
|
||||
}
|
||||
xPos++
|
||||
}
|
||||
yPos++
|
||||
}
|
||||
}
|
||||
yPos++
|
||||
versionString := fmt.Sprintf("Version: %0.1f", viper.GetFloat64("version"))
|
||||
wandle.Print((width-len(versionString))/2, yPos, style, versionString)
|
||||
var maxCmd1 int
|
||||
for k := range s.commands1 {
|
||||
tst := len(s.commands1[k].key) + 1 + len(s.commands1[k].description)
|
||||
if tst > maxCmd1 {
|
||||
maxCmd1 = tst
|
||||
}
|
||||
}
|
||||
var maxCmd2 int
|
||||
for k := range s.commands2 {
|
||||
tst := len(s.commands2[k].key) + 1 + len(s.commands2[k].description)
|
||||
if tst > maxCmd2 {
|
||||
maxCmd2 = tst
|
||||
}
|
||||
}
|
||||
xPos = (width / 2) - ((maxCmd1 + maxCmd2) / 2)
|
||||
yPos++
|
||||
|
||||
for k, cmd := range s.commands1 {
|
||||
wandle.Print(xPos, yPos+1+k, style, fmt.Sprintf("%6s %s", cmd.key, cmd.description))
|
||||
}
|
||||
for k, cmd := range s.commands2 {
|
||||
wandle.Print(xPos+40, yPos+1+k, style, fmt.Sprintf("%6s %s", cmd.key, cmd.description))
|
||||
}
|
||||
exitTxt := "Press any key to return to browser"
|
||||
st := style.Bold(true)
|
||||
wandle.Print((width-len(exitTxt))/2, height-1, st, exitTxt)
|
||||
}
|
75
ui/screen_browse.go
Normal file
75
ui/screen_browse.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/wandle"
|
||||
"git.bullercodeworks.com/brian/widdles"
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
const (
|
||||
//BS_CmdGotoAbout = BrowseId | iota
|
||||
)
|
||||
|
||||
type BrowseMsg struct {
|
||||
source int
|
||||
data interface{}
|
||||
err error
|
||||
}
|
||||
|
||||
type browseScreen struct {
|
||||
ui *Ui
|
||||
dbPath string
|
||||
|
||||
menu *widdles.TopMenu
|
||||
status *widdles.Text
|
||||
statusTimeout time.Duration
|
||||
statusTime time.Time
|
||||
}
|
||||
|
||||
func NewBrowseScreen(u *Ui) *browseScreen {
|
||||
w, h := termbox.Size()
|
||||
return &browseScreen{
|
||||
ui: u,
|
||||
menu: widdles.NewTopMenu(0, 0, w),
|
||||
status: widdles.NewText("", 0, h),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *browseScreen) Init() wandle.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *browseScreen) Update(msg wandle.Msg) wandle.Cmd {
|
||||
switch msg := msg.(type) {
|
||||
case BrowseMsg:
|
||||
return s.handleBrowseMsg(msg)
|
||||
case termbox.Event:
|
||||
return s.handleTermboxEvent(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *browseScreen) handleBrowseMsg(msg BrowseMsg) wandle.Cmd {
|
||||
switch msg.source {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *browseScreen) handleTermboxEvent(msg termbox.Event) wandle.Cmd {
|
||||
if (msg.Type == termbox.EventKey && msg.Key == termbox.KeyEsc) || s.menu.IsActive() {
|
||||
return s.menu.Update(msg)
|
||||
}
|
||||
switch msg.Type {
|
||||
case termbox.EventKey:
|
||||
if msg.Ch == '?' {
|
||||
return wandle.SwitchScreenCmd(NewAboutScreen(s.ui))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *browseScreen) View(style wandle.Style) {
|
||||
}
|
31
ui/ui.go
Normal file
31
ui/ui.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.bullercodeworks.com/brian/wandle"
|
||||
)
|
||||
|
||||
const (
|
||||
BrowseId = iota << 5
|
||||
AboutId
|
||||
)
|
||||
|
||||
type Ui struct {
|
||||
config Config
|
||||
wandle *wandle.Program
|
||||
|
||||
browseScreen *browseScreen
|
||||
}
|
||||
|
||||
func NewUi() *Ui {
|
||||
u := new(Ui)
|
||||
u.browseScreen = NewBrowseScreen(u)
|
||||
u.config = Config{
|
||||
sep: string(os.PathSeparator),
|
||||
}
|
||||
u.wandle = wandle.NewProgram(u.browseScreen)
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *Ui) Start() error { return u.wandle.Start() }
|
Reference in New Issue
Block a user