summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorAlex Goodman <wagoodman@users.noreply.github.com>2018-12-08 11:46:09 -0500
committerGitHub <noreply@github.com>2018-12-08 11:46:09 -0500
commit9f9a8f2c05ddf4d997fa55fb43946f81fa02237b (patch)
tree9ba3b684a014d09d561667e9153920889544d814 /ui
parent910c33fdf0889e925e8b423a6f94ddccd9df5be7 (diff)
Refactor image preprocessing (#121)
Diffstat (limited to 'ui')
-rw-r--r--ui/detailsview.go5
-rw-r--r--ui/layerview.go20
-rw-r--r--ui/ui.go8
3 files changed, 11 insertions, 22 deletions
diff --git a/ui/detailsview.go b/ui/detailsview.go
index 2eaa802..f387703 100644
--- a/ui/detailsview.go
+++ b/ui/detailsview.go
@@ -128,9 +128,10 @@ func (view *DetailsView) Render() error {
// update contents
view.view.Clear()
fmt.Fprintln(view.view, Formatting.Header("Digest: ")+currentLayer.Id())
- fmt.Fprintln(view.view, Formatting.Header("Tar ID: ")+currentLayer.TarId())
+ // TODO: add back in with view model
+ // fmt.Fprintln(view.view, Formatting.Header("Tar ID: ")+currentLayer.TarId())
fmt.Fprintln(view.view, Formatting.Header("Command:"))
- fmt.Fprintln(view.view, currentLayer.History.CreatedBy)
+ fmt.Fprintln(view.view, currentLayer.Command())
fmt.Fprintln(view.view, "\n"+Formatting.Header(vtclean.Clean(imageHeaderStr, false)))
diff --git a/ui/layerview.go b/ui/layerview.go
index a77adfd..b29b874 100644
--- a/ui/layerview.go
+++ b/ui/layerview.go
@@ -5,7 +5,6 @@ import (
"github.com/spf13/viper"
"github.com/wagoodman/dive/utils"
- "github.com/dustin/go-humanize"
"github.com/jroimartin/gocui"
"github.com/lunixbochs/vtclean"
"github.com/wagoodman/dive/image"
@@ -20,7 +19,7 @@ type LayerView struct {
view *gocui.View
header *gocui.View
LayerIndex int
- Layers []*image.Layer
+ Layers []image.Layer
CompareMode CompareType
CompareStartIndex int
ImageSize uint64
@@ -30,7 +29,7 @@ type LayerView struct {
}
// NewDetailsView creates a new view object attached the the global [gocui] screen object.
-func NewLayerView(name string, gui *gocui.Gui, layers []*image.Layer) (layerView *LayerView) {
+func NewLayerView(name string, gui *gocui.Gui, layers []image.Layer) (layerView *LayerView) {
layerView = new(LayerView)
// populate main fields
@@ -131,7 +130,7 @@ func (view *LayerView) SetCursor(layer int) error {
}
// currentLayer returns the Layer object currently selected.
-func (view *LayerView) currentLayer() *image.Layer {
+func (view *LayerView) currentLayer() image.Layer {
return view.Layers[(len(view.Layers)-1)-view.LayerIndex]
}
@@ -181,7 +180,7 @@ func (view *LayerView) renderCompareBar(layerIdx int) string {
func (view *LayerView) Update() error {
view.ImageSize = 0
for idx := 0; idx < len(view.Layers); idx++ {
- view.ImageSize += view.Layers[idx].History.Size
+ view.ImageSize += view.Layers[idx].Size()
}
return nil
}
@@ -212,17 +211,6 @@ func (view *LayerView) Render() error {
idx := (len(view.Layers) - 1) - revIdx
layerStr := layer.String()
- if idx == 0 {
- var layerId string
- if len(layer.History.ID) >= 25 {
- layerId = layer.History.ID[0:25]
- } else {
- layerId = fmt.Sprintf("%-25s", layer.History.ID)
- }
-
- layerStr = fmt.Sprintf(image.LayerFormat, layerId, humanize.Bytes(uint64(layer.History.Size)), "FROM "+layer.ShortId())
- }
-
compareBar := view.renderCompareBar(idx)
if idx == view.LayerIndex {
diff --git a/ui/ui.go b/ui/ui.go
index 8b3e815..6ad30e8 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -301,7 +301,7 @@ func renderStatusOption(control, title string, selected bool) string {
}
// Run is the UI entrypoint.
-func Run(layers []*image.Layer, refTrees []*filetree.FileTree, efficiency float64, inefficiencies filetree.EfficiencySlice) {
+func Run(analysis *image.AnalysisResult) {
Formatting.Selected = color.New(color.ReverseVideo, color.Bold).SprintFunc()
Formatting.Header = color.New(color.Bold).SprintFunc()
@@ -325,10 +325,10 @@ func Run(layers []*image.Layer, refTrees []*filetree.FileTree, efficiency float6
Views.lookup = make(map[string]View)
- Views.Layer = NewLayerView("side", g, layers)
+ Views.Layer = NewLayerView("side", g, analysis.Layers)
Views.lookup[Views.Layer.Name] = Views.Layer
- Views.Tree = NewFileTreeView("main", g, filetree.StackRange(refTrees, 0, 0), refTrees)
+ Views.Tree = NewFileTreeView("main", g, filetree.StackRange(analysis.RefTrees, 0, 0), analysis.RefTrees)
Views.lookup[Views.Tree.Name] = Views.Tree
Views.Status = NewStatusView("status", g)
@@ -337,7 +337,7 @@ func Run(layers []*image.Layer, refTrees []*filetree.FileTree, efficiency float6
Views.Filter = NewFilterView("command", g)
Views.lookup[Views.Filter.Name] = Views.Filter
- Views.Details = NewDetailsView("details", g, efficiency, inefficiencies)
+ Views.Details = NewDetailsView("details", g, analysis.Efficiency, analysis.Inefficiencies)
Views.lookup[Views.Details.Name] = Views.Details
g.Cursor = false