display list of layers in UI
This commit is contained in:
parent
4ed43ada81
commit
1e4ad0ce72
45
main.go
45
main.go
@ -7,18 +7,19 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"golang.org/x/net/context"
|
||||
"github.com/jroimartin/gocui"
|
||||
"log"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/jroimartin/gocui"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var data struct {
|
||||
tree *FileTree
|
||||
manifest *Manifest
|
||||
absPosition uint
|
||||
}
|
||||
|
||||
|
||||
func check(e error) {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
@ -110,20 +111,8 @@ func demo() {
|
||||
fmt.Println("See './image' for the cached image tar")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func getAbsPositionNode() (node *FileNode) {
|
||||
var visiter func(*FileNode) error
|
||||
var evaluator func(*FileNode) bool
|
||||
@ -154,7 +143,10 @@ func showCurNodeInSideBar(g *gocui.Gui, v *gocui.View) error {
|
||||
v, _ := g.View("side")
|
||||
// todo: handle above error.
|
||||
v.Clear()
|
||||
_, err := fmt.Fprintf(v, "FileNode:\n%+v\n", getAbsPositionNode())
|
||||
_, err := fmt.Fprintf(v, "FileNode:\n%+v\n\n", getAbsPositionNode())
|
||||
for ix, layerName := range data.manifest.Layers {
|
||||
fmt.Fprintf(v, "%d: %s\n", ix+1, layerName[0:25])
|
||||
}
|
||||
return err
|
||||
})
|
||||
// todo: blerg
|
||||
@ -166,7 +158,7 @@ func cursorDown(g *gocui.Gui, v *gocui.View) error {
|
||||
cx, cy := v.Cursor()
|
||||
|
||||
// if there isn't a next line
|
||||
line, err := v.Line(cy+1)
|
||||
line, err := v.Line(cy + 1)
|
||||
if err != nil {
|
||||
// todo: handle error
|
||||
}
|
||||
@ -200,7 +192,6 @@ func cursorUp(g *gocui.Gui, v *gocui.View) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func toggleCollapse(g *gocui.Gui, v *gocui.View) error {
|
||||
node := getAbsPositionNode()
|
||||
node.collapsed = !node.collapsed
|
||||
@ -218,7 +209,6 @@ func drawTree(g *gocui.Gui, v *gocui.View) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
return gocui.ErrQuit
|
||||
}
|
||||
@ -242,7 +232,6 @@ func keybindings(g *gocui.Gui) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func layout(g *gocui.Gui) error {
|
||||
maxX, maxY := g.Size()
|
||||
splitCol := 50
|
||||
@ -251,6 +240,7 @@ func layout(g *gocui.Gui) error {
|
||||
return err
|
||||
}
|
||||
v.Wrap = true
|
||||
|
||||
}
|
||||
if v, err := g.SetView("main", splitCol, -1, maxX, maxY); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
@ -269,16 +259,9 @@ func layout(g *gocui.Gui) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
data.tree = NewTree()
|
||||
data.tree.AddPath("/etc/nginx/nginx.conf", nil)
|
||||
data.tree.AddPath("/etc/nginx/public", nil)
|
||||
data.tree.AddPath("/var/run/systemd", nil)
|
||||
data.tree.AddPath("/var/run/bashful", nil)
|
||||
data.tree.AddPath("/tmp", nil)
|
||||
data.tree.AddPath("/tmp/nonsense", nil)
|
||||
data.tree.AddPath("/tmp/wifi/coffeeyo", nil)
|
||||
demo()
|
||||
initialize()
|
||||
|
||||
g, err := gocui.NewGui(gocui.OutputNormal)
|
||||
if err != nil {
|
||||
@ -299,5 +282,3 @@ func main() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func tarReadDemo() {
|
||||
func initialize() {
|
||||
f, err := os.Open("image/cache.tar")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@ -21,7 +21,7 @@ func tarReadDemo() {
|
||||
|
||||
tarReader := tar.NewReader(f)
|
||||
targetName := "manifest.json"
|
||||
var m Manifest
|
||||
var manifest Manifest
|
||||
var layerMap map[string]*FileTree
|
||||
layerMap = make(map[string]*FileTree)
|
||||
|
||||
@ -39,7 +39,7 @@ func tarReadDemo() {
|
||||
|
||||
name := header.Name
|
||||
if name == targetName {
|
||||
m = handleManifest(tarReader, header)
|
||||
manifest = handleManifest(tarReader, header)
|
||||
}
|
||||
|
||||
switch header.Typeflag {
|
||||
@ -69,7 +69,7 @@ func tarReadDemo() {
|
||||
}
|
||||
var trees []*FileTree
|
||||
trees = make([]*FileTree, 0)
|
||||
for _, treeName := range m.Layers {
|
||||
for _, treeName := range manifest.Layers {
|
||||
fmt.Printf("%s\n", treeName)
|
||||
trees = append(trees, layerMap[treeName])
|
||||
}
|
||||
@ -79,14 +79,9 @@ func tarReadDemo() {
|
||||
trees[0].Stack(trees[ix])
|
||||
}
|
||||
}
|
||||
// fmt.Printf("%+v\n", m)
|
||||
// fmt.Printf("%+v\n", layerMap)
|
||||
fmt.Printf("%+v\n", trees)
|
||||
// fmt.Printf("Tree 1 is: \n %+v\n", trees[1])
|
||||
// fmt.Printf("Tree 2 is: \n %+v\n", trees[2])
|
||||
// trees[1].Stack(trees[2])
|
||||
// fmt.Printf("Tree 1 stacked with tree 2 is: \n %+v\n", trees[1])
|
||||
// fmt.Printf("The whle stack is \n %+v \n", trees[0])
|
||||
fmt.Printf("Manifest is %+v\n\n", manifest)
|
||||
data.manifest = &manifest
|
||||
data.tree = trees[0]
|
||||
}
|
||||
|
||||
func getFileList(parentReader *tar.Reader, h *tar.Header) []FileChangeInfo {
|
||||
@ -155,7 +150,6 @@ func makeEntry(r *tar.Reader, h *tar.Header, path string) FileChangeInfo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type Manifest struct {
|
||||
Config string
|
||||
RepoTags []string
|
Loading…
x
Reference in New Issue
Block a user