NewCommonSettingsFromModule returns a common settings configuration tailed to the given module
(name, defaultTitle string, defaultFocusable bool, moduleConfig *config.Config, globalConfig *config.Config)
| 53 | |
| 54 | // NewCommonSettingsFromModule returns a common settings configuration tailed to the given module |
| 55 | func 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" |
no test coverage detected