From 3ff43f9205c7a213b1602aaf45fcdfee528533eb Mon Sep 17 00:00:00 2001 From: Kevin Lyda <kevin@lyda.ie> Date: Wed, 17 May 2023 08:53:32 +0100 Subject: [PATCH] Initial stub module for interfaces. --- modules/interfaces.go | 55 +++++++++++++++++++++++++++++++++++++++++++ modules/modules.go | 2 ++ modules/text.go | 6 +++-- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 modules/interfaces.go diff --git a/modules/interfaces.go b/modules/interfaces.go new file mode 100644 index 0000000..ef4b16b --- /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 93a8d22..1001504 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 2c7e356..fc4856c 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) } -- GitLab