From bf11addd6d079bd42236d6506479421a1cfb65de Mon Sep 17 00:00:00 2001 From: Kevin Lyda <kevin@lyda.ie> Date: Thu, 1 Dec 2022 14:44:12 +0000 Subject: [PATCH] Add blinking. --- bar/run.go | 6 +++++- config/config.go | 1 + doc/config.sample.yaml | 2 ++ modules/date.go | 15 ++++++++++++--- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/bar/run.go b/bar/run.go index fe55e25..84a7f96 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 8401ecb..1ba94b7 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 9d29fad..b0a4e4a 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 0035263..400d629 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) } -- GitLab