add image size to details pane (closes #66)

This commit is contained in:
Alex Goodman 2018-11-24 20:01:51 -05:00
parent 3c46874ef6
commit 30f3feda9d
No known key found for this signature in database
GPG Key ID: 743640FAA11698A1
2 changed files with 21 additions and 10 deletions

View File

@ -2,13 +2,12 @@ package ui
import ( import (
"fmt" "fmt"
"strconv"
"strings"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/jroimartin/gocui" "github.com/jroimartin/gocui"
"github.com/lunixbochs/vtclean" "github.com/lunixbochs/vtclean"
"github.com/wagoodman/dive/filetree" "github.com/wagoodman/dive/filetree"
"strconv"
"strings"
) )
// DetailsView holds the UI objects and data models for populating the lower-left pane. Specifically the pane that // DetailsView holds the UI objects and data models for populating the lower-left pane. Specifically the pane that
@ -112,15 +111,19 @@ func (view *DetailsView) Render() error {
} }
} }
effStr := fmt.Sprintf("\n%s %d %%", Formatting.Header("Image efficiency score:"), int(100.0*view.efficiency)) imageSizeStr := fmt.Sprintf("%s %s", Formatting.Header("Total Image size:"), humanize.Bytes(Views.Layer.ImageSize))
spaceStr := fmt.Sprintf("%s %s\n", Formatting.Header("Potential wasted space:"), humanize.Bytes(uint64(wastedSpace))) effStr := fmt.Sprintf("%s %d %%", Formatting.Header("Image efficiency score:"), int(100.0*view.efficiency))
wastedSpaceStr := fmt.Sprintf("%s %s", Formatting.Header("Potential wasted space:"), humanize.Bytes(uint64(wastedSpace)))
view.gui.Update(func(g *gocui.Gui) error { view.gui.Update(func(g *gocui.Gui) error {
// update header // update header
view.header.Clear() view.header.Clear()
width, _ := g.Size() width, _ := view.view.Size()
headerStr := fmt.Sprintf("[Image & Layer Details]%s", strings.Repeat("─", width*2))
fmt.Fprintln(view.header, Formatting.Header(vtclean.Clean(headerStr, false))) layerHeaderStr := fmt.Sprintf("[Layer Details]%s", strings.Repeat("─", width-15))
imageHeaderStr := fmt.Sprintf("[Image Details]%s", strings.Repeat("─", width-15))
fmt.Fprintln(view.header, Formatting.Header(vtclean.Clean(layerHeaderStr, false)))
// update contents // update contents
view.view.Clear() view.view.Clear()
@ -129,8 +132,11 @@ func (view *DetailsView) Render() error {
fmt.Fprintln(view.view, Formatting.Header("Command:")) fmt.Fprintln(view.view, Formatting.Header("Command:"))
fmt.Fprintln(view.view, currentLayer.History.CreatedBy) fmt.Fprintln(view.view, currentLayer.History.CreatedBy)
fmt.Fprintln(view.view, effStr) fmt.Fprintln(view.view, "\n"+Formatting.Header(vtclean.Clean(imageHeaderStr, false)))
fmt.Fprintln(view.view, spaceStr)
fmt.Fprintln(view.view, imageSizeStr)
fmt.Fprintln(view.view, wastedSpaceStr)
fmt.Fprintln(view.view, effStr+"\n")
fmt.Fprintln(view.view, inefficiencyReport) fmt.Fprintln(view.view, inefficiencyReport)
return nil return nil

View File

@ -23,6 +23,7 @@ type LayerView struct {
Layers []*image.Layer Layers []*image.Layer
CompareMode CompareType CompareMode CompareType
CompareStartIndex int CompareStartIndex int
ImageSize uint64
keybindingCompareAll []Key keybindingCompareAll []Key
keybindingCompareLayer []Key keybindingCompareLayer []Key
@ -178,6 +179,10 @@ func (view *LayerView) renderCompareBar(layerIdx int) string {
// Update refreshes the state objects for future rendering (currently does nothing). // Update refreshes the state objects for future rendering (currently does nothing).
func (view *LayerView) Update() error { func (view *LayerView) Update() error {
view.ImageSize = 0
for idx := 0; idx < len(view.Layers); idx++ {
view.ImageSize += view.Layers[idx].History.Size
}
return nil return nil
} }