Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image name to details view #325

Merged
merged 2 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golangci/golangci-lint v1.32.0 h1:3wL5pvhTpRvlvtosoZecS+hu40IAiJl1qlZQuXIFBAg=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down
2 changes: 1 addition & 1 deletion runtime/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func run(enableUi bool, options Options, imageResolver image.Resolver, events ev
// enough sleep will prevent this behavior (todo: remove this hack)
time.Sleep(100 * time.Millisecond)

err = ui.Run(analysis, treeStack)
err = ui.Run(options.Image, analysis, treeStack)
if err != nil {
events.exitWithError(err)
return
Expand Down
8 changes: 4 additions & 4 deletions runtime/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ var (
appSingleton *app
)

func newApp(gui *gocui.Gui, analysis *image.AnalysisResult, cache filetree.Comparer) (*app, error) {
func newApp(gui *gocui.Gui, imageName string, analysis *image.AnalysisResult, cache filetree.Comparer) (*app, error) {
var err error
once.Do(func() {
var controller *Controller
var globalHelpKeys []*key.Binding

controller, err = NewCollection(gui, analysis, cache)
controller, err = NewCollection(gui, imageName, analysis, cache)
if err != nil {
return
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func (a *app) quit() error {
}

// Run is the UI entrypoint.
func Run(analysis *image.AnalysisResult, treeStack filetree.Comparer) error {
func Run(imageName string, analysis *image.AnalysisResult, treeStack filetree.Comparer) error {
var err error

g, err := gocui.NewGui(gocui.OutputNormal)
Expand All @@ -136,7 +136,7 @@ func Run(analysis *image.AnalysisResult, treeStack filetree.Comparer) error {
}
defer g.Close()

_, err = newApp(g, analysis, treeStack)
_, err = newApp(g, imageName, analysis, treeStack)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/ui/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Controller struct {
views *view.Views
}

func NewCollection(g *gocui.Gui, analysis *image.AnalysisResult, cache filetree.Comparer) (*Controller, error) {
views, err := view.NewViews(g, analysis, cache)
func NewCollection(g *gocui.Gui, imageName string, analysis *image.AnalysisResult, cache filetree.Comparer) (*Controller, error) {
views, err := view.NewViews(g, imageName, analysis, cache)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion runtime/ui/view/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Details struct {
gui *gocui.Gui
view *gocui.View
header *gocui.View
imageName string
efficiency float64
inefficiencies filetree.EfficiencySlice
imageSize uint64
Expand All @@ -29,12 +30,13 @@ type Details struct {
}

// newDetailsView creates a new view object attached the the global [gocui] screen object.
func newDetailsView(gui *gocui.Gui, efficiency float64, inefficiencies filetree.EfficiencySlice, imageSize uint64) (controller *Details) {
func newDetailsView(gui *gocui.Gui, imageName string, efficiency float64, inefficiencies filetree.EfficiencySlice, imageSize uint64) (controller *Details) {
controller = new(Details)

// populate main fields
controller.name = "details"
controller.gui = gui
controller.imageName = imageName
controller.efficiency = efficiency
controller.inefficiencies = inefficiencies
controller.imageSize = imageSize
Expand Down Expand Up @@ -148,6 +150,7 @@ func (v *Details) Render() error {
}
}

imageNameStr := fmt.Sprintf("%s %s", format.Header("Image name:"), v.imageName)
imageSizeStr := fmt.Sprintf("%s %s", format.Header("Total Image size:"), humanize.Bytes(v.imageSize))
effStr := fmt.Sprintf("%s %d %%", format.Header("Image efficiency score:"), int(100.0*v.efficiency))
wastedSpaceStr := fmt.Sprintf("%s %s", format.Header("Potential wasted space:"), humanize.Bytes(uint64(wastedSpace)))
Expand Down Expand Up @@ -179,6 +182,7 @@ func (v *Details) Render() error {
lines = append(lines, format.Header("Command:"))
lines = append(lines, v.currentLayer.Command)
lines = append(lines, "\n"+imageHeaderStr)
lines = append(lines, imageNameStr)
lines = append(lines, imageSizeStr)
lines = append(lines, wastedSpaceStr)
lines = append(lines, effStr+"\n")
Expand Down
4 changes: 2 additions & 2 deletions runtime/ui/view/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Views struct {
Debug *Debug
}

func NewViews(g *gocui.Gui, analysis *image.AnalysisResult, cache filetree.Comparer) (*Views, error) {
func NewViews(g *gocui.Gui, imageName string, analysis *image.AnalysisResult, cache filetree.Comparer) (*Views, error) {
Layer, err := newLayerView(g, analysis.Layers)
if err != nil {
return nil, err
Expand All @@ -34,7 +34,7 @@ func NewViews(g *gocui.Gui, analysis *image.AnalysisResult, cache filetree.Compa

Filter := newFilterView(g)

Details := newDetailsView(g, analysis.Efficiency, analysis.Inefficiencies, analysis.SizeBytes)
Details := newDetailsView(g, imageName, analysis.Efficiency, analysis.Inefficiencies, analysis.SizeBytes)

Debug := newDebugView(g)

Expand Down