diff --git a/bar/run.go b/bar/run.go index fe55e259c67d021f3a377f58ce4b6cd8de265816..84a7f969a6743c840bdee95f83fc1c6dee5b0e37 100644 --- a/bar/run.go +++ b/bar/run.go @@ -33,6 +33,7 @@ func Run(cmd *cobra.Command, args []string) { if err != nil { // TODO Make a better default cfg, err = config.ReadConfigStr(`--- +refresh: 5 modules: - module: text name: post @@ -47,6 +48,9 @@ modules: `) cobra.CheckErr(err) } + if cfg.Refresh < 1 { + cfg.Refresh = 5 + } go handleCommands() fmt.Printf(`{ "version": 1, "stop_signal": %d, "cont_signal": %d, "click_events": true }`+"\n", @@ -59,6 +63,6 @@ modules: } fmt.Printf("%s\n[%s]", separator, strings.Join(line, ",")) separator = "," - time.Sleep(5 * time.Second) + time.Sleep(time.Duration(cfg.Refresh) * time.Second) } } diff --git a/config/config.go b/config/config.go index 8401ecbaf24ed482f30002b7c7555337c0e87c17..1ba94b7912e1172bfc6e6047dc9f0d461278edc2 100644 --- a/config/config.go +++ b/config/config.go @@ -10,6 +10,7 @@ import ( // Config is the structure for the config file. type Config struct { + Refresh int `yaml:"refresh"` Modules []modules.Module `yaml:"modules"` } diff --git a/doc/config.sample.yaml b/doc/config.sample.yaml index 9d29fad016b3a357c302f9281f06ed7147fec950..b0a4e4a04a674c623c2a93384cfdaa03426325cd 100644 --- a/doc/config.sample.yaml +++ b/doc/config.sample.yaml @@ -1,4 +1,5 @@ --- +refresh: 5 modules: - module: text name: post @@ -8,5 +9,6 @@ modules: on-click: xdg-open https://mastodon.ie/ - module: date params: + blink-char: ":" format: 06-01-02 15:04 on-click: xdg-open https://calendar.google.com/ diff --git a/modules/date.go b/modules/date.go index 00352631544e177d67d1c9e1b6b9204be9db1449..400d629f7ad1815e65ad6ea4c73c185b69c2f802 100644 --- a/modules/date.go +++ b/modules/date.go @@ -2,14 +2,17 @@ package modules import ( "fmt" + "strings" "time" ) // DateMod module parameters for the text module. type DateMod struct { - name string - onclick string - Format string `yaml:"format"` + name string + onclick string + blink bool + Format string `yaml:"format"` + BlinkChar string `yaml:"blink-char"` } // NewDate creates a DateMod instance. @@ -38,5 +41,11 @@ func (d *DateMod) OnClick() string { func (d *DateMod) Render() string { now := time.Now().Format(d.Format) + if d.BlinkChar != "" { + if d.blink { + now = strings.ReplaceAll(now, d.BlinkChar, " ") + } + d.blink = !d.blink + } return fmt.Sprintf("{\"full_text\": \"%s\"}", now) }