Functional, needs some polish
This commit is contained in:
@@ -49,7 +49,7 @@ type App struct {
|
||||
|
||||
func NewApp() *App {
|
||||
a := &App{
|
||||
style: tcell.StyleDefault.Foreground(tcell.ColorYellow),
|
||||
style: tcell.StyleDefault.Foreground(tcell.ColorLime),
|
||||
}
|
||||
err := a.init()
|
||||
cobra.CheckErr(err)
|
||||
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
"git.bullercodeworks.com/brian/expds/data/models"
|
||||
wd "git.bullercodeworks.com/brian/expds/widgets"
|
||||
w "git.bullercodeworks.com/brian/tcell-widgets"
|
||||
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
||||
"github.com/bluesky-social/indigo/atproto/syntax"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/spf13/viper"
|
||||
@@ -48,7 +47,7 @@ type ScreenHome struct {
|
||||
columns *w.LinearLayout
|
||||
|
||||
activePds *models.Pds
|
||||
pdsListing *wd.SimpleListWithHelp
|
||||
pdsListing *w.SimpleListWithHelp
|
||||
jsonContent *wd.JsonContent
|
||||
|
||||
pdsListingTypes []models.EntryType
|
||||
@@ -61,6 +60,11 @@ type ScreenHome struct {
|
||||
|
||||
cli *w.Cli
|
||||
|
||||
isLoading bool
|
||||
loading *w.Spinner
|
||||
loadingFrame *w.Text
|
||||
pdsStatus *w.Text
|
||||
|
||||
cursor int
|
||||
}
|
||||
|
||||
@@ -71,6 +75,18 @@ func (s *ScreenHome) Init(a *App) {
|
||||
s.expandedEntries = make(map[string]interface{})
|
||||
s.recordIdsToNSIDs = make(map[string]syntax.NSID)
|
||||
|
||||
s.isLoading = true
|
||||
|
||||
s.loadingFrame = w.NewText("home.loadingframe", s.style)
|
||||
s.loadingFrame.SetText("┤ ├")
|
||||
s.loadingFrame.SetPos(w.Coord{X: 1, Y: 1})
|
||||
s.pdsStatus = w.NewText("home.pdsstatus", s.style.Foreground(tcell.ColorRed))
|
||||
s.pdsStatus.SetText("𐄂")
|
||||
s.pdsStatus.SetPos(w.Coord{X: 2, Y: 1})
|
||||
s.loading = w.NewSpinner("home.loading", s.style)
|
||||
s.loading.SetVisible(true)
|
||||
s.loading.SetPos(w.Coord{X: 2, Y: 1})
|
||||
|
||||
s.menuLayout = w.NewTopMenuLayout("home.toplayout", s.style)
|
||||
s.initMenu()
|
||||
|
||||
@@ -87,16 +103,22 @@ func (s *ScreenHome) Init(a *App) {
|
||||
s.columns = w.NewLinearLayout("home.layout.columns", s.style)
|
||||
s.columns.SetOrientation(w.LinLayH)
|
||||
|
||||
s.pdsListing = wd.NewSimpleListWithHelp("pdslisting", s.style)
|
||||
s.pdsListing.SetBorder(h.BRD_SIMPLE)
|
||||
s.pdsListing.SetTitle("No PDS Loaded")
|
||||
s.pdsListing = w.NewSimpleListWithHelp("pdslisting", s.style)
|
||||
s.pdsListing.SetBorder(
|
||||
[]rune{'─', '┬', '│', '┴', '─', '└', '│', '┌', '├', '─', '┤', '┬', '│', '┴', '┼'},
|
||||
)
|
||||
s.pdsListing.SetTitle("─── No PDS Loaded")
|
||||
s.pdsListing.SetOnSelect(s.selectPdsListingEntry)
|
||||
s.pdsListing.SetOnChange(s.updateJsonView)
|
||||
s.pdsListing.SetVimMode(viper.GetBool(data.KeyVimMode))
|
||||
|
||||
s.jsonContent = wd.NewJsonContent("jsoncontent", s.style)
|
||||
brd := w.NewBorderedWidget("jsoncontentbrd", s.style, s.jsonContent)
|
||||
brd.SetBorder(
|
||||
[]rune{'─', '┐', '│', '┘', '─', '─', ' ', '─', '├', '─', '┤', '┬', '│', '┴', '┼'},
|
||||
)
|
||||
|
||||
s.columns.AddAll(s.pdsListing, s.jsonContent)
|
||||
s.columns.AddAll(s.pdsListing, brd)
|
||||
|
||||
s.layout.AddAll(s.columns, s.cli)
|
||||
s.layout.SetWeight(s.columns, 4)
|
||||
@@ -120,9 +142,19 @@ func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
|
||||
|
||||
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) HandleTime(ev *tcell.EventTime) {
|
||||
s.menuLayout.HandleTime(ev)
|
||||
s.loading.HandleTime(ev)
|
||||
}
|
||||
func (s *ScreenHome) Draw() {
|
||||
s.a.DrawWidget(s.menuLayout)
|
||||
|
||||
// These are outside of the menuLayout
|
||||
//s.a.DrawWidget(s.loadingFrame)
|
||||
//s.a.DrawWidget(s.loading)
|
||||
//s.a.DrawWidget(s.pdsStatus)
|
||||
}
|
||||
func (s *ScreenHome) Exit() error { return nil }
|
||||
func (s *ScreenHome) Log(t string, a ...any) {
|
||||
s.cli.Log(t, a...)
|
||||
s.showCli()
|
||||
@@ -130,16 +162,25 @@ func (s *ScreenHome) Log(t string, a ...any) {
|
||||
|
||||
func (s *ScreenHome) initMenu() {
|
||||
s.menuLayout.SetActive(true)
|
||||
menu := s.menuLayout.Menu()
|
||||
var vimText = "Enable Vim Mode"
|
||||
if viper.GetBool(data.KeyVimMode) {
|
||||
vimText = "Disable Vim Mode"
|
||||
}
|
||||
s.menuLayout.AddMenuItems(
|
||||
menu.CreateMenuItem("File", nil, 'f',
|
||||
menu.CreateMenuItem("Exit", func() bool {
|
||||
s.menuLayout.CreateMenuItem("file", "File", nil, 'f',
|
||||
s.menuLayout.CreateMenuItem("file.reloadpds", "Reload PDS", func() bool {
|
||||
if s.activePds == nil {
|
||||
return false
|
||||
}
|
||||
return s.cliGetPds("getpds", s.activePds.AtId.String())
|
||||
}, 'r'),
|
||||
s.menuLayout.CreateMenuItem("file.exit", "Exit", func() bool {
|
||||
s.a.Exit()
|
||||
return true
|
||||
}, 'x'),
|
||||
),
|
||||
menu.CreateMenuItem("Settings", nil, 's',
|
||||
menu.CreateMenuItem("Toggle Vim Mode", func() bool {
|
||||
s.menuLayout.CreateMenuItem("settings", "Settings", nil, 's',
|
||||
s.menuLayout.CreateMenuItem("settings.vimmode", vimText, func() bool {
|
||||
viper.Set(data.KeyVimMode, !viper.GetBool(data.KeyVimMode))
|
||||
viper.WriteConfig()
|
||||
s.update()
|
||||
@@ -149,8 +190,42 @@ func (s *ScreenHome) initMenu() {
|
||||
)
|
||||
}
|
||||
|
||||
func (s *ScreenHome) setPdsStatusLoading() {
|
||||
s.loading.SetVisible(true)
|
||||
s.pdsStatus.SetVisible(false)
|
||||
s.pdsStatus.SetStyle(s.style.Foreground(tcell.ColorLime))
|
||||
s.pdsStatus.SetText(" ")
|
||||
}
|
||||
func (s *ScreenHome) setPdsStatusGood() {
|
||||
s.loading.SetVisible(false)
|
||||
s.pdsStatus.SetVisible(true)
|
||||
s.pdsStatus.SetStyle(s.style.Foreground(tcell.ColorLime))
|
||||
s.pdsStatus.SetText("✔")
|
||||
}
|
||||
func (s *ScreenHome) setPdsStatusBad() {
|
||||
s.loading.SetVisible(false)
|
||||
s.pdsStatus.SetVisible(true)
|
||||
s.pdsStatus.SetStyle(s.style.Foreground(tcell.ColorRed))
|
||||
s.pdsStatus.SetText("𐄂")
|
||||
}
|
||||
|
||||
func (s *ScreenHome) update() {
|
||||
s.pdsListing.SetVimMode(viper.GetBool(data.KeyVimMode))
|
||||
vimMI := s.menuLayout.FindItem("settings.vimmode")
|
||||
var vimText = "Enable Vim Mode"
|
||||
if viper.GetBool(data.KeyVimMode) {
|
||||
vimText = "Disable Vim Mode"
|
||||
}
|
||||
vimMI.SetLabel(vimText)
|
||||
|
||||
miReload := s.menuLayout.FindItem("file.reloadpds")
|
||||
if s.activePds == nil {
|
||||
miReload.SetDisabled(true)
|
||||
miReload.SetStyle(s.style.Foreground(tcell.ColorGray))
|
||||
} else {
|
||||
miReload.SetDisabled(false)
|
||||
miReload.SetStyle(s.style.Foreground(tcell.ColorLime))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ScreenHome) initCli() {
|
||||
@@ -177,26 +252,31 @@ func (s *ScreenHome) showCli() {
|
||||
}
|
||||
|
||||
func (s *ScreenHome) cliGetPds(args ...string) bool {
|
||||
if len(args) == 0 {
|
||||
s.isLoading = true
|
||||
if len(args) < 1 {
|
||||
s.Log("No id given.")
|
||||
s.Log("Usage: 'getpds <atproto id>'")
|
||||
s.isLoading = false
|
||||
return true
|
||||
}
|
||||
pds, err := s.r.GetPDS(args[1])
|
||||
if err != nil {
|
||||
s.cli.Log(err.Error())
|
||||
return true
|
||||
}
|
||||
s.cli.Log("Retrieved: %s (%s)", pds.AtId, pds.Did)
|
||||
s.activePds = pds
|
||||
s.expandedEntries = make(map[string]interface{})
|
||||
s.updatePdsListing()
|
||||
s.updateJsonView(s.pdsListing.SelectedIndex(), s.pdsListing.GetSelectedItem())
|
||||
go func() {
|
||||
pds, err := s.r.GetPDS(args[1])
|
||||
if err != nil {
|
||||
s.cli.Log(err.Error())
|
||||
s.isLoading = false
|
||||
}
|
||||
s.cli.Log("Retrieved: %s (%s)", pds.AtId, pds.Did)
|
||||
s.activePds = pds
|
||||
s.expandedEntries = make(map[string]interface{})
|
||||
s.updatePdsListing()
|
||||
s.updateJsonView(s.pdsListing.SelectedIndex(), s.pdsListing.GetSelectedItem())
|
||||
s.isLoading = false
|
||||
}()
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *ScreenHome) updatePdsListing() {
|
||||
s.pdsListing.SetTitle(fmt.Sprintf("%s (%s)", s.activePds.AtId.String(), s.activePds.Did.String()))
|
||||
s.pdsListing.SetTitle(fmt.Sprintf("─── %s (%s)", s.activePds.AtId.String(), s.activePds.Did.String()))
|
||||
// When we first get the pds, all entries are models.TypeNSID
|
||||
s.pdsListingTypes = []models.EntryType{}
|
||||
s.recordIdsToNSIDs = make(map[string]syntax.NSID)
|
||||
|
||||
Reference in New Issue
Block a user