diff --git a/modules/docker/settings.go b/modules/docker/settings.go new file mode 100644 index 00000000..a0144a02 --- /dev/null +++ b/modules/docker/settings.go @@ -0,0 +1,24 @@ +package docker + +import ( + "github.com/olebedev/config" + "github.com/wtfutil/wtf/cfg" +) + +const defaultTitle = "docker" + +// Settings defines the configuration options for this module +type Settings struct { + common *cfg.Common + labelColor string +} + +// NewSettingsFromYAML creates and returns an instance of Settings with configuration options populated +func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { + settings := Settings{ + common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), + labelColor: ymlConfig.UString("labelColor", "white"), + } + + return &settings +} diff --git a/modules/docker/widget.go b/modules/docker/widget.go index a4efbbe3..a135285f 100644 --- a/modules/docker/widget.go +++ b/modules/docker/widget.go @@ -1,33 +1,12 @@ package docker import ( - - // "github.com/docker/docker/client" "github.com/docker/docker/client" - "github.com/olebedev/config" "github.com/pkg/errors" "github.com/rivo/tview" - "github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/view" ) -const defaultTitle = "docker" - -type Settings struct { - common *cfg.Common - labelColor string -} - -func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { - - settings := Settings{ - common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), - labelColor: ymlConfig.UString("labelColor", "labelColor"), - } - - return &settings -} - type Widget struct { view.TextWidget cli *client.Client @@ -42,10 +21,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * } widget.View.SetScrollable(true) - // widget.View.SetRegions(true) - - // os.Setenv("DOCKER_HOST", "unix:///var/run/docker.sock") - // os.Setenv("DOCKER_API_VERSION", "1.23") cli, err := client.NewEnvClient() if err != nil { @@ -59,17 +34,20 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * return &widget } +/* -------------------- Exported Functions -------------------- */ + func (widget *Widget) Refresh() { widget.refreshDisplayBuffer() widget.Redraw(widget.display) } +/* -------------------- Unexported Functions -------------------- */ + func (widget *Widget) display() (string, string, bool) { return widget.CommonSettings().Title, widget.displayBuffer, true } func (widget *Widget) refreshDisplayBuffer() { - if widget.cli == nil { return } @@ -83,5 +61,4 @@ func (widget *Widget) refreshDisplayBuffer() { widget.displayBuffer += "[" + widget.settings.labelColor + "::bul]containers\n" widget.displayBuffer += widget.getContainerStates() - }