MCPcopy
hub / github.com/wtfutil/wtf / NewCommonSettingsFromModule

Function NewCommonSettingsFromModule

cfg/common_settings.go:55–119  ·  view source on GitHub ↗

NewCommonSettingsFromModule returns a common settings configuration tailed to the given module

(name, defaultTitle string, defaultFocusable bool, moduleConfig *config.Config, globalConfig *config.Config)

Source from the content-addressed store, hash-verified

53
54// NewCommonSettingsFromModule returns a common settings configuration tailed to the given module
55func NewCommonSettingsFromModule(name, defaultTitle string, defaultFocusable bool, moduleConfig *config.Config, globalConfig *config.Config) *Common {
56 baseColors := NewDefaultColorTheme()
57
58 colorsConfig, err := globalConfig.Get("wtf.colors")
59 if err != nil && strings.Contains(err.Error(), "Nonexistent map") {
60 // Create a default colors config to fill in for the missing one
61 // This comes into play when the configuration file does not contain a `colors:` key, i.e:
62 //
63 // wtf:
64 // # colors: <- missing
65 // refreshInterval: 1
66 // openFileUtil: "open"
67 //
68 colorsConfig, _ = NewDefaultColorConfig()
69 }
70
71 // And finally create a third instance to be the final default fallback in case there are empty or nil values in
72 // the colors extracted from the config file (aka colorsConfig)
73 defaultColorTheme := NewDefaultColorTheme()
74
75 baseColors.Focusable = moduleConfig.UString("colors.border.focusable", colorsConfig.UString("border.focusable", defaultColorTheme.Focusable))
76 baseColors.Focused = moduleConfig.UString("colors.border.focused", colorsConfig.UString("border.focused", defaultColorTheme.Focused))
77 baseColors.Unfocusable = moduleConfig.UString("colors.border.normal", colorsConfig.UString("border.normal", defaultColorTheme.Unfocusable))
78
79 baseColors.Checked = moduleConfig.UString("colors.checked", colorsConfig.UString("checked", defaultColorTheme.Checked))
80
81 baseColors.EvenForeground = moduleConfig.UString("colors.rows.even", colorsConfig.UString("rows.even", defaultColorTheme.EvenForeground))
82 baseColors.OddForeground = moduleConfig.UString("colors.rows.odd", colorsConfig.UString("rows.odd", defaultColorTheme.OddForeground))
83
84 baseColors.Label = moduleConfig.UString("colors.label", colorsConfig.UString("label", defaultColorTheme.Label))
85 baseColors.Subheading = moduleConfig.UString("colors.subheading", colorsConfig.UString("subheading", defaultColorTheme.Subheading))
86 baseColors.Text = moduleConfig.UString("colors.text", colorsConfig.UString("text", defaultColorTheme.Text))
87 baseColors.Title = moduleConfig.UString("colors.title", colorsConfig.UString("title", defaultColorTheme.Title))
88
89 baseColors.Background = moduleConfig.UString("colors.background", colorsConfig.UString("background", defaultColorTheme.Background))
90
91 common := Common{
92 Colors: baseColors,
93
94 Module: Module{
95 Name: name,
96 Type: moduleConfig.UString("type", name),
97 },
98
99 PositionSettings: NewPositionSettingsFromYAML(moduleConfig),
100
101 Bordered: moduleConfig.UBool("border", true),
102 Config: moduleConfig,
103 Enabled: moduleConfig.UBool("enabled", false),
104 Focusable: moduleConfig.UBool("focusable", defaultFocusable),
105 LanguageTag: globalConfig.UString("wtf.language", defaultLanguageTag),
106 RefreshInterval: ParseTimeString(moduleConfig, "refreshInterval", "300s"),
107 Title: moduleConfig.UString("title", defaultTitle),
108
109 focusChar: moduleConfig.UInt("focusChar", -1),
110 }
111
112 sigilsPath := "wtf.sigils"

Callers 15

NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92
NewSettingsFromYAMLFunction · 0.92

Calls 6

NewDefaultColorThemeFunction · 0.85
NewDefaultColorConfigFunction · 0.85
ParseTimeStringFunction · 0.85
GetMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected