Skip to content

Commit

Permalink
Merge pull request #1 from treethought/peers
Browse files Browse the repository at this point in the history
better tabbed panes and peers as table
  • Loading branch information
treethought authored Sep 12, 2021
2 parents f5d62bc + 6f86722 commit d5582c6
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 148 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: goreleaser

on:
pull_request:
push:

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

dist/
30 changes: 30 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
# - go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,37 @@

tipfs is an ugly little ipfs TUI client.

[![asciicast](https://asciinema.org/a/435146.svg)](https://asciinema.org/a/435146)

## Install

``` sh
go get github.com/treethought/tipfs
```

## Features
- Browse, viewing Mutable File System
- Exploring DAG nodes
- Viewing peers
- View supported content in terminal
- Opening/copying CID in browser

## Keybindings

| key | action |
|-------|----------------------------------------|
| TAB | Switch focus between panels |
| o | Open in browser |
| y | Copy selected items CID |
| j | Move selection up |
| k | Move selection down |
| Enter | Select file to inspect |
| g | Go to top of panel |
| G | Go to bottom of panel |
| key | action |
|-------|-----------------------------|
| TAB | Switch focus between panels |
| Enter | Select file to inspect |
| o | Open in browser |
| y | Copy selected items CID |
| j | Move selection up |
| k | Move selection down |
| g | Go to top of panel |
| G | Go to bottom of panel |
| 1 | Switch to files mode |
| 2 | Switch to peers mode |





Expand Down
45 changes: 0 additions & 45 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,6 @@ func Execute() {
}

func init() {
// cobra.OnInitialize(initConfig)

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.masto.yaml)")

}

// initConfig reads in config file and ENV variables if set.
// func initConfig() {
// if cfgFile != "" {
// // Use config file from the flag.
// viper.SetConfigFile(cfgFile)
// } else {
// // Find home directory.
// _, err := homedir.Dir()
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }

// // Search config in home directory with name ".masto" (without extension).
// // viper.AddConfigPath(home)
// viper.SetConfigName(".mammut")
// viper.SetConfigName("mammut") // name of config file (without extension)
// viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
// viper.AddConfigPath("$HOME/.config") // call multiple times to add many search paths
// viper.AddConfigPath("$HOME") // call multiple times to add many search paths
// viper.AddConfigPath(".") // optionally look for config in the working directory
// if err := viper.ReadInConfig(); err != nil {
// if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// viper.SafeWriteConfig()
// } else {
// panic(fmt.Errorf("Fatal error config file: %s \n", err))
// }
// }

// }

// viper.AutomaticEnv() // read in environment variables that match

// // If a config file is found, read it in.
// if err := viper.ReadInConfig(); err == nil {
// fmt.Println("Using config file:", viper.ConfigFileUsed())
// }
// }
1 change: 1 addition & 0 deletions demo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 23 additions & 7 deletions ipfs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,34 @@ import (
"io/ioutil"

api "github.com/ipfs/go-ipfs-api"
ipld "github.com/ipfs/go-ipld-format"
"gopkg.in/yaml.v2"
)

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

type Client struct {
nodeURL string
sh *api.Shell
}

func NewClient(url string) *Client {

c := &Client{
nodeURL: url,
sh: api.NewLocalShell(),
}
return c
}

// func (c *Client) Get(path string, entry *api.MfsLsEntry) ([]byte, error) {
// }

func (c *Client) ReadFile(path string, entry *api.MfsLsEntry) ([]byte, error) {

if entry.Type == api.TDirectory {
return []byte("directory"), nil
}
Expand All @@ -33,10 +44,14 @@ func (c *Client) ReadFile(path string, entry *api.MfsLsEntry) ([]byte, error) {
return ioutil.ReadAll(r)
}

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) GetDag(ref string) (dag *DagData, err error) {
dag = &DagData{}

err = c.sh.DagGet(ref, dag)
if err != nil {
return nil, err
}
return dag, nil
}

func (c *Client) ListFiles(path string) (entries []*api.MfsLsEntry, err error) {
Expand All @@ -45,9 +60,6 @@ func (c *Client) ListFiles(path string) (entries []*api.MfsLsEntry, err error) {
fmt.Println(err)
return entries, err
}
for _, e := range entries {
fmt.Println(e.Name, e.Hash, e.Size, e.Type)
}
return entries, nil
}

Expand Down Expand Up @@ -81,3 +93,7 @@ func (c *Client) StatFile(path string, entry *api.MfsLsEntry) (string, error) {
func (c *Client) GetPeers() (*api.SwarmConnInfos, error) {
return c.sh.SwarmPeers(context.TODO())
}

func (c *Client) GetPeer(p string) (*api.PeerInfo, error) {
return c.sh.FindPeer(p)
}
12 changes: 6 additions & 6 deletions ui/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ import (
md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/eliukblau/pixterm/pkg/ansimage"
"github.com/gdamore/tcell/v2"

api "github.com/ipfs/go-ipfs-api"
)

type Content struct {
*cview.TextView

app *App
entry *api.MfsLsEntry
app *App
}

func NewContentView(app *App) *Content {
Expand All @@ -41,9 +38,8 @@ func (c *Content) Update() {
current := c.app.state.currentFile
path, entry := current.path, current.entry
c.Clear()
// go c.app.ui.QueueUpdateDraw(func() {

data, err := c.app.client.ReadFile(path, entry)
data, err := c.app.ipfs.ReadFile(path, entry)
if err != nil {
panic(err)
}
Expand All @@ -52,8 +48,12 @@ func (c *Content) Update() {
c.SetText(err.Error())
}

c.SetTextAlign(cview.AlignLeft)

switch contentType {
case "image/png", "image/jpeg":

c.SetTextAlign(cview.AlignCenter)
c.SetDynamicColors(true)
_, _, w, h := c.GetRect()
r := bytes.NewReader(data)
Expand Down
9 changes: 1 addition & 8 deletions ui/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
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 @@ -100,9 +95,7 @@ func (i *DagInfo) Update() {

go i.app.ui.QueueUpdateDraw(func() {

dag := &DagData{}

err := i.app.ipfs.DagGet(i.currentHash, &dag)
dag, err := i.app.ipfs.GetDag(i.currentHash)
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions ui/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type TreeEntry struct {
func (r *RepoTree) buildNodes(basePath string, entries ...*api.MfsLsEntry) []*cview.TreeNode {
nodes := []*cview.TreeNode{}
for _, i := range entries {
fmt.Println(i.Name)
node := cview.NewTreeNode(i.Name)
ref := TreeEntry{
entry: i,
Expand All @@ -40,7 +39,7 @@ func (r *RepoTree) buildNodes(basePath string, entries ...*api.MfsLsEntry) []*cv

if i.Type == api.TDirectory {

children, err := r.app.client.ListFiles(ref.path)
children, err := r.app.ipfs.ListFiles(ref.path)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -61,10 +60,11 @@ func NewRepoTree(app *App) *RepoTree {
TreeView: cview.NewTreeView(),
app: app,
}
m.SetBorder(false)
m.SetBorder(true)
m.SetPadding(1, 1, 1, 1)
m.SetTitle("repo")
m.SetBackgroundColor(tcell.ColorDefault)
m.SetScrollBarVisibility(cview.ScrollBarNever)

rootNode := cview.NewTreeNode("/")
m.SetRoot(rootNode)
Expand All @@ -73,7 +73,7 @@ func NewRepoTree(app *App) *RepoTree {
m.inputHandler = cbind.NewConfiguration()
m.initBindings()

entries, err := app.client.ListFiles("/")
entries, err := app.ipfs.ListFiles("/")
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion ui/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (i *FileInfo) Update() {
i.Clear()

go i.app.ui.QueueUpdateDraw(func() {
stat, err := i.app.client.StatFile(current.path, current.entry)
stat, err := i.app.ipfs.StatFile(current.path, current.entry)
if err != nil {
i.SetText(fmt.Sprintf("%s\n%v", current.path, err))
return
Expand Down
Loading

0 comments on commit d5582c6

Please sign in to comment.