Some work
This commit is contained in:
@@ -24,6 +24,7 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/expds/data"
|
||||
"git.bullercodeworks.com/brian/expds/data/models"
|
||||
@@ -31,6 +32,7 @@ import (
|
||||
w "git.bullercodeworks.com/brian/tcell-widgets"
|
||||
"github.com/bluesky-social/indigo/atproto/syntax"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
"github.com/spf13/viper"
|
||||
"golang.design/x/clipboard"
|
||||
)
|
||||
@@ -52,6 +54,9 @@ type ScreenHome struct {
|
||||
activePds *models.Pds
|
||||
pdsListing *w.SimpleListWithHelp
|
||||
jsonContent *wd.JsonContent
|
||||
status *wd.StatusBar
|
||||
stDtTmBlock *wd.StatusBlock
|
||||
stPathBlock *wd.StatusBlock
|
||||
|
||||
pdsListingTypes []models.EntryType
|
||||
pdsNSIDs []syntax.NSID
|
||||
@@ -120,11 +125,28 @@ func (s *ScreenHome) Init(a *App) {
|
||||
clipboard.Write(clipboard.FmtText, []byte(s.jsonContent.GetSelectedValue()))
|
||||
return true
|
||||
}),
|
||||
w.NewKey(w.BuildEKr('O'), func(ev *tcell.EventKey) bool {
|
||||
url := fmt.Sprintf("https://%s/xrpc/com.atproto.sync.getBlob?did=did:plc:pqwuemo2ic5tqmpwrajb2phi&cid=%s", s.activePds.AtId.String(), s.jsonContent.GetSelectedValue())
|
||||
open.Run(url)
|
||||
return true
|
||||
}),
|
||||
)
|
||||
s.jsonContent.SetKeyMap(km)
|
||||
s.jsonContent.SetBorder(
|
||||
[]rune{'─', '┐', '│', '┘', '─', '─', ' ', '─', '├', '─', '┤', '┬', '│', '┴', '┼'},
|
||||
)
|
||||
s.status = wd.NewStatusBar("home.statusbar", s.style)
|
||||
s.status.SetPos(w.Coord{X: 0, Y: s.a.GetH() - 1})
|
||||
s.status.SetLogger(s.Log)
|
||||
s.stPathBlock = wd.NewStatusBlock("home.statusbar.block", s.style.Background(tcell.ColorOrange).Foreground(tcell.ColorBlack))
|
||||
s.stPathBlock.SetType(wd.SBTypePath)
|
||||
s.status.Add(s.stPathBlock)
|
||||
s.stPathBlock.SetParts([]string{"dir1", "dir2", "dir3"})
|
||||
s.stDtTmBlock = wd.NewStatusBlock("home.statusbar.dttm", s.style.Background(tcell.ColorOrange).Foreground(tcell.ColorBlack))
|
||||
s.stDtTmBlock.SetType(wd.SBTypeText)
|
||||
s.status.Add(s.stDtTmBlock)
|
||||
s.status.SetFlag(s.stDtTmBlock, w.LFAlignHRight)
|
||||
|
||||
s.columns.AddAll(s.pdsListing, s.jsonContent)
|
||||
|
||||
s.layout.AddAll(s.columns)
|
||||
@@ -135,7 +157,9 @@ func (s *ScreenHome) Init(a *App) {
|
||||
func (s *ScreenHome) GetName() string { return "home" }
|
||||
func (s *ScreenHome) HandleResize(ev *tcell.EventResize) {
|
||||
s.w, s.h = ev.Size()
|
||||
s.menuLayout.HandleResize(ev)
|
||||
s.menuLayout.HandleResize(w.Coord{X: s.w, Y: s.h - 1}.ResizeEvent())
|
||||
s.status.SetPos(w.Coord{X: 0, Y: s.h - 1})
|
||||
s.status.HandleResize(w.Coord{X: s.w, Y: 1}.ResizeEvent())
|
||||
}
|
||||
|
||||
func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
|
||||
@@ -164,6 +188,7 @@ func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
|
||||
func (s *ScreenHome) HandleTime(ev *tcell.EventTime) {
|
||||
s.menuLayout.HandleTime(ev)
|
||||
s.loading.HandleTime(ev)
|
||||
s.stDtTmBlock.SetText(time.Now().Format(time.Kitchen))
|
||||
}
|
||||
func (s *ScreenHome) Draw() {
|
||||
if s.doOpen {
|
||||
@@ -179,6 +204,7 @@ func (s *ScreenHome) Draw() {
|
||||
if s.isLoading {
|
||||
s.a.DrawWidget(s.loading)
|
||||
}
|
||||
s.a.DrawWidget(s.status)
|
||||
}
|
||||
func (s *ScreenHome) Exit() error { return nil }
|
||||
func (s *ScreenHome) Log(t string, a ...any) {
|
||||
@@ -231,6 +257,7 @@ func (s *ScreenHome) update() {
|
||||
s.menuLayout.SetWidget(s.layout)
|
||||
}
|
||||
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"
|
||||
if viper.GetBool(data.KeyVimMode) {
|
||||
@@ -353,6 +380,25 @@ func (s *ScreenHome) selectPdsListingEntry(idx int, nm string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *ScreenHome) changePdsList(idx int, nm string) bool {
|
||||
upd := s.updateJsonView(idx, nm)
|
||||
upd = s.updateStatusPathBlock(idx, nm)
|
||||
return upd
|
||||
}
|
||||
func (s *ScreenHome) updateStatusPathBlock(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
|
||||
}
|
||||
switch s.pdsListingTypes[idx] {
|
||||
case models.TypeNSID:
|
||||
s.stPathBlock.SetParts([]string{nm})
|
||||
case models.TypeRecord:
|
||||
nsidNm := s.activePds.GetNSIDForRecordId(nm).String()
|
||||
s.stPathBlock.SetParts([]string{nsidNm, nm})
|
||||
}
|
||||
return true
|
||||
}
|
||||
func (s *ScreenHome) 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))
|
||||
|
||||
@@ -56,6 +56,7 @@ type Pds struct {
|
||||
NSIDs []syntax.NSID
|
||||
RecordIds []string
|
||||
nsidToRecordIds map[syntax.NSID][]string
|
||||
recordIdsToNSID map[string]syntax.NSID
|
||||
Records map[string]map[string]any
|
||||
|
||||
RefreshTime time.Time
|
||||
@@ -96,6 +97,7 @@ func NewPdsFromDid(id string) (*Pds, error) {
|
||||
Did: ident.DID,
|
||||
localPath: carPath,
|
||||
nsidToRecordIds: make(map[syntax.NSID][]string),
|
||||
recordIdsToNSID: make(map[string]syntax.NSID),
|
||||
Records: make(map[string]map[string]any),
|
||||
RefreshTime: time.Now(),
|
||||
}
|
||||
@@ -142,6 +144,7 @@ func (p *Pds) unpack() error {
|
||||
p.NSIDs = append(p.NSIDs, col)
|
||||
}
|
||||
p.nsidToRecordIds[col] = append(p.nsidToRecordIds[col], sRKey)
|
||||
p.recordIdsToNSID[sRKey] = col
|
||||
return nil
|
||||
})
|
||||
//slices.Sort(p.NSIDs)
|
||||
@@ -179,4 +182,5 @@ func (p *Pds) List() (map[string]string, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (p *Pds) GetRecordIdsFor(n syntax.NSID) []string { return p.nsidToRecordIds[n] }
|
||||
func (p *Pds) GetRecordIdsFor(n syntax.NSID) []string { return p.nsidToRecordIds[n] }
|
||||
func (p *Pds) GetNSIDForRecordId(rId string) syntax.NSID { return p.recordIdsToNSID[rId] }
|
||||
|
||||
1
go.mod
1
go.mod
@@ -8,6 +8,7 @@ require (
|
||||
github.com/gdamore/tcell v1.4.1
|
||||
github.com/ipfs/go-cid v0.4.1
|
||||
github.com/muesli/go-app-paths v0.2.2
|
||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
|
||||
github.com/spf13/cobra v1.10.2
|
||||
github.com/spf13/viper v1.21.0
|
||||
golang.design/x/clipboard v0.7.1
|
||||
|
||||
2
go.sum
2
go.sum
@@ -165,6 +165,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
|
||||
github.com/sagikazarmark/locafero v0.12.0 h1:/NQhBAkUb4+fH1jivKHWusDYFjMOOKU88eegjfxfHb4=
|
||||
github.com/sagikazarmark/locafero v0.12.0/go.mod h1:sZh36u/YSZ918v0Io+U9ogLYQJ9tLLBmM4eneO6WwsI=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA=
|
||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
|
||||
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
|
||||
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
|
||||
|
||||
@@ -71,9 +71,7 @@ func (w *JsonContent) Init(id string, style tcell.Style) {
|
||||
w.keyMap = wd.NewKeyMap(
|
||||
wd.NewKey(wd.BuildEK(tcell.KeyUp), func(_ *tcell.EventKey) bool { return w.MoveUp() }),
|
||||
wd.NewKey(wd.BuildEK(tcell.KeyDown), func(_ *tcell.EventKey) bool { return w.MoveDown() }),
|
||||
wd.NewKey(wd.BuildEK(tcell.KeyEnter), func(ev *tcell.EventKey) bool {
|
||||
return false
|
||||
}),
|
||||
wd.NewKey(wd.BuildEK(tcell.KeyEnter), func(ev *tcell.EventKey) bool { return false }),
|
||||
wd.NewKey(wd.BuildEK(tcell.KeyPgDn), func(_ *tcell.EventKey) bool { return w.PageDn() }),
|
||||
wd.NewKey(wd.BuildEK(tcell.KeyPgUp), func(_ *tcell.EventKey) bool { return w.PageUp() }),
|
||||
wd.NewKey(wd.BuildEKr('j'), func(ev *tcell.EventKey) bool {
|
||||
|
||||
@@ -34,6 +34,9 @@ type StatusBar struct {
|
||||
visible bool
|
||||
keyMap *t.KeyMap
|
||||
|
||||
blocks []*StatusBlock
|
||||
blockFlags map[*StatusBlock]t.LayoutFlag
|
||||
|
||||
logger func(string, ...any)
|
||||
}
|
||||
|
||||
@@ -47,11 +50,56 @@ func (w *StatusBar) Init(id string, s tcell.Style) {
|
||||
w.id = id
|
||||
w.style = s
|
||||
w.visible = true
|
||||
w.blockFlags = make(map[*StatusBlock]t.LayoutFlag)
|
||||
}
|
||||
|
||||
func (w *StatusBar) Id() string { return w.id }
|
||||
func (w *StatusBar) HandleResize(ev *tcell.EventResize) {
|
||||
w.w, w.h = ev.Size()
|
||||
// First, all blocks that are Left Aligned (or no alignment)
|
||||
x := w.x
|
||||
for i := range w.blocks {
|
||||
f, ok := w.blockFlags[w.blocks[i]]
|
||||
if !ok || (f&t.LFAlignLeft != 0 || f&t.LFAlignH == 0) {
|
||||
w.blocks[i].SetPos(t.Coord{X: x, Y: w.y})
|
||||
x += w.blocks[i].Width()
|
||||
}
|
||||
}
|
||||
// Center Aligned
|
||||
// First, get the width of all center blocks
|
||||
var cW int
|
||||
for i := range w.blocks {
|
||||
f, ok := w.blockFlags[w.blocks[i]]
|
||||
if ok && (f&t.LFAlignCenter != 0) {
|
||||
cW += w.blocks[i].Width()
|
||||
}
|
||||
}
|
||||
x = w.x + (w.w / 2) - (cW / 2)
|
||||
for i := range w.blocks {
|
||||
f, ok := w.blockFlags[w.blocks[i]]
|
||||
if ok && (f&t.LFAlignCenter != 0) {
|
||||
w.blocks[i].SetPos(t.Coord{X: x, Y: w.y})
|
||||
x += w.blocks[i].Width()
|
||||
}
|
||||
}
|
||||
|
||||
// Right Aligned
|
||||
// First, get the width of all Right Aligned blocks
|
||||
cW = 0
|
||||
for i := range w.blocks {
|
||||
f, ok := w.blockFlags[w.blocks[i]]
|
||||
if ok && (f&t.LFAlignCenter != 0) {
|
||||
cW += w.blocks[i].Width()
|
||||
}
|
||||
}
|
||||
x = w.x + w.w - cW
|
||||
for i := range w.blocks {
|
||||
f, ok := w.blockFlags[w.blocks[i]]
|
||||
if ok && (f&t.LFAlignRight != 0) {
|
||||
w.blocks[i].SetPos(t.Coord{X: x, Y: w.y})
|
||||
x += w.blocks[i].Width()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *StatusBar) GetKeyMap() *t.KeyMap { return w.keyMap }
|
||||
@@ -64,33 +112,48 @@ func (w *StatusBar) HandleKey(ev *tcell.EventKey) bool {
|
||||
func (w *StatusBar) HandleTime(ev *tcell.EventTime) {}
|
||||
|
||||
func (w *StatusBar) Draw(screen tcell.Screen) {
|
||||
//th.DrawText(w.x, w.y, fmt.Sprintf("StatusBar: %d,%d", w.x, w.y), w.style, screen)
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
for i := range w.blocks {
|
||||
w.Log("Drawing Block %d @ %d,%d", i, w.blocks[i].x, w.blocks[i].y)
|
||||
w.blocks[i].Draw(screen)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *StatusBar) SetStyle(s tcell.Style) { w.style = s }
|
||||
func (w *StatusBar) Active() bool { return false }
|
||||
func (w *StatusBar) SetActive(a bool) {}
|
||||
func (w *StatusBar) Visible() bool { return w.visible }
|
||||
func (w *StatusBar) SetVisible(a bool) { w.visible = a }
|
||||
func (w *StatusBar) Focusable() bool { return false }
|
||||
func (w *StatusBar) SetFocusable(b bool) {}
|
||||
func (w *StatusBar) SetX(x int) { w.x = x }
|
||||
func (w *StatusBar) SetY(y int) { w.y = y }
|
||||
func (w *StatusBar) GetX() int { return w.x }
|
||||
func (w *StatusBar) GetY() int { return w.y }
|
||||
func (w *StatusBar) GetPos() t.Coord { return t.Coord{X: w.x, Y: w.y} }
|
||||
func (w *StatusBar) SetPos(c t.Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *StatusBar) GetW() int { return w.w }
|
||||
func (w *StatusBar) GetH() int { return w.h }
|
||||
func (w *StatusBar) SetW(wd int) { w.w = wd }
|
||||
func (w *StatusBar) SetH(h int) { w.h = h }
|
||||
func (w *StatusBar) SetSize(c t.Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *StatusBar) WantW() int { return w.w }
|
||||
func (w *StatusBar) WantH() int { return w.h }
|
||||
func (w *StatusBar) MinW() int { return w.w }
|
||||
func (w *StatusBar) MinH() int { return 1 }
|
||||
|
||||
func (w *StatusBar) SetStyle(s tcell.Style) { w.style = s }
|
||||
func (w *StatusBar) Active() bool { return false }
|
||||
func (w *StatusBar) SetActive(a bool) {}
|
||||
func (w *StatusBar) Visible() bool { return w.visible }
|
||||
func (w *StatusBar) SetVisible(a bool) { w.visible = a }
|
||||
func (w *StatusBar) Focusable() bool { return false }
|
||||
func (w *StatusBar) SetFocusable(b bool) {}
|
||||
func (w *StatusBar) SetX(x int) { w.x = x }
|
||||
func (w *StatusBar) SetY(y int) { w.y = y }
|
||||
func (w *StatusBar) GetX() int { return w.x }
|
||||
func (w *StatusBar) GetY() int { return w.y }
|
||||
func (w *StatusBar) GetPos() t.Coord { return t.Coord{X: w.x, Y: w.y} }
|
||||
func (w *StatusBar) SetPos(c t.Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *StatusBar) GetW() int { return w.w }
|
||||
func (w *StatusBar) GetH() int { return w.h }
|
||||
func (w *StatusBar) SetW(wd int) { w.w = wd }
|
||||
func (w *StatusBar) SetH(h int) { w.h = h }
|
||||
func (w *StatusBar) SetSize(c t.Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *StatusBar) WantW() int { return w.w }
|
||||
func (w *StatusBar) WantH() int { return w.h }
|
||||
func (w *StatusBar) MinW() int { return w.w }
|
||||
func (w *StatusBar) MinH() int { return 1 }
|
||||
func (w *StatusBar) SetLogger(l func(string, ...any)) { w.logger = l }
|
||||
func (w *StatusBar) Log(txt string, args ...any) { w.logger(txt, args...) }
|
||||
|
||||
func (w *StatusBar) Add(b *StatusBlock) { w.blocks = append(w.blocks, b) }
|
||||
func (w *StatusBar) SetFlag(b *StatusBlock, f t.LayoutFlag) {
|
||||
if _, ok := w.blockFlags[b]; ok {
|
||||
w.blockFlags[b].Add(f)
|
||||
} else {
|
||||
w.blockFlags[b] = f
|
||||
}
|
||||
}
|
||||
func (w *StatusBar) RemoveFlag(b *StatusBlock, f t.LayoutFlag) { w.blockFlags[b].Remove(f) }
|
||||
func (w *StatusBar) ClearFlags(b *StatusBlock) { delete(w.blockFlags, b) }
|
||||
|
||||
78
widgets/status_bar_block.go
Normal file
78
widgets/status_bar_block.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
t "git.bullercodeworks.com/brian/tcell-widgets"
|
||||
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
/*
|
||||
StatusBlock is not a widget type, they're meant to be used within a StatusBar
|
||||
*/
|
||||
type StatusBlock struct {
|
||||
id string
|
||||
style tcell.Style
|
||||
x, y int
|
||||
|
||||
tp int
|
||||
parts []string
|
||||
text string
|
||||
|
||||
separator string
|
||||
}
|
||||
|
||||
const (
|
||||
SBTypeText = iota
|
||||
SBTypePath
|
||||
)
|
||||
|
||||
func NewStatusBlock(id string, s tcell.Style) *StatusBlock {
|
||||
b := StatusBlock{
|
||||
id: id, style: s,
|
||||
separator: " ",
|
||||
}
|
||||
return &b
|
||||
}
|
||||
|
||||
func (b *StatusBlock) SetPos(p t.Coord) { b.x, b.y = p.X, p.Y }
|
||||
func (b *StatusBlock) Width() int {
|
||||
switch b.tp {
|
||||
case SBTypePath:
|
||||
return len(strings.Join(b.parts, b.separator))
|
||||
default:
|
||||
return len(b.text)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *StatusBlock) SetType(tp int) {
|
||||
switch tp {
|
||||
case SBTypeText:
|
||||
b.tp = tp
|
||||
default:
|
||||
b.tp = SBTypeText
|
||||
}
|
||||
}
|
||||
func (b *StatusBlock) SetParts(pts []string) { b.parts = pts }
|
||||
func (b *StatusBlock) AddPart(p string) { b.parts = append(b.parts, p) }
|
||||
func (b *StatusBlock) SetText(t string) { b.text = t }
|
||||
|
||||
func (b *StatusBlock) Draw(screen tcell.Screen) {
|
||||
//wh.DrawText(b.x, b.y, fmt.Sprintf("%d,%d: Text: %s; Path: %s", b.x, b.y, b.text, strings.Join(b.parts, b.separator)), b.style, screen)
|
||||
switch b.tp {
|
||||
case SBTypeText:
|
||||
b.DrawText(screen)
|
||||
case SBTypePath:
|
||||
b.DrawPath(screen)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *StatusBlock) DrawText(screen tcell.Screen) {
|
||||
wh.DrawText(b.x, b.y, b.text, b.style, screen)
|
||||
}
|
||||
|
||||
func (b *StatusBlock) DrawPath(screen tcell.Screen) {
|
||||
wh.DrawText(b.x, b.y, fmt.Sprintf("%s %s", strings.Join(b.parts, b.separator), b.separator), b.style, screen)
|
||||
}
|
||||
Reference in New Issue
Block a user