github.com/wtfutil/wtf@v0.43.0/modules/gcal/settings.go (about)

     1  package gcal
     2  
     3  import (
     4  	"github.com/olebedev/config"
     5  	"github.com/wtfutil/wtf/cfg"
     6  )
     7  
     8  const (
     9  	defaultFocusable = true
    10  	defaultTitle     = "Calendar"
    11  )
    12  
    13  type colors struct {
    14  	day         string
    15  	description string `help:"The default color for calendar event descriptions." values:"Any X11 color name." optional:"true"`
    16  	eventTime   string `help:"The default color for calendar event times." values:"Any X11 color name." optional:"true"`
    17  	past        string `help:"The color for calendar events that have passed." values:"Any X11 color name." optional:"true"`
    18  	title       string `help:"The default colour for calendar event titles." values:"Any X11 color name." optional:"true"`
    19  
    20  	highlights []interface{} `help:"A list of arrays that define a regular expression pattern and a color. If a calendar event title matches a regular expression, the title will be drawn in that colour. Over-rides the default title colour." values:"An array of a valid regular expression, any X11 color name." optional:"true"`
    21  }
    22  
    23  // Settings defines the configuration options for this module
    24  type Settings struct {
    25  	colors
    26  	*cfg.Common
    27  
    28  	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"`
    29  	currentIcon           string `help:"The icon displayed beside the current calendar event." values:"Any displayable unicode character." optional:"true"`
    30  	displayResponseStatus bool   `help:"Whether or not to display your response status to the calendar event." values:"true or false" optional:"true"`
    31  	email                 string `help:"The email address associated with your Google account. Necessary for determining 'responseStatus'." values:"A valid email address string."`
    32  	eventCount            int    `help:"The number of calendar events to display." values:"A positive integer, 0..n." optional:"true"`
    33  	hourFormat            string `help:"The format of the clock." values:"12 or 24"`
    34  	multiCalendar         bool   `help:"Whether or not to display your primary calendar or all calendars you have access to." values:"true or false" optional:"true"`
    35  	secretFile            string `help:"Your Google client secret JSON file." values:"A string representing a file path to the JSON secret file."`
    36  	showAllDay            bool   `help:"Whether or not to display all-day events" values:"true or false" optional:"true" default:"true"`
    37  	showDeclined          bool   `help:"Whether or not to display events you’ve declined to attend." values:"true or false" optional:"true"`
    38  	showEndTime           bool   `help:"Display the end time of events, in addition to start time." values:"true or false" optional:"true" default:"false"`
    39  	withLocation          bool   `help:"Whether or not to show the location of the appointment." values:"true or false"`
    40  	timezone              string `help:"The time zone used to display calendar event times." values:"A valid TZ database time zone string" optional:"true"`
    41  	calendarReadLevel     string `help:"The calender read level specifies level you want to read events. Default: writer " values:"reader, writer" optional:"true"`
    42  }
    43  
    44  // NewSettingsFromYAML creates and returns an instance of Settings with configuration options populated
    45  func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
    46  	settings := Settings{
    47  		Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
    48  
    49  		conflictIcon:          ymlConfig.UString("conflictIcon", "🚨"),
    50  		currentIcon:           ymlConfig.UString("currentIcon", "🔸"),
    51  		displayResponseStatus: ymlConfig.UBool("displayResponseStatus", true),
    52  		email:                 ymlConfig.UString("email", ""),
    53  		eventCount:            ymlConfig.UInt("eventCount", 10),
    54  		hourFormat:            ymlConfig.UString("hourFormat", "24"),
    55  		multiCalendar:         ymlConfig.UBool("multiCalendar", false),
    56  		secretFile:            ymlConfig.UString("secretFile", ""),
    57  		showAllDay:            ymlConfig.UBool("showAllDay", true),
    58  		showEndTime:           ymlConfig.UBool("showEndTime", false),
    59  		showDeclined:          ymlConfig.UBool("showDeclined", false),
    60  		withLocation:          ymlConfig.UBool("withLocation", true),
    61  		timezone:              ymlConfig.UString("timezone", ""),
    62  		calendarReadLevel:     ymlConfig.UString("calendarReadLevel", "writer"),
    63  	}
    64  
    65  	settings.colors.day = ymlConfig.UString("colors.day", settings.Colors.Subheading)
    66  	settings.colors.description = ymlConfig.UString("colors.description", "white")
    67  
    68  	// settings.colors.eventTime is a new feature introduced via issue #638. Prior to this, the color of the event
    69  	// time was (unintentionally) customized via settings.colors.description. To maintain backwards compatibility
    70  	// for users who might be already using this to set the color of the event time, we try to determine the default
    71  	// from settings.colors.description. If it is not set, then the default value of "white" is used.  Finally, if a
    72  	// user sets a value for colors.eventTime, it overrides the defaults.
    73  	//
    74  	// PS: We should have a deprecation plan for supporting this backwards compatibility feature.
    75  	settings.colors.eventTime = ymlConfig.UString("colors.eventTime", settings.colors.description)
    76  
    77  	settings.colors.highlights = ymlConfig.UList("colors.highlights")
    78  	settings.colors.past = ymlConfig.UString("colors.past", "gray")
    79  	settings.colors.title = ymlConfig.UString("colors.title", "white")
    80  
    81  	settings.SetDocumentationPath("google/gcal")
    82  
    83  	return &settings
    84  }