mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add default label color to docker module
This commit is contained in:
parent
0cd9605a5e
commit
32884e5de4
24
modules/docker/settings.go
Normal file
24
modules/docker/settings.go
Normal file
@ -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
|
||||||
|
}
|
@ -1,33 +1,12 @@
|
|||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
// "github.com/docker/docker/client"
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/olebedev/config"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/cfg"
|
|
||||||
"github.com/wtfutil/wtf/view"
|
"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 {
|
type Widget struct {
|
||||||
view.TextWidget
|
view.TextWidget
|
||||||
cli *client.Client
|
cli *client.Client
|
||||||
@ -42,10 +21,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetScrollable(true)
|
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()
|
cli, err := client.NewEnvClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -59,17 +34,20 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.refreshDisplayBuffer()
|
widget.refreshDisplayBuffer()
|
||||||
widget.Redraw(widget.display)
|
widget.Redraw(widget.display)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() (string, string, bool) {
|
func (widget *Widget) display() (string, string, bool) {
|
||||||
return widget.CommonSettings().Title, widget.displayBuffer, true
|
return widget.CommonSettings().Title, widget.displayBuffer, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) refreshDisplayBuffer() {
|
func (widget *Widget) refreshDisplayBuffer() {
|
||||||
|
|
||||||
if widget.cli == nil {
|
if widget.cli == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -83,5 +61,4 @@ func (widget *Widget) refreshDisplayBuffer() {
|
|||||||
|
|
||||||
widget.displayBuffer += "[" + widget.settings.labelColor + "::bul]containers\n"
|
widget.displayBuffer += "[" + widget.settings.labelColor + "::bul]containers\n"
|
||||||
widget.displayBuffer += widget.getContainerStates()
|
widget.displayBuffer += widget.getContainerStates()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user