github.com/wtfutil/wtf@v0.43.0/modules/progress/settings.go (about) 1 package progress 2 3 import ( 4 "github.com/olebedev/config" 5 "github.com/wtfutil/wtf/cfg" 6 ) 7 8 const ( 9 defaultFocusable = false 10 defaultTitle = "Progress" 11 ) 12 13 type colors struct { 14 gradientA string `help:"Start color for linear gradient." values:"any X11 or hex color" optional:"true" default:"#56ab2f"` 15 gradientB string `help:"End color for linear gradient." values:"any X11 or hex color" optional:"true" default:"#a8e063"` 16 solid string `help:"Use a solid color instead of linear color gradient ." values:"any X11 or hex color" optional:"true"` 17 } 18 19 // Settings defines the configuration properties for this module 20 type Settings struct { 21 colors 22 common *cfg.Common 23 24 showPercentage string `help:"Where to display the percentage" values:"left, right, above, below, titleLeft, titleRight, or none" optional:"true" default:"right"` 25 padding int `help:"Amount of spaces to add as left/right padding." values:"A positive integer, 0..n" optional:"true" default:"1"` 26 27 minimum float64 `help:"Minimum progress value." values:"A positive decimal value, 0.0..n.n" optional:"true" default:"0"` 28 maximum float64 `help:"Maximum progress value." values:"A positive decimal value, 0.0..n.n" optional:"true" default:"0"` 29 current float64 `help:"Current progress value. If maximum value is 0, current value is assumed to be a percentage between 0-100." values:"A positive decimal value, 0.0..n.n" optional:"true" default:"0"` 30 31 minimumCmd string `help:"Execute shell command to determine minimum progress value. Return value must be numeric." values:"Any shell command" optional:"true"` 32 maximumCmd string `help:"Execute shell command to determine maximum progress value. Return value must be numeric." values:"Any shell command" optional:"true"` 33 currentCmd string `help:"Execute shell command to determine current progress value. Return value must be numeric." values:"Any shell command" optional:"true"` 34 } 35 36 // NewSettingsFromYAML creates a new settings instance from a YAML config block 37 func NewSettingsFromYAML(name string, ymlConfig, globalConfig *config.Config) *Settings { 38 settings := Settings{ 39 common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), 40 41 showPercentage: ymlConfig.UString("showPercentage", "right"), 42 padding: ymlConfig.UInt("padding", 1), 43 minimum: ymlConfig.UFloat64("minimum", 0), 44 maximum: ymlConfig.UFloat64("maximum", 0), 45 current: ymlConfig.UFloat64("current", 0), 46 minimumCmd: ymlConfig.UString("minimumCmd", ""), 47 maximumCmd: ymlConfig.UString("maximumCmd", ""), 48 currentCmd: ymlConfig.UString("currentCmd", ""), 49 } 50 51 settings.colors.gradientA = ymlConfig.UString("colors.gradientA", "#56ab2f") 52 settings.colors.gradientB = ymlConfig.UString("colors.gradientB", "#a8e063") 53 settings.colors.solid = ymlConfig.UString("colors.solid", "") 54 55 return &settings 56 }