Things are working pretty well now

This commit is contained in:
2026-02-02 14:11:01 -06:00
parent f3c63fe95b
commit 486c07f2d4
9 changed files with 442 additions and 136 deletions

View File

@@ -43,7 +43,6 @@ type ScreenHome struct {
style tcell.Style
menuLayout *w.TopMenuLayout
menu *w.Menu
openPdsEntry *w.Field
@@ -56,11 +55,6 @@ type ScreenHome struct {
status *wd.StatusBar
stPathBlock *wd.StatusBlock
pdsListingTypes []models.EntryType
pdsNSIDs []syntax.NSID
expandedEntries map[string]interface{}
recordIdsToNSIDs map[string]syntax.NSID
cli *w.Cli
doOpen bool
@@ -74,9 +68,6 @@ func (s *ScreenHome) Init(a *App) {
s.a, s.r = a, a.repo
s.style = a.style
s.expandedEntries = make(map[string]interface{})
s.recordIdsToNSIDs = make(map[string]syntax.NSID)
s.openPdsEntry = w.NewField("home.openpds.field", s.style)
s.openPdsEntry.SetLabel("ID")
s.openPdsEntry.SetActive(true)
@@ -168,11 +159,14 @@ func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
s.toggleCli()
return true
}
m := s.menuLayout.Menu()
if ev.Key() == tcell.KeyEscape {
return s.menuLayout.HandleKey(ev)
} else if m.Active() {
return s.menuLayout.HandleKey(ev)
}
if s.doOpen {
if ev.Key() == tcell.KeyEscape {
s.doOpen = false
return true
}
if ev.Key() == tcell.KeyCtrlU {
s.openPdsEntry.SetValue("")
return true
@@ -183,6 +177,7 @@ func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
}
return s.openPdsEntry.HandleKey(ev)
}
return s.menuLayout.HandleKey(ev)
}
func (s *ScreenHome) HandleTime(ev *tcell.EventTime) {
@@ -195,8 +190,9 @@ func (s *ScreenHome) Draw() {
s.menuLayout.SetStyle(s.style.Foreground(tcell.ColorGray))
}
s.menuLayout.SetStyle(s.style)
m := s.menuLayout.Menu()
s.a.DrawWidget(s.menuLayout)
if s.doOpen {
if s.doOpen && !m.Active() {
s.a.DrawWidget(s.openPdsEntry)
}
@@ -214,10 +210,16 @@ func (s *ScreenHome) Log(t string, a ...any) {
func (s *ScreenHome) initMenu() {
s.menuLayout.SetActive(true)
var vimText = "Enable Vim Mode"
wrk := "[ ]"
if viper.GetBool(data.KeyVimMode) {
vimText = "Disable Vim Mode"
wrk = "[X]"
}
vimText := fmt.Sprintf("%s Vim Mode", wrk)
wrk = "[ ]"
if viper.GetBool(data.KeyRecNmInfer) {
wrk = "[X]"
}
inferRecNm := fmt.Sprintf("%s Infer Record Names", wrk)
s.menuLayout.AddMenuItems(
s.menuLayout.CreateMenuItem("file", "File", nil, 'f',
s.menuLayout.CreateMenuItem("file.openpds", "Open PDS", func() bool {
@@ -246,6 +248,13 @@ func (s *ScreenHome) initMenu() {
s.update()
return true
}, 'v'),
s.menuLayout.CreateMenuItem("settings.inferrecnm", inferRecNm, func() bool {
s.menuLayout.ToggleMenu()
viper.Set(data.KeyRecNmInfer, !viper.GetBool(data.KeyRecNmInfer))
viper.WriteConfig()
s.update()
return true
}, 'r'),
),
)
}
@@ -259,11 +268,17 @@ func (s *ScreenHome) update() {
s.pdsListing.SetVimMode(viper.GetBool(data.KeyVimMode))
s.jsonContent.SetVimMode(viper.GetBool(data.KeyVimMode))
vimMI := s.menuLayout.FindItem("settings.vimmode")
var vimText = "Enable Vim Mode"
wrk := "[ ]"
if viper.GetBool(data.KeyVimMode) {
vimText = "Disable Vim Mode"
wrk = "[X]"
}
vimMI.SetLabel(vimText)
vimMI.SetLabel(fmt.Sprintf("%s Vim Mode", wrk))
recNmInf := s.menuLayout.FindItem("settings.inferrecnm")
wrk = "[ ]"
if viper.GetBool(data.KeyRecNmInfer) {
wrk = "[X]"
}
recNmInf.SetLabel(fmt.Sprintf("%s Infer Record Names", wrk))
miReload := s.menuLayout.FindItem("file.reloadpds")
if s.activePds == nil {
@@ -323,7 +338,6 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
s.doOpen = false
s.cli.Log("Retrieved: %s (%s)", pds.AtId, pds.Did)
s.activePds = pds
s.expandedEntries = make(map[string]interface{})
s.updatePdsListing()
n, err := s.pdsListing.GetActiveNode()
if err == nil && n != nil {
@@ -346,7 +360,21 @@ func (s *ScreenHome) updatePdsListing() {
nsid := s.activePds.NSIDs[i]
rIds := s.activePds.GetRecordIdsFor(nsid)
for j := range rIds {
c := wd.NewTreeNode(fmt.Sprintf("%s (%s)", "record", rIds[j]), rIds[j])
label := rIds[j]
if viper.GetBool(data.KeyRecNmInfer) {
if rec, ok := s.activePds.Records[rIds[j]]; ok {
for k := range rec {
if k == "name" || k == "title" || k == "label" {
if f, ok := rec[k].(string); ok {
label = fmt.Sprintf("%s (%s)", f, rIds[j])
break
}
}
}
}
}
c := wd.NewTreeNode(label, rIds[j])
t.AddChild(c)
}
s.pdsListing.Add(t)
@@ -384,63 +412,18 @@ func (s *ScreenHome) updateStatusPathBlock(tn *wd.TreeNode) bool {
func (s *ScreenHome) updateJsonView(tn *wd.TreeNode) bool {
// TODO: Update JSON View
return true
}
/*
func (s *ScreenHome) o_selectPdsListingEntry(idx int, nm string) bool {
if !s.o_updateJsonView(idx, nm) {
return false
}
switch s.pdsListingTypes[idx] {
case models.TypeNSID:
// Expand the NSID
if _, ok := s.expandedEntries[nm]; ok {
delete(s.expandedEntries, nm)
} else {
s.expandedEntries[nm] = new(interface{})
}
s.updatePdsListing()
return true
case models.TypeRecord:
// If signed in and we can edit this, activate jsonContent
s.columns.ActivateWidget(s.jsonContent)
return true
}
return false
}
func (s *ScreenHome) o_updateJsonView(idx int, nm string) bool {
if len(s.pdsListingTypes) < idx {
s.Log("error finding pds listing type (idx: %d >= list length: %d", idx, len(s.pdsListingTypes))
return false
}
// Update the jsonContent with the list of records
switch s.pdsListingTypes[idx] {
case models.TypeNSID:
nsid, err := syntax.ParseNSID(nm)
if tn.Depth() == 0 {
nsid, err := syntax.ParseNSID(tn.Value())
if err != nil {
s.Log("error parsing NSID from %s: %w", nm, err)
s.Log("error parsing NSID from %s: %w", tn.Value(), err)
return false
}
recordIds := s.activePds.GetRecordIdsFor(nsid)
s.jsonContent.SetValue(recordIds)
return true
case models.TypeRecord:
var nsid syntax.NSID
var ok bool
nm, _ := strings.CutPrefix(nm, "• ")
if nsid, ok = s.recordIdsToNSIDs[nm]; !ok {
s.Log("error finding NSID for record %s", nm)
}
rId := fmt.Sprintf("%s/%s", nsid.String(), nm)
s.jsonContent.SetValue(s.activePds.Records[rId])
return true
} else {
s.jsonContent.SetValue(s.activePds.Records[tn.Value()])
}
return false
return true
}
*/