Skip to content

Commit

Permalink
basic dag view
Browse files Browse the repository at this point in the history
  • Loading branch information
treethought committed Sep 8, 2021
1 parent 1bb62bc commit 0d5d008
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 80 deletions.
6 changes: 6 additions & 0 deletions ipfs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func NewClient(url string) *Client {
return c
}

func (c *Client) GetDag(ref string) (out map[string]interface{}, err error) {
out = make(map[string]interface{})
err = c.sh.DagGet(ref, &out)
return out, err
}

func (c *Client) ListFiles(path string) (entries []*api.MfsLsEntry, err error) {
entries, err = c.sh.FilesLs(context.Background(), path, api.FilesLs.Stat(true))
if err != nil {
Expand Down
66 changes: 0 additions & 66 deletions ui/buffer.go

This file was deleted.

45 changes: 45 additions & 0 deletions ui/dag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ui

import (
"github.com/gdamore/tcell/v2"
api "github.com/ipfs/go-ipfs-api"
"gopkg.in/yaml.v2"

"code.rocketnine.space/tslocum/cview"
)

type DagInfo struct {
*cview.TextView

app *App
entry *api.MfsLsEntry
}

func NewDagInfo(app *App) *DagInfo {
m := &DagInfo{
TextView: cview.NewTextView(),
app: app,
}
m.SetBorder(true)
m.SetPadding(1, 1, 1, 1)
m.SetTitle("dag")
m.SetBackgroundColor(tcell.ColorDefault)

return m
}

func (i *DagInfo) SetItem(entry *api.MfsLsEntry) {
i.entry = entry

dag, err := i.app.client.GetDag(entry.Hash)
if err != nil {
panic(err)
}

data, err := yaml.Marshal(dag)
if err != nil {
panic(err)
}

i.SetText(string(data))
}
3 changes: 2 additions & 1 deletion ui/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewRepoTree(app *App) *RepoTree {
}
m.SetBorder(true)
m.SetPadding(1, 1, 1, 1)
m.SetTitle("menu")
m.SetTitle("repo")
m.SetBackgroundColor(tcell.ColorDefault)
m.SetSelectedTextColor(tcell.ColorTeal)

Expand Down Expand Up @@ -50,6 +50,7 @@ func NewRepoTree(app *App) *RepoTree {
}

m.app.info.SetItem(entry)
m.app.dag.SetItem(entry)

})
return m
Expand Down
8 changes: 4 additions & 4 deletions ui/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"github.com/gdamore/tcell/v2"
)

type Info struct {
type FileInfo struct {
*cview.TextView
app *App
}

func NewInfo(app *App) *Info {
m := &Info{
func NewFileInfo(app *App) *FileInfo {
m := &FileInfo{
TextView: cview.NewTextView(),
app: app,
}
Expand All @@ -27,7 +27,7 @@ func NewInfo(app *App) *Info {
return m
}

func (i *Info) SetItem(entry *api.MfsLsEntry) {
func (i *FileInfo) SetItem(entry *api.MfsLsEntry) {
info := fmt.Sprintf("%+v", entry)

stat, err := i.app.client.StatEntry(entry)
Expand Down
19 changes: 10 additions & 9 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type App struct {
client *ipfs.Client
ui *cview.Application
root *cview.Flex
menu *RepoTree
info *Info
buffer *Buffer
repo *RepoTree
info *FileInfo
dag *DagInfo
panels *cview.Panels
focusManager *cview.FocusManager
}
Expand All @@ -25,9 +25,9 @@ func New() *App {
}

func (app *App) initViews() {
app.menu = NewRepoTree(app)
app.info = NewInfo(app)
app.buffer = NewBuffer(app)
app.repo = NewRepoTree(app)
app.info = NewFileInfo(app)
app.dag = NewDagInfo(app)

panels := cview.NewPanels()
app.panels = panels
Expand All @@ -37,14 +37,15 @@ func (app *App) initViews() {
mid.SetDirection(cview.FlexRow)
mid.AddItem(app.panels, 0, 4, true)
mid.AddItem(app.info, 0, 4, false)
mid.AddItem(app.dag, 0, 4, false)

flex := cview.NewFlex()
flex.SetBackgroundTransparent(false)
flex.SetBackgroundColor(tcell.ColorDefault)

left := cview.NewFlex()
left.SetDirection(cview.FlexRow)
left.AddItem(app.menu, 0, 7, false)
left.AddItem(app.repo, 0, 7, false)

flex.AddItem(left, 0, 2, false)
flex.AddItem(mid, 0, 4, false)
Expand Down Expand Up @@ -72,7 +73,7 @@ func (app *App) initBindings() {
func (app *App) initInputHandler() {
app.focusManager = cview.NewFocusManager(app.ui.SetFocus)
app.focusManager.SetWrapAround(true)
app.focusManager.Add(app.menu, app.panels)
app.focusManager.Add(app.repo, app.panels)

}

Expand All @@ -88,7 +89,7 @@ func (app *App) Start() {
app.initBindings()

app.ui.SetRoot(app.root, true)
app.ui.SetFocus(app.menu)
app.ui.SetFocus(app.repo)

err := app.ui.Run()
if err != nil {
Expand Down

0 comments on commit 0d5d008

Please sign in to comment.