1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Simplify the inclusion of the Common config settings into each module

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer
2020-11-26 19:53:21 -08:00
parent f9a06540f1
commit d6a0797bf2
161 changed files with 378 additions and 330 deletions

View File

@@ -14,7 +14,7 @@ func (widget *Widget) display() {
}
func (widget *Widget) content() (string, string, bool) {
title := widget.settings.common.Title
title := widget.settings.Title
calEvents := widget.calEvents
if widget.err != nil {

View File

@@ -21,25 +21,25 @@ func Test_display_content(t *testing.T) {
}{
{
name: "Event content without any events",
settings: &Settings{common: &cfg.Common{}},
settings: &Settings{Common: &cfg.Common{}},
events: nil,
descriptionWanted: "No calendar events",
},
{
name: "Event content with a single event, without end times displayed",
settings: &Settings{common: &cfg.Common{}, showEndTime: false},
settings: &Settings{Common: &cfg.Common{}, showEndTime: false},
events: []*CalEvent{NewCalEvent(event)},
descriptionWanted: "[]Saturday, Apr 19\n []01:00 []Foo[white]\n \n",
},
{
name: "Event content with a single event without showEndTime explictily set in settings",
settings: &Settings{common: &cfg.Common{}},
settings: &Settings{Common: &cfg.Common{}},
events: []*CalEvent{NewCalEvent(event)},
descriptionWanted: "[]Saturday, Apr 19\n []01:00 []Foo[white]\n \n",
},
{
name: "Event content with a single event with end times displayed",
settings: &Settings{common: &cfg.Common{}, showEndTime: true},
settings: &Settings{Common: &cfg.Common{}, showEndTime: true},
events: []*CalEvent{NewCalEvent(event)},
descriptionWanted: "[]Saturday, Apr 19\n []01:00-02:00 []Foo[white]\n \n",
},

View File

@@ -23,7 +23,7 @@ type colors struct {
// Settings defines the configuration options for this module
type Settings struct {
colors
common *cfg.Common
*cfg.Common
conflictIcon string `help:"The icon displayed beside calendar events that have conflicting times (they intersect or overlap in some way)." values:"Any displayable unicode character." optional:"true"`
currentIcon string `help:"The icon displayed beside the current calendar event." values:"Any displayable unicode character." optional:"true"`
@@ -44,7 +44,7 @@ type Settings struct {
// 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, defaultFocusable, ymlConfig, globalConfig),
Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
conflictIcon: ymlConfig.UString("conflictIcon", "🚨"),
currentIcon: ymlConfig.UString("currentIcon", "🔸"),
@@ -62,8 +62,9 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
calendarReadLevel: ymlConfig.UString("calendarReadLevel", "writer"),
}
settings.colors.day = ymlConfig.UString("colors.day", settings.common.Colors.Subheading)
settings.colors.day = ymlConfig.UString("colors.day", settings.Colors.Subheading)
settings.colors.description = ymlConfig.UString("colors.description", "white")
// settings.colors.eventTime is a new feature introduced via issue #638. Prior to this, the color of the event
// time was (unintentionally) customized via settings.colors.description. To maintain backwards compatibility
// for users who might be already using this to set the color of the event time, we try to determine the default
@@ -72,6 +73,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
//
// PS: We should have a deprecation plan for supporting this backwards compatibility feature.
settings.colors.eventTime = ymlConfig.UString("colors.eventTime", settings.colors.description)
settings.colors.highlights = ymlConfig.UList("colors.highlights")
settings.colors.past = ymlConfig.UString("colors.past", "gray")
settings.colors.title = ymlConfig.UString("colors.title", "white")

View File

@@ -16,7 +16,7 @@ type Widget struct {
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
TextWidget: view.NewTextWidget(app, nil, settings.common),
TextWidget: view.NewTextWidget(app, nil, settings.Common),
app: app,
settings: settings,