Initial Commit
This commit is contained in:
97
app/app.go
Normal file
97
app/app.go
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
Copyright © Brian Buller <brian@bullercodeworks.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.bullercodeworks.com/brian/expds/data"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
repo *data.Repo
|
||||
style tcell.Style
|
||||
}
|
||||
|
||||
func NewApp() *App {
|
||||
a := &App{
|
||||
style: tcell.StyleDefault.Foreground(tcell.ColorYellow),
|
||||
}
|
||||
err := a.init()
|
||||
cobra.CheckErr(err)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *App) init() error {
|
||||
var err error
|
||||
a.repo, err = data.NewRepo()
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *App) Run(args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetSize() (int, int) { return a.tScreen.Size() }
|
||||
func (a *App) GetW() int { return a.w }
|
||||
func (a *App) GetH() int { return a.h }
|
||||
|
||||
func (a *App) SetScreen(scr AppScreen) {
|
||||
a.screen = scr
|
||||
a.screen.Init(a)
|
||||
a.screen.HandleResize(tcell.NewEventResize(a.GetSize()))
|
||||
}
|
||||
|
||||
func (a *App) GetTScreen() tcell.Screen { return a.tScreen }
|
||||
|
||||
func (a *App) Stop() { a.running = false }
|
||||
func (a *App) PostNowEvent() error {
|
||||
ev := new(tcell.EventTime)
|
||||
ev.SetEventNow()
|
||||
return a.PostEvent(ev)
|
||||
}
|
||||
|
||||
func (a *App) PostEvent(ev tcell.Event) error {
|
||||
if a.tScreen != nil {
|
||||
return a.tScreen.PostEvent(ev)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (a *App) Sync() { a.tScreen.Sync() }
|
||||
func (a *App) ClearScreen() { a.tScreen.Clear() }
|
||||
func (a *App) Exit() { a.running = false }
|
||||
func (a *App) Cleanup() { a.tScreen.Fini() }
|
||||
|
||||
func (a *App) GetRepo() *data.Repo { return a.repo }
|
||||
|
||||
// Draw a rune to the screen
|
||||
func (a *DhApp) DrawRune(x, y int, style tcell.Style, r rune) {
|
||||
a.tScreen.SetContent(x, y, r, nil, style)
|
||||
}
|
||||
|
||||
// Draw text to the screen
|
||||
func (a *DhApp) DrawText(x, y int, text string, style tcell.Style) {
|
||||
h.DrawText(x, y, text, style, a.tScreen)
|
||||
}
|
||||
|
||||
// Draw a widget to the screen
|
||||
func (a *DhApp) DrawWidget(w w.Widget) { w.Draw(a.tScreen) }
|
||||
35
app/app_screen.go
Normal file
35
app/app_screen.go
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright © Brian Buller <brian@bullercodeworks.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package app
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
type AppScreen interface {
|
||||
Init(*App)
|
||||
GetName() string
|
||||
HandleResize(*tcell.EventResize)
|
||||
HandleKey(*tcell.EventKey) bool
|
||||
HandleTime(*tcell.EventTime)
|
||||
Draw()
|
||||
Log(string, ...any)
|
||||
Exit() error
|
||||
}
|
||||
113
app/screen_home.go
Normal file
113
app/screen_home.go
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
Copyright © Brian Buller <brian@bullercodeworks.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.bullercodeworks.com/brian/expds/data"
|
||||
wd "git.bullercodeworks.com/brian/expds/widgets"
|
||||
w "git.bullercodeworks.com/brian/tcell-widgets"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
type ScreenHome struct {
|
||||
a *App
|
||||
r *data.Repo
|
||||
w, h int
|
||||
style tcell.Style
|
||||
|
||||
menuLayout *w.TopMenuLayout
|
||||
menu *w.Menu
|
||||
|
||||
layout *w.LinearLayout
|
||||
|
||||
pdsListing *wd.SimpleListWithHelp
|
||||
jsonContent *wd.JsonContent
|
||||
|
||||
alert *w.Alert
|
||||
alertLayout *w.LinearLayout
|
||||
|
||||
cursor int
|
||||
}
|
||||
|
||||
func (s *ScreenHome) Init(a *App) {
|
||||
s.a, s.r = a, a.repo
|
||||
s.style = a.style
|
||||
|
||||
s.menuLayout = w.NewTopMenuLayout("home.toplayout", s.style)
|
||||
s.initMenu()
|
||||
|
||||
s.alert = w.NewAlert("home.alert", s.style)
|
||||
s.alert.SetVisible(false)
|
||||
s.alertLayout = w.NewLinearLayout("home.alertlayout", s.style)
|
||||
s.alertLayout.Add(s.alert)
|
||||
|
||||
s.layout = w.NewLinearLayout("home.layout", s.style)
|
||||
s.layout.SetOrientation(w.LinLayH)
|
||||
|
||||
s.pdsListing = wd.NewSimpleListWithHelp("pdslisting", s.style)
|
||||
s.pdsListing.SetTitle("No PDS Loaded")
|
||||
s.pdsListing.SetOnSelect(s.loadSelectedPdsListing)
|
||||
s.layout.Add(s.pdsListing)
|
||||
|
||||
s.jsonContent = wd.NewJsonContent("jsoncontent", s.style)
|
||||
s.layout.Add(s.jsonContent)
|
||||
|
||||
s.menuLayout.SetWidget(s.layout)
|
||||
}
|
||||
|
||||
func (s *ScreenHome) initMenu() {
|
||||
s.menuLayout.SetActive(true)
|
||||
menu := s.menuLayout.Menu()
|
||||
s.menuLayout.AddMenuItems(
|
||||
menu.CreateMenuItem("File", nil, 'f',
|
||||
menu.CreateMenuItem("Exit", func() bool {
|
||||
s.a.Exit()
|
||||
return true
|
||||
}, 'x'),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (s *ScreenHome) GetName() string { return "home" }
|
||||
func (s *ScreenHome) HandleResize(ev *tcell.EventResize) {
|
||||
s.w, s.h = ev.Size()
|
||||
s.menuLayout.HandleResize(ev)
|
||||
}
|
||||
|
||||
func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
|
||||
if s.alert.Visible() {
|
||||
return s.alert.HandleKey(ev)
|
||||
}
|
||||
return s.menuLayout.HandleKey(ev)
|
||||
}
|
||||
|
||||
func (s *ScreenHome) HandleTime(ev *tcell.EventTime) { s.menuLayout.HandleTime(ev) }
|
||||
|
||||
func (s *ScreenHome) Draw() { s.a.DrawWidget(s.menuLayout) }
|
||||
|
||||
func (s *ScreenHome) Exit() error { return nil }
|
||||
|
||||
func (s *ScreenHome) Log(t string, a ...any) {}
|
||||
|
||||
func (s *ScreenHome) loadSelectedPdsListing(idx int, nm string) bool {
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user