Skip to content

Commit

Permalink
add y to yank hash
Browse files Browse the repository at this point in the history
  • Loading branch information
treethought committed Sep 11, 2021
1 parent fc66339 commit 0baac51
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
code.rocketnine.space/tslocum/cbind v0.1.5
code.rocketnine.space/tslocum/cview v1.5.7
github.com/JohannesKaufmann/html-to-markdown v1.3.0
github.com/atotto/clipboard v0.1.4
github.com/eliukblau/pixterm v1.3.1
github.com/gdamore/tcell/v2 v2.4.1-0.20210828201608-73703f7ed490
github.com/ipfs/go-ipfs-api v0.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw=
Expand Down
2 changes: 1 addition & 1 deletion ui/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewContentView(app *App) *Content {
}

func (c *Content) Update() {
current := c.app.state.currentItem
current := c.app.state.currentFile
path, entry := current.path, current.entry
c.Clear()
// go c.app.ui.QueueUpdateDraw(func() {
Expand Down
29 changes: 17 additions & 12 deletions ui/dag.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package ui

import (
"github.com/atotto/clipboard"
"github.com/gdamore/tcell/v2"

"code.rocketnine.space/tslocum/cbind"
"code.rocketnine.space/tslocum/cview"
ipld "github.com/ipfs/go-ipld-format"
)

type DagData struct {
Data string
Links []ipld.Link
}

type DagInfo struct {
*cview.TreeView
app *App
Expand Down Expand Up @@ -60,13 +66,18 @@ func (i *DagInfo) handleSelect(ev *tcell.EventKey) *tcell.EventKey {

func (d *DagInfo) initBindings() {
d.inputHandler.SetKey(tcell.ModNone, tcell.KeyEnter, d.handleSelect)
d.SetInputCapture(d.inputHandler.Capture)

}
d.inputHandler.SetRune(tcell.ModNone, 'y', func(ev *tcell.EventKey) *tcell.EventKey {
node := d.GetCurrentNode()
ref := node.GetReference()
e, ok := ref.(ipld.Link)
if !ok {
return nil
}
clipboard.WriteAll(e.Cid.String())

type DagData struct {
Data string
Links []ipld.Link
return nil
})
d.SetInputCapture(d.inputHandler.Capture)
}

func (i *DagInfo) Update() {
Expand Down Expand Up @@ -111,11 +122,5 @@ func (i *DagInfo) Update() {
i.GetRoot().AddChild(node)
}

// i.SetText(strings.Join(lines, "\n"))
// data, err := yaml.Marshal(dag)
// if err != nil {
// panic(err)
// }
// i.SetText(string(data))
})
}
12 changes: 12 additions & 0 deletions ui/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"runtime"

"code.rocketnine.space/tslocum/cbind"
"github.com/atotto/clipboard"
api "github.com/ipfs/go-ipfs-api"

"code.rocketnine.space/tslocum/cview"
Expand Down Expand Up @@ -119,6 +120,17 @@ func (r *RepoTree) handleSelect(ev *tcell.EventKey) *tcell.EventKey {
func (t *RepoTree) initBindings() {
t.inputHandler.SetKey(tcell.ModNone, tcell.KeyEnter, t.handleSelect)
t.inputHandler.SetRune(tcell.ModNone, 'o', t.handleOpen)
t.inputHandler.SetRune(tcell.ModNone, 'y', func(ev *tcell.EventKey) *tcell.EventKey {
node := t.GetCurrentNode()
ref := node.GetReference()
e, ok := ref.(TreeEntry)
if !ok {
return nil
}
clipboard.WriteAll(e.entry.Hash)

return nil
})
t.SetInputCapture(t.inputHandler.Capture)

}
Expand Down
4 changes: 2 additions & 2 deletions ui/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ui
import (
"fmt"


"code.rocketnine.space/tslocum/cview"
"github.com/gdamore/tcell/v2"
)
Expand All @@ -27,7 +26,8 @@ func NewFileInfo(app *App) *FileInfo {
}

func (i *FileInfo) Update() {
current := i.app.state.currentItem
current := i.app.state.currentFile

info := fmt.Sprintf("%+v", current.entry)
i.Clear()

Expand Down
9 changes: 5 additions & 4 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ type Widget interface {

type State struct {
app *App
currentItem TreeEntry
currentFile TreeEntry
}

func NewState(app *App) *State {
return &State{
app: app,
currentItem: TreeEntry{path: "/", entry: nil},
currentFile: TreeEntry{path: "/", entry: nil},
}
}

func (s *State) SetItem(e TreeEntry) {
s.currentItem = e
s.currentFile = e
for _, w := range s.app.widgets {
w.Update()
}
Expand Down Expand Up @@ -99,7 +100,7 @@ func (app *App) initViews() {
flex.AddItem(mid, 0, 4, false)
app.root = flex

app.initInputHandler(repo, content, info, dag)
app.initInputHandler(repo, content, dag, info)

}

Expand Down

0 comments on commit 0baac51

Please sign in to comment.