github.com/wtfutil/wtf@v0.43.0/modules/todo/settings.go (about) 1 package todo 2 3 import ( 4 "github.com/olebedev/config" 5 "github.com/wtfutil/wtf/cfg" 6 ) 7 8 const ( 9 defaultFocusable = true 10 defaultTitle = "Todo" 11 ) 12 13 // Settings defines the configuration properties for this module 14 type Settings struct { 15 *cfg.Common 16 17 filePath string 18 checked string 19 unchecked string 20 newPos string 21 checkedPos string 22 parseDates bool 23 dateColor string 24 switchToInDaysIn int 25 undatedAsDays int 26 hideYearIfCurrent bool 27 dateFormat string 28 parseTags bool 29 tagColor string 30 tagsAtEnd bool 31 hideTags []interface{} 32 hiddenNumInTitle bool 33 } 34 35 // NewSettingsFromYAML creates a new settings instance from a YAML config block 36 func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { 37 common := cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig) 38 39 settings := Settings{ 40 Common: common, 41 42 filePath: ymlConfig.UString("filename"), 43 checked: ymlConfig.UString("checkedIcon", common.Checkbox.Checked), 44 unchecked: ymlConfig.UString("uncheckedIcon", common.Checkbox.Unchecked), 45 newPos: ymlConfig.UString("newPos", "first"), 46 checkedPos: ymlConfig.UString("checkedPos", "last"), 47 parseDates: ymlConfig.UBool("dates.enabled", true), 48 dateColor: ymlConfig.UString("colors.date", "chartreuse"), 49 switchToInDaysIn: ymlConfig.UInt("dates.switchToInDaysIn", 7), 50 undatedAsDays: ymlConfig.UInt("dates.undatedAsDays", 7), 51 hideYearIfCurrent: ymlConfig.UBool("dates.hideYearIfCurrent", true), 52 dateFormat: ymlConfig.UString("dates.format", "yyyy-mm-dd"), 53 parseTags: ymlConfig.UBool("tags.enabled", true), 54 tagColor: ymlConfig.UString("colors.tags", "khaki"), 55 tagsAtEnd: ymlConfig.UString("tags.pos", "end") == "end", 56 hideTags: ymlConfig.UList("tags.hide"), 57 hiddenNumInTitle: ymlConfig.UBool("tags.hiddenInTitle", true), 58 } 59 60 switch settings.newPos { 61 case "first", "last": 62 default: 63 settings.newPos = "last" 64 } 65 switch settings.checkedPos { 66 case "first", "last", "none": 67 default: 68 settings.checkedPos = "last" 69 } 70 switch settings.dateFormat { 71 case "yyyy-mm-dd", "yy-mm-dd", "dd-mm-yyyy", "dd-mm-yy", "dd M yy", "dd M yyyy": 72 default: 73 settings.dateFormat = "yyyy-mm-dd" 74 } 75 76 return &settings 77 }