Skip to content
Snippets Groups Projects
Unverified Commit 12bc71ba authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Generate from configs.

parent dc03fb66
Branches
No related tags found
No related merge requests found
......@@ -28,20 +28,37 @@ func handleCommands() {
// Run is essentially the main program.
func Run(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
cfg, err := config.ReadConfig(viper.GetString("config"))
if err != nil {
// TODO Make a better default
cfg, err = config.ReadConfigStr(`---
modules:
- module: text
name: post
params:
text: "post"
color: "#11ff11"
on-click: xdg-open https://mastodon.ie/
- module: date
params:
format: 06-05-04 15:02
on-click: xdg-open https://calendar.google.com/
`)
cobra.CheckErr(err)
}
go handleCommands()
fmt.Printf(`{ "version": 1, "stop_signal": %d, "cont_signal": %d, "click_events": true }`+"\n",
unix.SignalNum("SIGSTOP"), unix.SignalNum("SIGCONT"))
fmt.Println("[")
separator := "["
for {
line := make([]string, 0, 5)
for _, module := range cfg.Modules {
line = append(line, module.Render())
}
fmt.Printf(strings.Join(line, ","))
fmt.Printf("%s\n[%s]", separator, strings.Join(line, ","))
separator = ","
time.Sleep(5 * time.Second)
}
}
......@@ -2,6 +2,7 @@ package config
import (
"os"
"strings"
"gitlab.ie.suberic.net/kevin/i3going-on/modules"
"gopkg.in/yaml.v3"
......@@ -12,6 +13,14 @@ type Config struct {
Modules []modules.Module `yaml:"modules"`
}
// ReadConfigStr reads in the config.
func ReadConfigStr(configStr string) (*Config, error) {
configParser := yaml.NewDecoder(strings.NewReader(configStr))
cfg := &Config{}
err := configParser.Decode(&cfg)
return cfg, err
}
// ReadConfig reads in the config.
func ReadConfig(configFile string) (*Config, error) {
config, err := os.Open(configFile)
......
package modules
import (
"fmt"
)
// TextMod module parameters for the text module.
type TextMod struct {
name string
......@@ -26,18 +30,12 @@ func (t *TextMod) Name() string {
}
// OnClick returns the on-click setting for the module.
func (t *TextMod) Render() string {
{
"name": "color",
"full_text": "RED",
"color": "#11ff11"
func (t *TextMod) OnClick() string {
return t.onclick
}
// Render renders the module.
func (d *DateMod) Render() string {
now := time.Now().Format(d.Format)
return fmt.Sprintf("{\"full_text\": \"%s\"}", )
func (t *TextMod) Render() string {
// TODO: Make color and name optional.
return fmt.Sprintf(`{"name": "%s", "full_text": "%s", "color": "%s"}`, t.name, t.Text, t.Color)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment