diff options
author | dwillist <dthornton@vmware.com> | 2021-01-19 15:12:14 -0500 |
---|---|---|
committer | dwillist <dthornton@vmware.com> | 2021-01-19 15:12:14 -0500 |
commit | a11e9c1cf23c379dcec0bb45721ec1bca4e2c717 (patch) | |
tree | 0e87ceef3614c6e3e401d3830c85e7e6a1970c09 | |
parent | abee6a60f1332195f4a192d5b7d515f4bd5a50e2 (diff) |
update colorization to inherit settings from terminal
Signed-off-by: dwillist <dthornton@vmware.com>
-rw-r--r-- | runtime/ui/app.go | 19 | ||||
-rw-r--r-- | runtime/ui/format/format.go | 18 |
2 files changed, 25 insertions, 12 deletions
diff --git a/runtime/ui/app.go b/runtime/ui/app.go index 4b089b8..8090cf7 100644 --- a/runtime/ui/app.go +++ b/runtime/ui/app.go @@ -6,11 +6,12 @@ import ( "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" + "github.com/wagoodman/dive/runtime/ui/format" "github.com/wagoodman/dive/runtime/ui/viewmodels" - "go.uber.org/zap" ) // type global @@ -28,17 +29,16 @@ type UI struct { func newApp(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 := components.NewKeyConfig() diveApplication := components.NewDiveApplication(app) - // ensure the background color is inherited from the terminal emulator - //tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault - //tview.Styles.PrimaryTextColor = tcell.ColorDefault - //initialize viewmodels filterViewModel := viewmodels.NewFilterViewModel(nil) - // TODO extract the CNB specific logic here for now... layerModel := viewmodels.NewLayersViewModel(analysis.Layers) regularLayerDetailsView := components.NewLayerDetailsView(layerModel).Setup() layerDetailsBox := components.NewWrapper("Layer Details", "", regularLayerDetailsView).Setup() @@ -47,7 +47,6 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr //layerViewModel := viewmodels.NewLayersViewModel(analysis.Layers) treeViewModel, err := viewmodels.NewTreeViewModel(cache, layerModel, filterViewModel) if err != nil { - // TODO: replace panic with a reasonable exit strategy panic(err) } @@ -69,8 +68,6 @@ func newApp(app *tview.Application, analysis *image.AnalysisResult, cache filetr keyMenuView := components.NewKeyMenuView() - // Implementation notes: should we factor out this setup?? - // Probably yes, but difficult to make this both easy to setup & mutable leftVisibleGrid := components.NewVisibleFlex() leftVisibleGrid.SetDirection(tview.FlexRow) rightVisibleGrid := components.NewVisibleFlex() @@ -165,9 +162,9 @@ func Run(analysis *image.AnalysisResult, treeStack filetree.Comparer) error { } if err = uiSingleton.app.Run(); err != nil { - zap.S().Info("app error: ", err.Error()) + logrus.Error("app error: ", err.Error()) return err } - zap.S().Info("app run loop exited") + logrus.Info("app run loop exited") return nil } diff --git a/runtime/ui/format/format.go b/runtime/ui/format/format.go index 0451598..9b79461 100644 --- a/runtime/ui/format/format.go +++ b/runtime/ui/format/format.go @@ -39,6 +39,22 @@ var ( //selectStr = " " ) +func SyncWithTermColors() { + tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault + tview.Styles.PrimaryTextColor = tcell.ColorDefault + tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault // Main background color for primitives. + tview.Styles.ContrastBackgroundColor = tcell.ColorDefault // Background color for contrasting elements. + tview.Styles.MoreContrastBackgroundColor = tcell.ColorDefault // Background color for even more contrasting elements. + tview.Styles.BorderColor = tcell.ColorDefault // Box borders. + tview.Styles.TitleColor = tcell.ColorDefault // Box titles. + tview.Styles.GraphicsColor = tcell.ColorDefault // Graphics. + tview.Styles.PrimaryTextColor = tcell.ColorDefault // Primary text. + tview.Styles.SecondaryTextColor = tcell.ColorDefault // Secondary text (e.g. labels). + tview.Styles.TertiaryTextColor = tcell.ColorDefault // Tertiary text (e.g. subtitles, notes). + tview.Styles.InverseTextColor = tcell.ColorDefault // Text on primary-colored backgrounds. + tview.Styles.ContrastSecondaryTextColor = tcell.ColorDefault // Secondary text on ContrastBackgroundColor-colored backgrounds. +} + type Formatter func(s string) string func GenerateFormatter(fg, bg, flags string) Formatter { @@ -57,7 +73,7 @@ var ( // Bolds text Header Formatter = GenerateFormatter("", "", "b") Normal Formatter = GenerateFormatter("", "", "") - None Formatter = func(s string) string {return s} + None Formatter = func(s string) string { return s } Selected Formatter = GenerateFormatter("", "", "rb") StatusSelected Formatter = GenerateFormatter(colorTranslate(tcell.ColorWhite), colorTranslate(tcell.ColorDarkMagenta), "") StatusNormal Formatter = GenerateFormatter("", "", "r") |