diff --git a/modules/interfaces.go b/modules/interfaces.go new file mode 100644 index 0000000000000000000000000000000000000000..ef4b16b15ef3944ff13b4d5abdd6b0337787dbcc --- /dev/null +++ b/modules/interfaces.go @@ -0,0 +1,55 @@ +// Package modules implements all the modules. +// Copyright (C) 2022 Kevin Lyda <kevin@lyda.ie> +package modules + +/* + +To implement this, these are some good modules to look at: + +https://pkg.go.dev/github.com/mdlayher/wifi +https://pkg.go.dev/net#Interface + +*/ + +import ( + "fmt" +) + +// InterfacesMod module parameters for the text module. +type InterfacesMod struct { + name string + onclick string + Format string `yaml:"format"` +} + +// NewInterfaces creates a InterfacesMod instance. +func NewInterfaces(m *Module) *InterfacesMod { + t := &InterfacesMod{ + name: m.Name, + onclick: m.OnClick, + } + return t +} + +// SetDefaults sets defaults. +func (t *InterfacesMod) SetDefaults() { + if t.Format == "" { + t.Format = "Hello world!" + } +} + +// Name returns the name setting for the module. +func (t *InterfacesMod) Name() string { + return t.name +} + +// OnClick returns the on-click setting for the module. +func (t *InterfacesMod) OnClick() string { + return t.onclick +} + +// Render renders the module. +func (t *InterfacesMod) Render() string { + // TODO: Make color and name optional. + return fmt.Sprintf(`{"name": "%s", "full_text": "Not Implemented Yet", "color": "#ff0000"}`, t.name) +} diff --git a/modules/modules.go b/modules/modules.go index 93a8d228654e7b881e4236837b4fc5d3833f143c..1001504196680f8173810a8f2659907cd42a9a9b 100644 --- a/modules/modules.go +++ b/modules/modules.go @@ -54,6 +54,8 @@ func (m *Module) UnmarshalYAML(node *yaml.Node) error { m.Params = NewText(m) case "battery": m.Params = NewBattery(m) + case "interfaces": + m.Params = NewInterfaces(m) default: return fmt.Errorf("module '%s' is unknown", params.Module) } diff --git a/modules/text.go b/modules/text.go index 2c7e356d4f38caadecc85417714d461c445bfda6..fc4856c36ad2b41424f1c203576508d107d68bee 100644 --- a/modules/text.go +++ b/modules/text.go @@ -42,6 +42,8 @@ func (t *TextMod) OnClick() string { // Render renders the module. 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) + if t.Color != "" { + return fmt.Sprintf(`{"name": "%s", "full_text": "%s", "color": "%s"}`, t.name, t.Text, t.Color) + } + return fmt.Sprintf(`{"name": "%s", "full_text": "%s"}`, t.name, t.Text) }