summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/ci/evaluator.go6
-rw-r--r--runtime/config/application_config.go159
-rw-r--r--runtime/config/diff_config.go26
-rw-r--r--runtime/config/file_tree_config.go7
-rw-r--r--runtime/config/keybinding_config.go19
-rw-r--r--runtime/config/layer_view_config.go5
-rw-r--r--runtime/config/logging.go7
-rw-r--r--runtime/log.go11
-rw-r--r--runtime/logger/logger.go23
-rw-r--r--runtime/run.go25
-rw-r--r--runtime/ui/app.go59
-rw-r--r--runtime/ui/components/app_config.go44
-rw-r--r--runtime/ui/components/dive_application.go12
-rw-r--r--runtime/ui/components/filetree_primative.go44
-rw-r--r--runtime/ui/components/filter_primative.go12
-rw-r--r--runtime/ui/components/helpers/key_binding.go8
-rw-r--r--runtime/ui/components/keybinding_primitive.go14
-rw-r--r--runtime/ui/components/layer_details_view.go2
-rw-r--r--runtime/ui/components/layers_primative.go32
-rw-r--r--runtime/ui/components/visible_grid.go9
-rw-r--r--runtime/ui/components/wrapper_primative.go6
-rw-r--r--runtime/ui/constructors/key_config.go31
-rw-r--r--runtime/ui/viewmodels/filter_view_model.go6
-rw-r--r--runtime/ui/viewmodels/layers_view_model.go9
-rw-r--r--runtime/ui/viewmodels/tree_view_model.go12
25 files changed, 425 insertions, 163 deletions
diff --git a/runtime/ci/evaluator.go b/runtime/ci/evaluator.go
index b567e9c..2279df4 100644
--- a/runtime/ci/evaluator.go
+++ b/runtime/ci/evaluator.go
@@ -7,12 +7,10 @@ import (
"strings"
"github.com/dustin/go-humanize"
+ "github.com/logrusorgru/aurora"
+ "github.com/spf13/viper"
"github.com/wagoodman/dive/dive/image"
"github.com/wagoodman/dive/utils"
-
- "github.com/spf13/viper"
-
- "github.com/logrusorgru/aurora"
)
type CiEvaluator struct {
diff --git a/runtime/config/application_config.go b/runtime/config/application_config.go
new file mode 100644
index 0000000..a3f629e
--- /dev/null
+++ b/runtime/config/application_config.go
@@ -0,0 +1,159 @@
+package config
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path"
+ "strings"
+
+ "github.com/mitchellh/go-homedir"
+ "github.com/spf13/viper"
+ "gopkg.in/yaml.v2"
+)
+
+type ApplicationConfig struct {
+ ConfigFile string
+ FileTree fileTreeViewConfig `mapstructure:"filetree"`
+ Layer layerViewConfig `mapstructure:"layer"`
+ Keybinding keybindingConfig `mapstructure:"keybinding"`
+ Diff diffConfig `mapstructure:"diff"`
+ Log loggingConfig `mapstructure:"log"`
+ ContainerEngine string `mapstructure:"container-engine"`
+ IgnoreErrors bool `mapstructure:"ignore-errors"`
+}
+
+func LoadApplicationConfig(v *viper.Viper, cfgFile string) (*ApplicationConfig, error) {
+ setDefaultConfigValues(v)
+ readConfig(cfgFile)
+
+ instance := &ApplicationConfig{}
+ if err := v.Unmarshal(instance); err != nil {
+ return nil, fmt.Errorf("unable to unmarshal application config: %w", err)
+ }
+
+ instance.ConfigFile = v.ConfigFileUsed()
+
+ return instance, instance.build()
+}
+
+func (a *ApplicationConfig) build() error {
+ // currently no other configs need to be built
+ return a.Diff.build()
+}
+
+func (a ApplicationConfig) String() string {
+ content, err := yaml.Marshal(&a)
+ if err != nil {
+ return "[no config]"
+ }
+ return string(content)
+}
+
+func readConfig(cfgFile string) {
+ viper.SetEnvPrefix("DIVE")
+ // replace all - with _ when looking for matching environment variables
+ viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
+ viper.AutomaticEnv()
+
+ // if config files are present, load them
+ if cfgFile == "" {
+ // default configs are ignored if not found
+ cfgFile = getDefaultCfgFile()
+ }
+
+ if cfgFile == "" {
+ return
+ }
+
+ viper.SetConfigFile(cfgFile)
+ if err := viper.ReadInConfig(); err != nil {
+ panic(fmt.Errorf("unable to read config file: %w", err))
+ }
+}
+
+// getDefaultCfgFile checks for config file in paths from xdg specs
+// and in $HOME/.config/dive/ directory
+// defaults to $HOME/.dive.yaml
+func getDefaultCfgFile() string {
+ home, err := homedir.Dir()
+ if err != nil {
+ err = fmt.Errorf("unable to get home dir: %w", err)
+ panic(err)
+ }
+
+ xdgHome := os.Getenv("XDG_CONFIG_HOME")
+ xdgDirs := os.Getenv("XDG_CONFIG_DIRS")
+ xdgPaths := append([]string{xdgHome}, strings.Split(xdgDirs, ":")...)
+ allDirs := append(xdgPaths, path.Join(home, ".config"))
+
+ for _, val := range allDirs {
+ file := findInPath(val)
+ if len(file) > 0 {
+ return file
+ }
+ }
+
+ for _, altPath := range []string{path.Join(home, ".dive.yaml"), path.Join(home, ".dive.yml")} {
+ if _, err := os.Stat(altPath); os.IsNotExist(err) {
+ continue
+ } else if err != nil {
+ panic(err)
+ }
+ return altPath
+ }
+ return ""
+}
+
+// findInPath returns first "*.yaml" or "*.yml" file in path's subdirectory "dive"
+// if not found returns empty string
+func findInPath(pathTo string) string {
+ directory := path.Join(pathTo, "dive")
+ files, err := ioutil.ReadDir(directory)
+ if err != nil {
+ return ""
+ }
+
+ for _, file := range files {
+ filename := file.Name()
+ if path.Ext(filename) == ".yaml" || path.Ext(filename) == ".yml" {
+ return path.Join(directory, filename)
+ }
+ }
+ return ""
+}
+
+func setDefaultConfigValues(v *viper.Viper) {
+ // logging
+ v.SetDefault("log.enabled", true)
+ v.SetDefault("log.level", "debug")
+ v.SetDefault("log.path", "./dive.log")
+ // keybindings: status view / global
+ v.SetDefault("keybinding.quit", "Ctrl+C")
+ v.SetDefault("keybinding.toggle-view", "Tab")
+ v.SetDefault("keybinding.filter-files", "Ctrl+f")
+ // keybindings: layer view
+ v.SetDefault("keybinding.compare-all", "Ctrl+A")
+ v.SetDefault("keybinding.compare-layer", "Ctrl+L")
+ // keybindings: filetree view
+ v.SetDefault("keybinding.toggle-collapse-dir", "Space")
+ v.SetDefault("keybinding.toggle-collapse-all-dir", "Ctrl+Space")
+ v.SetDefault("keybinding.toggle-filetree-attributes", "Ctrl+B")
+ v.SetDefault("keybinding.toggle-added-files", "Ctrl+A")
+ v.SetDefault("keybinding.toggle-removed-files", "Ctrl+R")
+ v.SetDefault("keybinding.toggle-modified-files", "Ctrl+N")
+ v.SetDefault("keybinding.toggle-unmodified-files", "Ctrl+U")
+ v.SetDefault("keybinding.toggle-wrap-tree", "Ctrl+P")
+ v.SetDefault("keybinding.page-up", "PgUp")
+ v.SetDefault("keybinding.page-down", "PgDn")
+ // layer view
+ v.SetDefault("layer.show-aggregated-changes", false)
+ // filetree view
+ v.SetDefault("diff.hide", "")
+ v.SetDefault("filetree.collapse-dir", false)
+ v.SetDefault("filetree.pane-width", 0.5)
+ v.SetDefault("filetree.show-attributes", true)
+ // general behavior
+ v.SetDefault("container-engine", "docker")
+ v.SetDefault("ignore-errors", false)
+}
diff --git a/runtime/config/diff_config.go b/runtime/config/diff_config.go
new file mode 100644
index 0000000..761af23
--- /dev/null
+++ b/runtime/config/diff_config.go
@@ -0,0 +1,26 @@
+package config
+
+import "github.com/wagoodman/dive/dive/filetree"
+
+type diffConfig struct {
+ // note: this really relates to the fileTreeViewConfig, but is here for legacy reasons
+ Hide []string `mapstructure:"hide"`
+ DiffTypes []filetree.DiffType `yaml:"-"`
+}
+
+func (c *diffConfig) build() error {
+ c.DiffTypes = nil
+ for _, hideType := range c.Hide {
+ switch hideType {
+ case "added":
+ c.DiffTypes = append(c.DiffTypes, filetree.Added)
+ case "removed":
+ c.DiffTypes = append(c.DiffTypes, filetree.Removed)
+ case "modified":
+ c.DiffTypes = append(c.DiffTypes, filetree.Modified)
+ case "unmodified":
+ c.DiffTypes = append(c.DiffTypes, filetree.Unmodified)
+ }
+ }
+ return nil
+}
diff --git a/runtime/config/file_tree_config.go b/runtime/config/file_tree_config.go
new file mode 100644
index 0000000..07ea89e
--- /dev/null
+++ b/runtime/config/file_tree_config.go
@@ -0,0 +1,7 @@
+package config
+
+type fileTreeViewConfig struct {
+ CollapseDir bool `mapstructure:"collapse-dir"`
+ PaneWidthRatio float64 `mapstructure:"pane-width"`
+ ShowAttributes bool `mapstructure:"show-attributes"`
+}
diff --git a/runtime/config/keybinding_config.go b/runtime/config/keybinding_config.go
new file mode 100644
index 0000000..6b14dc8
--- /dev/null
+++ b/runtime/config/keybinding_config.go
@@ -0,0 +1,19 @@
+package config
+
+type keybindingConfig struct {
+ Quit string `mapstructure:"quit"`
+ ToggleViews string `mapstructure:"toggle-view"`
+ FilterFiles string `mapstructure:"filter-files"`
+ CompareAll string `mapstructure:"compare-all"`
+ CompareLayer string `mapstructure:"compare-layer"`
+ ToggleCollapseDir string `mapstructure:"toggle-collapse-dir"`
+ ToggleCollapseAllDir string `mapstructure:"toggle-collapse-all-dir"`
+ ToggleFileTreeAttributes string `mapstructure:"toggle-filetree-attributes"`
+ ToggleAddedFiles string `mapstructure:"toggle-added-files"`
+ ToggleRemovedFiles string `mapstructure:"toggle-removed-files"`
+ ToggleModifiedFiles string `mapstructure:"toggle-modified-files"`
+ ToggleUnmodifiedFiles string `mapstructure:"toggle-unmodified-files"`
+ ToggleWrapTree string `mapstructure:"toggle-wrap-tree"`
+ PageUp string `mapstructure:"page-up"`
+ PageDown string `mapstructure:"page-down"`
+}
diff --git a/runtime/config/layer_view_config.go b/runtime/config/layer_view_config.go
new file mode 100644
index 0000000..6833e74
--- /dev/null
+++ b/runtime/config/layer_view_config.go
@@ -0,0 +1,5 @@
+package config
+
+type layerViewConfig struct {
+ ShowAggregatedChanges bool `mapstructure:"show-aggregated-changes"`
+}
diff --git a/runtime/config/logging.go b/runtime/config/logging.go
new file mode 100644
index 0000000..a18e9ce
--- /dev/null
+++ b/runtime/config/logging.go
@@ -0,0 +1,7 @@
+package config
+
+type loggingConfig struct {
+ Enabled bool `mapstructure:"enabled"`
+ Level string `mapstructure:"level"`
+ Path string `mapstructure:"path"`
+}
diff --git a/runtime/log.go b/runtime/log.go
new file mode 100644
index 0000000..735dcf8
--- /dev/null
+++ b/runtime/log.go
@@ -0,0 +1,11 @@
+package runtime
+
+import (
+ "github.com/wagoodman/dive/internal/log"
+ "github.com/wagoodman/dive/runtime/logger"
+)
+
+// SetLogger sets the logger object used for all logging calls.
+func SetLogger(logger logger.Logger) {
+ log.Log = logger
+}
diff --git a/runtime/logger/logger.go b/runtime/logger/logger.go
new file mode 100644
index 0000000..a311099
--- /dev/null
+++ b/runtime/logger/logger.go
@@ -0,0 +1,23 @@
+package logger
+
+type Logger interface {
+ MessageLogger
+ FieldLogger
+}
+
+type FieldLogger interface {
+ WithFields(fields ...interface{}) MessageLogger
+}
+
+type MessageLogger interface {
+ Errorf(format string, args ...interface{})
+ Error(args ...interface{})
+ Warnf(format string, args ...interface{})
+ Warn(args ...interface{})
+ Infof(format string, args ...interface{})
+ Info(args ...interface{})
+ Debugf(format string, args ...interface{})
+ Debug(args ...interface{})
+ Tracef(format string, args ...interface{})
+ Trace(args ...interface{})
+}
diff --git a/runtime/run.go b/runtime/run.go
index 3831c8a..1273808 100644
--- a/runtime/run.go
+++ b/runtime/run.go
@@ -4,19 +4,21 @@ import (
"fmt"
"os"
+ "github.com/wagoodman/dive/runtime/config"
+
"github.com/dustin/go-humanize"
- "github.com/sirupsen/logrus"
"github.com/spf13/afero"
"github.com/wagoodman/dive/dive"
"github.com/wagoodman/dive/dive/filetree"
"github.com/wagoodman/dive/dive/image"
+ "github.com/wagoodman/dive/internal/log"
"github.com/wagoodman/dive/runtime/ci"
"github.com/wagoodman/dive/runtime/export"
"github.com/wagoodman/dive/runtime/ui"
"github.com/wagoodman/dive/utils"
)
-func run(enableUi bool, options Options, imageResolver image.Resolver, events eventChannel, filesystem afero.Fs) {
+func run(config config.ApplicationConfig, enableUi bool, options Options, imageResolver image.Resolver, events eventChannel, filesystem afero.Fs) {
var img *image.Image
var err error
defer close(events)
@@ -24,6 +26,10 @@ func run(enableUi bool, options Options, imageResolver image.Resolver, events ev
doExport := options.ExportFile != ""
doBuild := len(options.BuildArgs) > 0
+ if config.ConfigFile != "" {
+ events.message(fmt.Sprintf("Using config file: %s", config.ConfigFile))
+ }
+
if doBuild {
events.message(utils.TitleFormat("Building image..."))
img, err = imageResolver.Build(options.BuildArgs)
@@ -102,9 +108,11 @@ func run(enableUi bool, options Options, imageResolver image.Resolver, events ev
}
if enableUi {
- err = ui.Run(analysis, treeStack)
+ err = ui.Run(config, analysis, treeStack)
if err != nil {
- logrus.Fatal("run info exit: ", err.Error())
+ log.WithFields(
+ "error", err,
+ ).Errorf("UI error")
events.exitWithError(err)
return
}
@@ -112,20 +120,19 @@ func run(enableUi bool, options Options, imageResolver image.Resolver, events ev
}
}
-func Run(options Options) {
+func Run(options Options, config config.ApplicationConfig) {
var exitCode int
var events = make(eventChannel)
imageResolver, err := dive.GetImageResolver(options.Source)
if err != nil {
message := "cannot determine image provider"
- logrus.Error(message)
- logrus.Error(err)
+ log.Errorf("%s : %+v", message, err.Error())
fmt.Fprintf(os.Stderr, "%s: %+v\n", message, err)
os.Exit(1)
}
- go run(true, options, imageResolver, events, afero.NewOsFs())
+ go run(config, true, options, imageResolver, events, afero.NewOsFs())
for event := range events {
if event.stdout != "" {
@@ -140,7 +147,7 @@ func Run(options Options) {
}
if event.err != nil {
- logrus.Error(event.err)
+ log.Error(event.err)
_, err := fmt.Fprintln(os.Stderr, event.err.Error())
if err != nil {
fmt.Println("error: could not write to buffer:", err)
diff --git a/runtime/ui/app.go b/runtime/ui/app.go
index e9a576a..4c629eb 100644
--- a/runtime/ui/app.go
+++ b/runtime/ui/app.go
@@ -2,12 +2,12 @@ package ui
import (
"fmt"
- "log"
"sync"
+ "github.com/wagoodman/dive/runtime/config"
+
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
- "github.com/sirupsen/logrus"
"github.com/wagoodman/dive/dive/filetree"
"github.com/wagoodman/dive/dive/image"
"github.com/wagoodman/dive/runtime/ui/components"
@@ -28,27 +28,36 @@ type UI struct {
fileTree tview.Primitive
}
-func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetree.Comparer) (*UI, error) {
+func newApp(config config.ApplicationConfig, app *tview.Application, analysis *image.AnalysisResult, cache filetree.Comparer) (*UI, error) {
var err error
once.Do(func() {
// TODO: Extract initilaization logic into its own package
format.SyncWithTermColors()
- config := constructors.NewKeyConfig()
- appConfig := components.AppConfig{}
+ keyConfig := constructors.NewKeyConfig()
+
diveApplication := components.NewDiveApplication(app)
//initialize viewmodels
- modelConfig := constructors.ModelConfig{
- Cache: &CacheWrapper{Cache: &cache},
- Layers: analysis.Layers,
- }
- _, layersViewModel, treeViewModel, err := constructors.InitializeModels(modelConfig)
+ filterViewModel := viewmodels.NewFilterViewModel(nil)
+ layersViewModel := viewmodels.NewLayersViewModel(analysis.Layers)
+ cacheWrapper := CacheWrapper{Cache: &cache}
+ treeViewModel, err := viewmodels.NewTreeViewModel(&cacheWrapper, layersViewModel, filterViewModel)
if err != nil {
- log.Fatal(fmt.Errorf("unable to initialize viewmodels: %q", err))
+ panic(err)
}
+ // TODO: this seemed to be partially pushed, commented out for the meantime
+ //modelConfig := constructors.ModelConfig{
+ // Cache: &CacheWrapper{Cache: &cache},
+ // Layers: analysis.Layers,
+ //}
+ //_, layersViewModel, treeViewModel, err := constructors.InitializeModels(modelConfig)
+ //if err != nil {
+ // log.Fatal(fmt.Errorf("unable to initialize viewmodels: %q", err))
+ //}
+
regularLayerDetailsView := components.NewLayerDetailsView(layersViewModel).Setup()
layerDetailsBox := components.NewWrapper("Layer Details", "", regularLayerDetailsView).Setup()
layerDetailsBox.SetVisibility(components.MinHeightVisibility(10))
@@ -60,13 +69,13 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr
filterView := components.NewFilterView(treeViewModel).Setup()
- layersView := components.NewLayerList(treeViewModel).Setup(config)
+ layersView := components.NewLayerList(treeViewModel).Setup(keyConfig)
layerSubtitle := fmt.Sprintf("Cmp%7s %s", "Size", "Command")
layersBox := components.NewWrapper("Layers", layerSubtitle, layersView).Setup()
fileTreeView := components.NewTreeView(treeViewModel)
- fileTreeView = fileTreeView.Setup(config)
+ fileTreeView = fileTreeView.Setup(keyConfig)
fileTreeBox := components.NewWrapper("Current Layer Contents", "", fileTreeView).Setup()
keyMenuView := components.NewKeyMenuView()
@@ -92,7 +101,8 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr
AddItem(filterView, 1, 0, false).
SetConsumers(filterView, fileTreeBox)
- leftPortion, rightPortion := appConfig.GetPaneWidth()
+ rightPortion := int(config.FileTree.PaneWidthRatio * 100)
+ leftPortion := int((1 - config.FileTree.PaneWidthRatio) * 100)
totalVisibleGrid.AddItem(leftVisibleGrid, 0, leftPortion, true).
AddItem(rightVisibleGrid, 0, rightPortion, false)
@@ -104,18 +114,18 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr
keyMenuView.AddBoundViews(diveApplication)
- quitBinding, err := config.GetKeyBinding("keybinding.quit")
+ quitBinding, err := keyConfig.GetKeyBinding("keybinding.quit")
if err != nil {
// TODO handle this as an error
panic(err)
}
- filterBinding, err := config.GetKeyBinding("keybinding.filter-files")
+ filterBinding, err := keyConfig.GetKeyBinding("keybinding.filter-files")
if err != nil {
// TODO handle this as an error
panic(err)
}
- switchBinding, err := config.GetKeyBinding("keybinding.toggle-view")
+ switchBinding, err := keyConfig.GetKeyBinding("keybinding.toggle-view")
if err != nil {
// TODO handle this as an error
panic(err)
@@ -154,22 +164,22 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr
diveApplication.SetFocus(gridWithFooter)
// additional setup configuration
- if appConfig.GetAggregateLayerSetting() {
+ if config.Layer.ShowAggregatedChanges {
err := layersViewModel.SwitchLayerMode()
if err != nil {
panic(err)
}
}
- if appConfig.GetCollapseDir() {
+ if config.FileTree.CollapseDir {
fileTreeView.CollapseOrExpandAll()
}
- for _, hideType := range appConfig.GetDefaultHide() {
+ for _, hideType := range config.Diff.DiffTypes {
treeViewModel.ToggleHiddenFileType(hideType)
}
- if appConfig.GetShowAttributes() {
+ if config.FileTree.ShowAttributes {
fileTreeView.ToggleHideAttributes()
}
})
@@ -178,18 +188,15 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr
}
// Run is the UI entrypoint.
-func Run(analysis *image.AnalysisResult, treeStack filetree.Comparer) error {
- app := tview.NewApplication()
- _, err := newApp(app, analysis, treeStack)
+func Run(config config.ApplicationConfig, analysis *image.AnalysisResult, treeStack filetree.Comparer) error {
+ _, err := newApp(config, tview.NewApplication(), analysis, treeStack)
if err != nil {
return err
}
if err = uiSingleton.app.Run(); err != nil {
- logrus.Error("app error: ", err.Error())
return err
}
- logrus.Info("app run loop exited")
return nil
}
diff --git a/runtime/ui/components/app_config.go b/runtime/ui/components/app_config.go
deleted file mode 100644
index 02b568c..0000000
--- a/runtime/ui/components/app_config.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package components
-
-import (
- "github.com/spf13/viper"
- "github.com/wagoodman/dive/dive/filetree"
-)
-
-type AppConfig struct {}
-
-func (a *AppConfig) GetDefaultHide() (result []filetree.DiffType) {
- slice := viper.GetStringSlice("diff.hide")
- for _, hideType := range slice {
- switch hideType{
- case "added":
- result = append(result, filetree.Added)
- case "removed":
- result = append(result, filetree.Removed)
- case "modified":
- result = append(result, filetree.Modified)
- case "unmodified":
- result = append(result, filetree.Unmodified)
- }
- }
-
- return result
-}
-
-func (a *AppConfig) GetAggregateLayerSetting() bool {
- return viper.GetBool("layer.show-aggregated-changes")
-}
-
-func (a *AppConfig) GetCollapseDir() bool {
- return viper.GetBool("filetree.collapse-dir")
-}
-
-func (a *AppConfig) GetPaneWidth() (int,int) {
- fwp := viper.GetFloat64("filetree.pane-width")
- lwp := 1 - fwp
- return int(fwp*100), int(lwp*100)
-}
-
-func (a *AppConfig) GetShowAttributes() bool {
- return viper.GetBool("filetree.show-attributes")
-}
diff --git a/runtime/ui/components/dive_application.go b/runtime/ui/components/dive_application.go
index 7c24cc1..d2a7ec1 100644
--- a/runtime/ui/components/dive_application.go
+++ b/runtime/ui/components/dive_application.go
@@ -1,19 +1,15 @@
package components
import (
- "fmt"
-
"github.com/rivo/tview"
- "github.com/sirupsen/logrus"
+ "github.com/wagoodman/dive/internal/log"
"github.com/wagoodman/dive/runtime/ui/components/helpers"
)
type DiveApplication struct {
*tview.Application
-
boundList []BoundView
-
- bindings []helpers.KeyBinding
+ bindings []helpers.KeyBinding
}
func NewDiveApplication(app *tview.Application) *DiveApplication {
@@ -24,10 +20,10 @@ func NewDiveApplication(app *tview.Application) *DiveApplication {
}
func (d *DiveApplication) GetKeyBindings() []helpers.KeyBindingDisplay {
- result := []helpers.KeyBindingDisplay{}
+ var result []helpers.KeyBindingDisplay
for i := 0; i < len(d.bindings); i++ {
binding := d.bindings[i]
- logrus.Debug(fmt.Sprintf("adding keybinding with name %s", binding.Display))
+ log.WithFields("name", binding.Display).Tracef("adding keybinding")
result = append(result, helpers.KeyBindingDisplay{KeyBinding: &binding, Selected: AlwaysFalse, Hide: AlwaysFalse})
}
diff --git a/runtime/ui/components/filetree_primative.go b/runtime/ui/components/filetree_primative.go
index f905b76..c68a1ff 100644
--- a/runtime/ui/components/filetree_primative.go
+++ b/runtime/ui/components/filetree_primative.go
@@ -6,8 +6,8 @@ import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
- "github.com/sirupsen/logrus"
"github.com/wagoodman/dive/dive/filetree"
+ "github.com/wagoodman/dive/internal/log"
"github.com/wagoodman/dive/runtime/ui/components/helpers"
"github.com/wagoodman/dive/runtime/ui/format"
)
@@ -306,23 +306,17 @@ func (t *TreeView) HasFocus() bool {
func (t *TreeView) collapseDir() bool {
node := t.getAbsPositionNode()
if node != nil && node.Data.FileInfo.IsDir {
- logrus.Debugf("collapsing node %s", node.Path())
+ log.WithFields(
+ "path", node.Path(),
+ ).Trace("collapsing node")
node.Data.ViewInfo.Collapsed = !node.Data.ViewInfo.Collapsed
}
- if node != nil {
- logrus.Debugf("unable to collapse node %s", node.Path())
- logrus.Debugf(" IsDir: %t", node.Data.FileInfo.IsDir)
-
- } else {
- logrus.Debugf("unable to collapse nil node")
- }
-
return true
}
func (t *TreeView) CollapseOrExpandAll() bool {
visitor := func(n *filetree.FileNode) error {
- if n.Data.FileInfo.IsDir {
+ if n != nil && n.Data.FileInfo.IsDir {
n.Data.ViewInfo.Collapsed = t.globalCollapseAll
}
return nil
@@ -332,9 +326,9 @@ func (t *TreeView) CollapseOrExpandAll() bool {
return true
}
if err := t.tree.VisitDepthParentFirst(visitor, evaluator); err != nil {
- panic(fmt.Errorf("error callapsing all dir: %w", err))
- // TODO log error here
- //return false
+ err = fmt.Errorf("error collapsing all directories: %w", err)
+ log.Error(err)
+ panic(err)
}
t.globalCollapseAll = !t.globalCollapseAll
@@ -363,7 +357,7 @@ func (t *TreeView) getAbsPositionNode() (node *filetree.FileNode) {
err := t.tree.VisitDepthParentFirst(visitor, evaluator)
if err != nil {
- logrus.Errorf("unable to get node position: %+v", err)
+ log.Errorf("unable to get node position: %+v", err)
}
return node
@@ -386,10 +380,13 @@ func (t *TreeView) keyDown() bool {
t.bufferIndexLowerBound++
}
- logrus.Debugf(" treeIndex: %d", t.treeIndex)
- logrus.Debugf(" bufferIndexLowerBound: %d", t.bufferIndexLowerBound)
- logrus.Debugf(" height: %d", height)
-
+ log.WithFields(
+ "component", "TreeView",
+ "path", t.getAbsPositionNode().Path(),
+ "treeIndex", t.treeIndex,
+ "bufferIndexLowerBound", t.bufferIndexLowerBound,
+ "height", height,
+ ).Tracef("keyDown event")
return true
}
@@ -402,9 +399,12 @@ func (t *TreeView) keyUp() bool {
t.bufferIndexLowerBound--
}
- logrus.Debugf("keyUp end at: %s", t.getAbsPositionNode().Path())
- logrus.Debugf(" treeIndex: %d", t.treeIndex)
- logrus.Debugf(" bufferIndexLowerBound: %d", t.bufferIndexLowerBound)
+ log.WithFields(
+ "component", "TreeView",
+ "path", t.getAbsPositionNode().Path(),
+ "treeIndex", t.treeIndex,
+ "bufferIndexLowerBound", t.bufferIndexLowerBound,
+ ).Tracef("keyUp event")
return true
}
diff --git a/runtime/ui/components/filter_primative.go b/runtime/ui/components/filter_primative.go
index bde235b..b65aeb1 100644
--- a/runtime/ui/components/filter_primative.go
+++ b/runtime/ui/components/filter_primative.go
@@ -49,16 +49,16 @@ func (fv *FilterView) Setup() *FilterView {
return fv
}
-func (ll *FilterView) getBox() *tview.Box {
- return ll.Box
+func (fv *FilterView) getBox() *tview.Box {
+ return fv.Box
}
-func (ll *FilterView) getDraw() drawFn {
- return ll.Draw
+func (fv *FilterView) getDraw() drawFn {
+ return fv.Draw
}
-func (ll *FilterView) getInputWrapper() inputFn {
- return ll.InputHandler
+func (fv *FilterView) getInputWrapper() inputFn {
+ return fv.InputHandler
}
func (fv *FilterView) Empty() bool {
diff --git a/runtime/ui/components/helpers/key_binding.go b/runtime/ui/components/helpers/key_binding.go
index b8186c5..f42a325 100644
--- a/runtime/ui/components/helpers/key_binding.go
+++ b/runtime/ui/components/helpers/key_binding.go
@@ -19,8 +19,8 @@ type KeyBindingDisplay struct {
}
func (kb *KeyBindingDisplay) Name() string {
- s := ""
- m := []string{}
+ var s string
+ var m []string
kMod := kb.Modifiers()
if kMod&tcell.ModShift != 0 {
m = append(m, "Shift")
@@ -39,7 +39,7 @@ func (kb *KeyBindingDisplay) Name() string {
key := kb.Key()
if s, ok = tcell.KeyNames[key]; !ok {
if key == tcell.KeyRune {
- if kb.Rune() == rune(' ') {
+ if kb.Rune() == ' ' {
s = "Space"
} else {
s = string(kb.Rune())
@@ -50,7 +50,7 @@ func (kb *KeyBindingDisplay) Name() string {
}
if len(m) != 0 {
if kMod&tcell.ModCtrl != 0 && strings.HasPrefix(s, "Ctrl-") {
- s = s[5:]
+ s = strings.TrimPrefix(s, "Ctrl-")
}
return fmt.Sprintf("%s%s", strings.Join(m, ""), s)
}
diff --git a/runtime/ui/components/keybinding_primitive.go b/runtime/ui/components/keybinding_primitive.go
index 7733b45..6c6dffd 100644
--- a/runtime/ui/components/keybinding_primitive.go
+++ b/runtime/ui/components/keybinding_primitive.go
@@ -6,7 +6,7 @@ import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
- "github.com/sirupsen/logrus"
+ "github.com/wagoodman/dive/internal/log"
"github.com/wagoodman/dive/runtime/ui/components/helpers"
"github.com/wagoodman/dive/runtime/ui/format"
)
@@ -34,7 +34,7 @@ func (t *KeyMenuView) AddBoundViews(b ...BoundView) *KeyMenuView {
}
func (t *KeyMenuView) RemoveViews(b ...BoundView) *KeyMenuView {
- newBoundList := []BoundView{}
+ var newBoundList []BoundView
boundSet := map[BoundView]interface{}{}
for _, v := range b {
boundSet[v] = true
@@ -51,8 +51,8 @@ func (t *KeyMenuView) RemoveViews(b ...BoundView) *KeyMenuView {
}
func (t *KeyMenuView) GetKeyBindings() []helpers.KeyBindingDisplay {
- logrus.Debug("Getting binding keys from keybinding primitive")
- result := []helpers.KeyBindingDisplay{}
+ log.Trace("getting binding keys from keybinding primitive")
+ var result []helpers.KeyBindingDisplay
for _, view := range t.boundList {
if view.HasFocus() {
result = append(result, view.GetKeyBindings()...)
@@ -66,7 +66,7 @@ func (t *KeyMenuView) Draw(screen tcell.Screen) {
t.Box.Draw(screen)
x, y, width, _ := t.Box.GetInnerRect()
- lines := []string{}
+ var lines []string
keyBindings := t.GetKeyBindings()
for idx, binding := range keyBindings {
if binding.Hide() {
@@ -87,8 +87,8 @@ func (t *KeyMenuView) Draw(screen tcell.Screen) {
prefix = ""
}
keyBindingContent := keyBindingFormatter(prefix + binding.Name() + " ")
- displayContnet := displayFormatter(binding.Display + postfix)
- lines = append(lines, fmt.Sprintf("%s%s", keyBindingContent, displayContnet))
+ displayContent := displayFormatter(binding.Display + postfix)
+ lines = append(lines, fmt.Sprintf("%s%s", keyBindingContent, displayContent))
}
joinedLine := strings.Join(lines, "")
_, w := tview.PrintWithStyle(screen, joinedLine, x, y, width, tview.AlignLeft, tcell.StyleDefault)
diff --git a/runtime/ui/components/layer_details_view.go b/runtime/ui/components/layer_details_view.go
index dec36aa..04692ed 100644
--- a/runtime/ui/components/layer_details_view.go
+++ b/runtime/ui/components/layer_details_view.go
@@ -55,7 +55,7 @@ func (lv *LayerDetailsView) GetKeyBindings() []helpers.KeyBindingDisplay {
}
func layerDetailsText(layer *image.Layer) string {
- lines := []string{}
+ var lines []string
if layer.Names != nil && len(layer.Names) > 0 {
lines = append(lines, boldString("Tags: ")+strings.Join(layer.Names, ", "))
} else {
diff --git a/runtime/ui/components/layers_primative.go b/runtime/ui/components/layers_primative.go
index 9b04066..deb9b5d 100644
--- a/runtime/ui/components/layers_primative.go
+++ b/