diff options
author | Alex Goodman <wagoodman@gmail.com> | 2019-10-13 11:49:18 -0400 |
---|---|---|
committer | Alex Goodman <wagoodman@gmail.com> | 2019-10-13 11:49:18 -0400 |
commit | 939741625d9212e62e3de84dc149f711befba6cf (patch) | |
tree | a6255f6e7533c3bc1f05bc0e43cee27825328c65 | |
parent | 2069a3fede176e349a8a555ea8a582cdbb86e220 (diff) |
drop package names from object names
-rw-r--r-- | runtime/ui/controller/collection.go (renamed from runtime/ui/controller/controller_collection.go) | 34 | ||||
-rw-r--r-- | runtime/ui/controller/details.go (renamed from runtime/ui/controller/details_controller.go) | 80 | ||||
-rw-r--r-- | runtime/ui/controller/filetree.go (renamed from runtime/ui/controller/filetree_controller.go) | 210 | ||||
-rw-r--r-- | runtime/ui/controller/filter.go (renamed from runtime/ui/controller/filter_controller.go) | 84 | ||||
-rw-r--r-- | runtime/ui/controller/layer.go (renamed from runtime/ui/controller/layer_controller.go) | 184 | ||||
-rw-r--r-- | runtime/ui/controller/status.go (renamed from runtime/ui/controller/status_controller.go) | 46 | ||||
-rw-r--r-- | runtime/ui/layout_manager.go | 4 | ||||
-rw-r--r-- | runtime/ui/ui.go | 6 | ||||
-rw-r--r-- | runtime/ui/viewmodel/filetree.go (renamed from runtime/ui/viewmodel/filetree_viewmodel.go) | 44 | ||||
-rw-r--r-- | runtime/ui/viewmodel/filetree_test.go (renamed from runtime/ui/viewmodel/filetree_viewmodel_test.go) | 4 |
10 files changed, 348 insertions, 348 deletions
diff --git a/runtime/ui/controller/controller_collection.go b/runtime/ui/controller/collection.go index f0b7c7b..a7c6124 100644 --- a/runtime/ui/controller/controller_collection.go +++ b/runtime/ui/controller/collection.go @@ -9,22 +9,22 @@ import ( ) // var ccOnce sync.Once -var controllers *ControllerCollection +var controllers *Collection -type ControllerCollection struct { +type Collection struct { gui *gocui.Gui - Tree *FileTreeController - Layer *LayerController - Status *StatusController - Filter *FilterController - Details *DetailsController + Tree *FileTree + Layer *Layer + Status *Status + Filter *Filter + Details *Details lookup map[string]Controller } -func NewControllerCollection(g *gocui.Gui, analysis *image.AnalysisResult, cache filetree.TreeCache) (*ControllerCollection, error) { +func NewCollection(g *gocui.Gui, analysis *image.AnalysisResult, cache filetree.TreeCache) (*Collection, error) { var err error - controllers = &ControllerCollection{ + controllers = &Collection{ gui: g, } controllers.lookup = make(map[string]Controller) @@ -56,7 +56,7 @@ func NewControllerCollection(g *gocui.Gui, analysis *image.AnalysisResult, cache return controllers, nil } -func (c *ControllerCollection) UpdateAndRender() error { +func (c *Collection) UpdateAndRender() error { err := c.Update() if err != nil { logrus.Debug("failed update: ", err) @@ -73,7 +73,7 @@ func (c *ControllerCollection) UpdateAndRender() error { } // Update refreshes the state objects for future rendering. -func (c *ControllerCollection) Update() error { +func (c *Collection) Update() error { for _, controller := range c.lookup { err := controller.Update() if err != nil { @@ -85,7 +85,7 @@ func (c *ControllerCollection) Update() error { } // Render flushes the state objects to the screen. -func (c *ControllerCollection) Render() error { +func (c *Collection) Render() error { for _, controller := range c.lookup { if controller.IsVisible() { err := controller.Render() @@ -98,7 +98,7 @@ func (c *ControllerCollection) Render() error { } // ToggleView switches between the file view and the layer view and re-renders the screen. -func (c *ControllerCollection) ToggleView() (err error) { +func (c *Collection) ToggleView() (err error) { v := c.gui.CurrentView() if v == nil || v.Name() == c.Layer.Name() { _, err = c.gui.SetCurrentView(c.Tree.Name()) @@ -114,7 +114,7 @@ func (c *ControllerCollection) ToggleView() (err error) { return c.UpdateAndRender() } -func (c *ControllerCollection) ToggleFilterView() error { +func (c *Collection) ToggleFilterView() error { // delete all user input from the tree view err := c.Filter.ToggleVisible() if err != nil { @@ -135,17 +135,17 @@ func (c *ControllerCollection) ToggleFilterView() error { } // CursorDown moves the cursor down in the currently selected gocui pane, scrolling the screen as needed. -func (c *ControllerCollection) CursorDown(g *gocui.Gui, v *gocui.View) error { +func (c *Collection) CursorDown(g *gocui.Gui, v *gocui.View) error { return c.CursorStep(g, v, 1) } // CursorUp moves the cursor up in the currently selected gocui pane, scrolling the screen as needed. -func (c *ControllerCollection) CursorUp(g *gocui.Gui, v *gocui.View) error { +func (c *Collection) CursorUp(g *gocui.Gui, v *gocui.View) error { return c.CursorStep(g, v, -1) } // Moves the cursor the given step distance, setting the origin to the new cursor line -func (c *ControllerCollection) CursorStep(g *gocui.Gui, v *gocui.View, step int) error { +func (c *Collection) CursorStep(g *gocui.Gui, v *gocui.View, step int) error { cx, cy := v.Cursor() // if there isn't a next line diff --git a/runtime/ui/controller/details_controller.go b/runtime/ui/controller/details.go index d3eccbc..60336e1 100644 --- a/runtime/ui/controller/details_controller.go +++ b/runtime/ui/controller/details.go @@ -14,9 +14,9 @@ import ( "github.com/lunixbochs/vtclean" ) -// DetailsController holds the UI objects and data models for populating the lower-left pane. Specifically the pane that +// Details holds the UI objects and data models for populating the lower-left pane. Specifically the pane that // shows the layer details and image statistics. -type DetailsController struct { +type Details struct { name string gui *gocui.Gui view *gocui.View @@ -26,8 +26,8 @@ type DetailsController struct { } // NewDetailsController creates a new view object attached the the global [gocui] screen object. -func NewDetailsController(name string, gui *gocui.Gui, efficiency float64, inefficiencies filetree.EfficiencySlice) (controller *DetailsController) { - controller = new(DetailsController) +func NewDetailsController(name string, gui *gocui.Gui, efficiency float64, inefficiencies filetree.EfficiencySlice) (controller *Details) { + controller = new(Details) // populate main fields controller.name = name @@ -38,63 +38,63 @@ func NewDetailsController(name string, gui *gocui.Gui, efficiency float64, ineff return controller } -func (controller *DetailsController) Name() string { - return controller.name +func (c *Details) Name() string { + return c.name } // Setup initializes the UI concerns within the context of a global [gocui] view object. -func (controller *DetailsController) Setup(v *gocui.View, header *gocui.View) error { +func (c *Details) Setup(v *gocui.View, header *gocui.View) error { // set controller options - controller.view = v - controller.view.Editable = false - controller.view.Wrap = true - controller.view.Highlight = false - controller.view.Frame = false + c.view = v + c.view.Editable = false + c.view.Wrap = true + c.view.Highlight = false + c.view.Frame = false - controller.header = header - controller.header.Editable = false - controller.header.Wrap = false - controller.header.Frame = false + c.header = header + c.header.Editable = false + c.header.Wrap = false + c.header.Frame = false var infos = []key.BindingInfo{ { Key: gocui.KeyArrowDown, Modifier: gocui.ModNone, - OnAction: controller.CursorDown, + OnAction: c.CursorDown, }, { Key: gocui.KeyArrowUp, Modifier: gocui.ModNone, - OnAction: controller.CursorUp, + OnAction: c.CursorUp, }, } - _, err := key.GenerateBindings(controller.gui, controller.name, infos) + _, err := key.GenerateBindings(c.gui, c.name, infos) if err != nil { return err } - return controller.Render() + return c.Render() } // IsVisible indicates if the details view pane is currently initialized. -func (controller *DetailsController) IsVisible() bool { - return controller != nil +func (c *Details) IsVisible() bool { + return c != nil } // CursorDown moves the cursor down in the details pane (currently indicates nothing). -func (controller *DetailsController) CursorDown() error { - return controllers.CursorDown(controller.gui, controller.view) +func (c *Details) CursorDown() error { + return controllers.CursorDown(c.gui, c.view) } // CursorUp moves the cursor up in the details pane (currently indicates nothing). -func (controller *DetailsController) CursorUp() error { - return controllers.CursorUp(controller.gui, controller.view) +func (c *Details) CursorUp() error { + return controllers.CursorUp(c.gui, c.view) } // Update refreshes the state objects for future rendering. -func (controller *DetailsController) Update() error { +func (c *Details) Update() error { return nil } @@ -103,7 +103,7 @@ func (controller *DetailsController) Update() error { // 2. the image efficiency score // 3. the estimated wasted image space // 4. a list of inefficient file allocations -func (controller *DetailsController) Render() error { +func (c *Details) Render() error { currentLayer := controllers.Layer.currentLayer() var wastedSpace int64 @@ -112,12 +112,12 @@ func (controller *DetailsController) Render() error { inefficiencyReport := fmt.Sprintf(format.Header(template), "Count", "Total Space", "Path") height := 100 - if controller.view != nil { - _, height = controller.view.Size() + if c.view != nil { + _, height = c.view.Size() } - for idx := 0; idx < len(controller.inefficiencies); idx++ { - data := controller.inefficiencies[len(controller.inefficiencies)-1-idx] + for idx := 0; idx < len(c.inefficiencies); idx++ { + data := c.inefficiencies[len(c.inefficiencies)-1-idx] wastedSpace += data.CumulativeSize // todo: make this report scrollable @@ -127,24 +127,24 @@ func (controller *DetailsController) Render() error { } imageSizeStr := fmt.Sprintf("%s %s", format.Header("Total Image size:"), humanize.Bytes(controllers.Layer.ImageSize)) - effStr := fmt.Sprintf("%s %d %%", format.Header("Image efficiency score:"), int(100.0*controller.efficiency)) + effStr := fmt.Sprintf("%s %d %%", format.Header("Image efficiency score:"), int(100.0*c.efficiency)) wastedSpaceStr := fmt.Sprintf("%s %s", format.Header("Potential wasted space:"), humanize.Bytes(uint64(wastedSpace))) - controller.gui.Update(func(g *gocui.Gui) error { + c.gui.Update(func(g *gocui.Gui) error { // update header - controller.header.Clear() - width, _ := controller.view.Size() + c.header.Clear() + width, _ := c.view.Size() layerHeaderStr := fmt.Sprintf("[Layer Details]%s", strings.Repeat("─", width-15)) imageHeaderStr := fmt.Sprintf("[Image Details]%s", strings.Repeat("─", width-15)) - _, err := fmt.Fprintln(controller.header, format.Header(vtclean.Clean(layerHeaderStr, false))) + _, err := fmt.Fprintln(c.header, format.Header(vtclean.Clean(layerHeaderStr, false))) if err != nil { return err } // update contents - controller.view.Clear() + c.view.Clear() var lines = make([]string, 0) if currentLayer.Names != nil && len(currentLayer.Names) > 0 { @@ -162,7 +162,7 @@ func (controller *DetailsController) Render() error { lines = append(lines, effStr+"\n") lines = append(lines, inefficiencyReport) - _, err = fmt.Fprintln(controller.view, strings.Join(lines, "\n")) + _, err = fmt.Fprintln(c.view, strings.Join(lines, "\n")) if err != nil { logrus.Debug("unable to write to buffer: ", err) } @@ -172,6 +172,6 @@ func (controller *DetailsController) Render() error { } // KeyHelp indicates all the possible actions a user can take while the current pane is selected (currently does nothing). -func (controller *DetailsController) KeyHelp() string { +func (c *Details) KeyHelp() string { return "TBD" } diff --git a/runtime/ui/controller/filetree_controller.go b/runtime/ui/controller/filetree.go index 5dc27db..df10a6b 100644 --- a/runtime/ui/controller/filetree_controller.go +++ b/runtime/ui/controller/filetree.go @@ -20,21 +20,21 @@ const ( type CompareType int -// FileTreeController holds the UI objects and data models for populating the right pane. Specifically the pane that +// FileTree holds the UI objects and data models for populating the right pane. Specifically the pane that // shows selected layer or aggregate file ASCII tree. -type FileTreeController struct { +type FileTree struct { name string gui *gocui.Gui view *gocui.View header *gocui.View - vm *viewmodel.FileTreeViewModel + vm *viewmodel.FileTree helpKeys []*key.Binding } // NewFileTreeController creates a new view object attached the the global [gocui] screen object. -func NewFileTreeController(name string, gui *gocui.Gui, tree *filetree.FileTree, refTrees []*filetree.FileTree, cache filetree.TreeCache) (controller *FileTreeController, err error) { - controller = new(FileTreeController) +func NewFileTreeController(name string, gui *gocui.Gui, tree *filetree.FileTree, refTrees []*filetree.FileTree, cache filetree.TreeCache) (controller *FileTree, err error) { + controller = new(FileTree) // populate main fields controller.name = name @@ -47,143 +47,143 @@ func NewFileTreeController(name string, gui *gocui.Gui, tree *filetree.FileTree, return controller, err } -func (controller *FileTreeController) Name() string { - return controller.name +func (c *FileTree) Name() string { + return c.name } -func (controller *FileTreeController) AreAttributesVisible() bool { - return controller.vm.ShowAttributes +func (c *FileTree) AreAttributesVisible() bool { + return c.vm.ShowAttributes } // Setup initializes the UI concerns within the context of a global [gocui] view object. -func (controller *FileTreeController) Setup(v *gocui.View, header *gocui.View) error { +func (c *FileTree) Setup(v *gocui.View, header *gocui.View) error { // set controller options - controller.view = v - controller.view.Editable = false - controller.view.Wrap = false - controller.view.Frame = false + c.view = v + c.view.Editable = false + c.view.Wrap = false + c.view.Frame = false - controller.header = header - controller.header.Editable = false - controller.header.Wrap = false - controller.header.Frame = false + c.header = header + c.header.Editable = false + c.header.Wrap = false + c.header.Frame = false var infos = []key.BindingInfo{ { ConfigKeys: []string{"keybinding.toggle-collapse-dir"}, - OnAction: controller.toggleCollapse, + OnAction: c.toggleCollapse, Display: "Collapse dir", }, { ConfigKeys: []string{"keybinding.toggle-collapse-all-dir"}, - OnAction: controller.toggleCollapseAll, + OnAction: c.toggleCollapseAll, Display: "Collapse all dir", }, { ConfigKeys: []string{"keybinding.toggle-added-files"}, - OnAction: func() error { return controller.toggleShowDiffType(filetree.Added) }, - IsSelected: func() bool { return !controller.vm.HiddenDiffTypes[filetree.Added] }, + OnAction: func() error { return c.toggleShowDiffType(filetree.Added) }, + IsSelected: func() bool { return !c.vm.HiddenDiffTypes[filetree.Added] }, Display: "Added", }, { ConfigKeys: []string{"keybinding.toggle-removed-files"}, - OnAction: func() error { return controller.toggleShowDiffType(filetree.Removed) }, - IsSelected: func() bool { return !controller.vm.HiddenDiffTypes[filetree.Removed] }, + OnAction: func() error { return c.toggleShowDiffType(filetree.Removed) }, + IsSelected: func() bool { return !c.vm.HiddenDiffTypes[filetree.Removed] }, Display: "Removed", }, { ConfigKeys: []string{"keybinding.toggle-modified-files"}, - OnAction: func() error { return controller.toggleShowDiffType(filetree.Modified) }, - IsSelected: func() bool { return !controller.vm.HiddenDiffTypes[filetree.Modified] }, + OnAction: func() error { return c.toggleShowDiffType(filetree.Modified) }, + IsSelected: func() bool { return !c.vm.HiddenDiffTypes[filetree.Modified] }, Display: "Modified", }, { ConfigKeys: []string{"keybinding.toggle-unchanged-files", "keybinding.toggle-unmodified-files"}, - OnAction: func() error { return controller.toggleShowDiffType(filetree.Unmodified) }, - IsSelected: func() bool { return !controller.vm.HiddenDiffTypes[filetree.Unmodified] }, + OnAction: func() error { return c.toggleShowDiffType(filetree.Unmodified) }, + IsSelected: func() bool { return !c.vm.HiddenDiffTypes[filetree.Unmodified] }, Display: "Unmodified", }, { ConfigKeys: []string{"keybinding.toggle-filetree-attributes"}, - OnAction: controller.toggleAttributes, - IsSelected: func() bool { return controller.vm.ShowAttributes }, + OnAction: c.toggleAttributes, + IsSelected: func() bool { return c.vm.ShowAttributes }, Display: "Attributes", }, { ConfigKeys: []string{"keybinding.page-up"}, - OnAction: controller.PageUp, + OnAction: c.PageUp, }, { ConfigKeys: []string{"keybinding.page-down"}, - OnAction: controller.PageDown, + OnAction: c.PageDown, }, { Key: gocui.KeyArrowDown, Modifier: gocui.ModNone, - OnAction: controller.CursorDown, + OnAction: c.CursorDown, }, { Key: gocui.KeyArrowUp, Modifier: gocui.ModNone, - OnAction: controller.CursorUp, + OnAction: c.CursorUp, }, { Key: gocui.KeyArrowLeft, Modifier: gocui.ModNone, - OnAction: controller.CursorLeft, + OnAction: c.CursorLeft, }, { Key: gocui.KeyArrowRight, Modifier: gocui.ModNone, - OnAction: controller.CursorRight, + OnAction: c.CursorRight, }, } - helpKeys, err := key.GenerateBindings(controller.gui, controller.name, infos) + helpKeys, err := key.GenerateBindings(c.gui, c.name, infos) if err != nil { return err } - controller.helpKeys = helpKeys + c.helpKeys = helpKeys - _, height := controller.view.Size() - controller.vm.Setup(0, height) - _ = controller.Update() - _ = controller.Render() + _, height := c.view.Size() + c.vm.Setup(0, height) + _ = c.Update() + _ = c.Render() return nil } // IsVisible indicates if the file tree view pane is currently initialized -func (controller *FileTreeController) IsVisible() bool { - return controller != nil +func (c *FileTree) IsVisible() bool { + return c != nil } // ResetCursor moves the cursor back to the top of the buffer and translates to the top of the buffer. -func (controller *FileTreeController) resetCursor() { - _ = controller.view.SetCursor(0, 0) - controller.vm.ResetCursor() +func (c *FileTree) resetCursor() { + _ = c.view.SetCursor(0, 0) + c.vm.ResetCursor() } // SetTreeByLayer populates the view model by stacking the indicated image layer file trees. -func (controller *FileTreeController) setTreeByLayer(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop int) error { - err := controller.vm.SetTreeByLayer(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop) +func (c *FileTree) setTreeByLayer(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop int) error { + err := c.vm.SetTreeByLayer(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop) if err != nil { return err } // controller.ResetCursor() - _ = controller.Update() - return controller.Render() + _ = c.Update() + return c.Render() } // CursorDown moves the cursor down and renders the view. // Note: we cannot use the gocui buffer since any state change requires writing the entire tree to the buffer. // Instead we are keeping an upper and lower bounds of the tree string to render and only flushing // this range into the view buffer. This is much faster when tree sizes are large. -func (controller *FileTreeController) CursorDown() error { - if controller.vm.CursorDown() { - return controller.Render() +func (c *FileTree) CursorDown() error { + if c.vm.CursorDown() { + return c.Render() } return nil } @@ -192,82 +192,82 @@ func (controller *FileTreeController) CursorDown() error { // Note: we cannot use the gocui buffer since any state change requires writing the entire tree to the buffer. // Instead we are keeping an upper and lower bounds of the tree string to render and only flushing // this range into the view buffer. This is much faster when tree sizes are large. -func (controller *FileTreeController) CursorUp() error { - if controller.vm.CursorUp() { - return controller.Render() +func (c *FileTree) CursorUp() error { + if c.vm.CursorUp() { + return c.Render() } return nil } // CursorLeft moves the cursor up until we reach the Parent Node or top of the tree -func (controller *FileTreeController) CursorLeft() error { - err := controller.vm.CursorLeft(filterRegex()) +func (c *FileTree) CursorLeft() error { + err := c.vm.CursorLeft(filterRegex()) if err != nil { return err } - _ = controller.Update() - return controller.Render() + _ = c.Update() + return c.Render() } // CursorRight descends into directory expanding it if needed -func (controller *FileTreeController) CursorRight() error { - err := controller.vm.CursorRight(filterRegex()) +func (c *FileTree) CursorRight() error { + err := c.vm.CursorRight(filterRegex()) if err != nil { return err } - _ = controller.Update() - return controller.Render() + _ = c.Update() + return c.Render() } // PageDown moves to next page putting the cursor on top -func (controller *FileTreeController) PageDown() error { - err := controller.vm.PageDown() +func (c *FileTree) PageDown() error { + err := c.vm.PageDown() if err != nil { return err } - return controller.Render() + return c.Render() } // PageUp moves to previous page putting the cursor on top -func (controller *FileTreeController) PageUp() error { - err := controller.vm.PageUp() +func (c *FileTree) PageUp() error { + err := c.vm.PageUp() if err != nil { return err } - return controller.Render() + return c.Render() } // getAbsPositionNode determines the selected screen cursor's location in the file tree, returning the selected FileNode. -// func (controller *FileTreeController) getAbsPositionNode() (node *filetree.FileNode) { +// func (controller *FileTree) getAbsPositionNode() (node *filetree.FileNode) { // return controller.vm.getAbsPositionNode(filterRegex()) // } // ToggleCollapse will collapse/expand the selected FileNode. -func (controller *FileTreeController) toggleCollapse() error { - err := controller.vm.ToggleCollapse(filterRegex()) +func (c *FileTree) toggleCollapse() error { + err := c.vm.ToggleCollapse(filterRegex()) if err != nil { return err } - _ = controller.Update() - return controller.Render() + _ = c.Update() + return c.Render() } // ToggleCollapseAll will collapse/expand the all directories. -func (controller *FileTreeController) toggleCollapseAll() error { - err := controller.vm.ToggleCollapseAll() +func (c *FileTree) toggleCollapseAll() error { + err := c.vm.ToggleCollapseAll() if err != nil { return err } - if controller.vm.CollapseAll { - controller.resetCursor() + if c.vm.CollapseAll { + c.resetCursor() } - _ = controller.Update() - return controller.Render() + _ = c.Update() + return c.Render() } // ToggleAttributes will show/hide file attributes -func (controller *FileTreeController) toggleAttributes() error { - err := controller.vm.ToggleAttributes() +func (c *FileTree) toggleAttributes() error { + err := c.vm.ToggleAttributes() if err != nil { return err } @@ -276,8 +276,8 @@ func (controller *FileTreeController) toggleAttributes() error { } // ToggleShowDiffType will show/hide the selected DiffType in the filetree pane. -func (controller *FileTreeController) toggleShowDiffType(diffType filetree.DiffType) error { - controller.vm.ToggleShowDiffType(diffType) +func (c *FileTree) toggleShowDiffType(diffType filetree.DiffType) error { + c.vm.ToggleShowDiffType(diffType) // we need to render the changes to the status pane as well (not just this contoller/view) return controllers.UpdateAndRender() } @@ -301,58 +301,58 @@ func filterRegex() *regexp.Regexp { } // OnLayoutChange is called by the UI framework to inform the view-model of the new screen dimensions -func (controller *FileTreeController) OnLayoutChange(resized bool) error { - _ = controller.Update() +func (c *FileTree) OnLayoutChange(resized bool) error { + _ = c.Update() if resized { - return controller.Render() + return c.Render() } return nil } // Update refreshes the state objects for future rendering. -func (controller *FileTreeController) Update() error { +func (c *FileTree) Update() error { var width, height int - if controller.view != nil { - width, height = controller.view.Size() + if c.view != nil { + width, height = c.view.Size() } else { // before the TUI is setup there may not be a controller to reference. Use the entire screen as reference. - width, height = controller.gui.Size() + width, height = c.gui.Size() } // height should account for the header - return controller.vm.Update(filterRegex(), width, height-1) + return c.vm.Update(filterRegex(), width, height-1) } // Render flushes the state objects (file tree) to the pane. -func (controller *FileTreeController) Render() error { +func (c *FileTree) Render() error { title := "Current Layer Contents" if controllers.Layer.CompareMode == CompareAll { title = "Aggregated Layer Contents" } // indicate when selected - if controller.gui.CurrentView() == controller.view { + if c.gui.CurrentView() == c.view { title = "● " + title } - controller.gui.Update(func(g *gocui.Gui) error { + c.gui.Update(func(g *gocui.Gui) error { // update the header - controller.header.Clear() + c.header.Clear() width, _ := g.Size() headerStr := fmt.Sprintf("[%s]%s\n", title, strings.Repeat("─", width*2)) - if controller.vm.ShowAttributes { + if c.vm.ShowAttributes { headerStr += fmt.Sprintf(filetree.AttributeFormat+" %s", "P", "ermission", "UID:GID", "Size", "Filetree") } - _, _ = fmt.Fprintln(controller.header, format.Header(vtclean.Clean(headerStr, false))) + _, _ = fmt.Fprintln(c.header, format.Header(vtclean.Clean(headerStr, false))) // update the contents - controller.view.Clear() - err := controller.vm.Render() + c.view.Clear() + err := c.vm.Render() if err != nil { return err } - _, err = fmt.Fprint(controller.view, controller.vm.Buffer.String()) + _, err = fmt.Fprint(c.view, c.vm.Buffer.String()) return err }) @@ -360,9 +360,9 @@ func (controller *FileTreeController) Render() error { } // KeyHelp indicates all the possible actions a user can take while the current pane is selected. -func (controller *FileTreeController) KeyHelp() string { +func (c *FileTree) KeyHelp() string { var help string - for _, binding := range controller.helpKeys { + for _, binding := range c.helpKeys { help += binding.RenderKeyHelp() } return help diff --git a/runtime/ui/controller/filter_controller.go b/runtime/ui/controller/filter.go index 2ff718d..51c0e3b 100644 --- a/runtime/ui/controller/filter_controller.go +++ b/runtime/ui/controller/filter.go @@ -7,9 +7,9 @@ import ( "github.com/wagoodman/dive/runtime/ui/format" ) -// FilterController holds the UI objects and data models for populating the bottom row. Specifically the pane that +// Filter holds the UI objects and data models for populating the bottom row. Specifically the pane that // allows the user to filter the file tree by path. -type FilterController struct { +type Filter struct { name string gui *gocui.Gui view *gocui.View @@ -20,8 +20,8 @@ type FilterController struct { } // NewFilterController creates a new view object attached the the global [gocui] screen object. -func NewFilterController(name string, gui *gocui.Gui) (controller *FilterController) { - controller = new(FilterController) +func NewFilterController(name string, gui *gocui.Gui) (controller *Filter) { + controller = new(Filter) // populate main fields controller.name = name @@ -32,40 +32,40 @@ func NewFilterController(name string, gui *gocui.Gui) (controller *FilterControl return controller } -func (controller *FilterController) Name() string { - return controller.name +func (c *Filter) Name() string { + return c.name } // Setup initializes the UI concerns within the context of a global [gocui] view object. -func (controller *FilterController) Setup(v *gocui.View, header *gocui.View) error { +func (c *Filter) Setup(v *gocui.View, header *gocui.View) error { // set controller options - controller.view = v - controller.maxLength = 200 - controller.view.Frame = false - controller.view.BgColor = gocui.AttrReverse - controller.view.Editable = true - controller.view.Editor = controller - - controller.header = header - controller.header.BgColor = gocui.AttrReverse - controller.header.Editable = false - controller.header.Wrap = false - controller.header.Frame = false - - return controller.Render() + c.view = v + c.maxLength = 200 + c.view.Frame = false + c.view.BgColor = gocui.AttrReverse + c.view.Editable = true + c.view.Editor = c + + c.header = header + c.header.BgColor = gocui.AttrReverse + c.header.Editable = false + c.header.Wrap = false + c.header.Frame = false + + return c.Render() } // ToggleFilterView shows/hides the file tree filter pane. -func (controller *FilterController) ToggleVisible() error { +func (c *Filter) ToggleVisible() error { // delete all user input from the tree view - controller.view.Clear() + c.view.Clear() // toggle hiding - controller.hidden = !controller.hidden + c.hidden = !c.hidden - if !controller.hidden { - _, err := controller.gui.SetCurrentView(controller.name) + if !c.hidden { + _, err := c.gui.SetCurrentView(c.name) if err != nil { logrus.Error("unable to toggle filter view: ", err) return err @@ -76,41 +76,41 @@ func (controller *FilterController) ToggleVisible() error { // reset the cursor for the next time it is visible // Note: there is a subtle gocui behavior here where this cannot be called when the view // is newly visible. Is this a problem with dive or gocui? - return controller.view.SetCursor(0, 0) + return c.view.SetCursor(0, 0) } // todo: remove the need for this -func (controller *FilterController) HeaderStr() string { - return controller.headerStr +func (c *Filter) HeaderStr() string { + return c.headerStr } // IsVisible indicates if the filter view pane is currently initialized -func (controller *FilterController) IsVisible() bool { - if controller == nil { +func (c *Filter) IsVisible() bool { + if c == nil { return false } - return !controller.hidden + return !c.hidden } // CursorDown moves the cursor down in the filter pane (currently indicates nothing). -func (controller *FilterController) CursorDown() error { +func (c *Filter) CursorDown() error { return nil } // CursorUp moves the cursor up in the filter pane (currently indicates nothing). -func (controller *FilterController) CursorUp() error { +func (c *Filter) CursorUp() error { return nil } // Edit intercepts the key press events in the filer view to update the file view in real time. -func (controller *FilterController) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) { - if !controller.IsVisible() { +func (c *Filter) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) { + if !c.IsVisible() { return } cx, _ := v.Cursor() ox, _ := v.Origin() - limit := ox+cx+1 > controller.maxLength + limit := ox+cx+1 > c.maxLength switch { case ch != 0 && mod == 0 && !limit: v.EditWrite(ch) @@ -126,14 +126,14 @@ func (controller *FilterController) Edit(v *gocui.View, key gocui.Key, ch rune, } // Update refreshes the state objects for future rendering (currently does nothing). -func (controller *FilterController) Update() error { +func (c *Filter) Update() error { return nil } // Render flushes the state objects to the screen. Currently this is the users path filter input. -func (controller *FilterController) Render() error { - controller.gui.Update(func(g *gocui.Gui) error { - _, err := fmt.Fprintln(controller.header, format.Header(controller.headerStr)) +func (c *Filter) Render() error { + c.gui.Update(func(g *gocui.Gui) error { + _, err := fmt.Fprintln(c.header, format.Header(c.headerStr)) if err != nil { logrus.Error("unable to write to buffer: ", err) } @@ -143,6 +143,6 @@ func (controller *FilterController) Render() error { } // KeyHelp indicates all the possible actions a user can take while the current pane is selected. -func (controller *FilterController) KeyHelp() string { +func (c *Filter) KeyHelp() string { return format.StatusControlNormal("▏Type to filter the file tree ") } diff --git a/runtime/ui/controller/layer_controller.go b/runtime/ui/controller/layer.go index a0bf0c0..948a0b1 100644 --- a/runtime/ui/controller/layer_controller.go +++ b/runtime/ui/controller/layer.go @@ -13,9 +13,9 @@ import ( "github.com/spf13/viper" ) -// LayerController holds the UI objects and data models for populating the lower-left pane. Specifically the pane that +// Layer holds the UI objects and data models for populating the lower-left pane. Specifically the pane that // shows the image layers and layer selector. -type LayerController struct { +type Layer struct { name string gui *gocui.Gui view *gocui.View @@ -30,8 +30,8 @@ type LayerController struct { } // NewLayerController creates a new view object attached the the global [gocui] screen object. -func NewLayerController(name string, gui *gocui.Gui, layers []*image.Layer) (controller *LayerController, err error) { - controller = new(LayerController) +func NewLayerController(name string, gui *gocui.Gui, layers []*image.Layer) (controller *Layer, err error) { + controller = new(Layer) // populate main fields controller.name = name @@ -50,196 +50,196 @@ func NewLayerController(name string, gui *gocui.Gui, layers []*image.Layer) (con return controller, err } -func (controller *LayerController) Name() string { |