Text overlay support

This commit is contained in:
2026-04-18 11:38:16 -06:00
parent 44dc22d8ee
commit 962ee747fd
7 changed files with 495 additions and 33 deletions

View File

@@ -31,8 +31,8 @@
//
// ## Expanding
//
// To support toggle keys (icon_true/icon_false + poll block), add those fields
// to keyEntry and extend renderKeySnippet() to emit the extra YAML lines.
// Toggle keys (icon_true/icon_false + poll block) are supported — see IsToggle
// and the Poll* fields on keyEntry, and the toggle branch in renderKeySnippet().
//
// To support deleting or editing existing keys, you'd need a different strategy
// (e.g. yaml.v3 node-level manipulation). That's not in scope for the current
@@ -51,9 +51,11 @@ import (
// keyEntry holds the data collected from the TUI forms, ready to be rendered
// as a YAML snippet and appended to config.yaml.
//
// Two mutually exclusive modes:
// Three mutually exclusive modes:
// - Module key: Module + Function + Params are set, Command is empty
// - Command key: Command is set, Module/Function/Params are empty
// - Toggle key: IsToggle is true, IconTrue/IconFalse replace Icon,
// and Poll* fields define state checking. Press action uses Module or Command.
type keyEntry struct {
Index int // key slot (0-31)
Icon string // icon filename relative to icons_dir
@@ -61,6 +63,17 @@ type keyEntry struct {
Function string // function name within the module (e.g. "set_status")
Params map[string]string // param overrides (merged with module defaults at runtime)
Command string // raw shell command (non-module keys only)
// Toggle key fields
IsToggle bool
IconTrue string // icon when poll state is true/on
IconFalse string // icon when poll state is false/off
PollCommand string // shell command to check state
PollModule string // module for poll (alternative to PollCommand)
PollFunction string // function for poll
PollParams map[string]string // poll param overrides
PollMatch string // substring match in output -> true state
PollInterval string // poll frequency (e.g. "2s")
}
// appendKeyToConfig reads config.yaml, appends a key entry as raw YAML text,
@@ -123,7 +136,13 @@ func renderKeySnippet(e keyEntry) string {
var b strings.Builder
fmt.Fprintf(&b, " %d:\n", e.Index)
fmt.Fprintf(&b, " icon: %s\n", e.Icon)
if e.IsToggle {
fmt.Fprintf(&b, " icon_true: %s\n", e.IconTrue)
fmt.Fprintf(&b, " icon_false: %s\n", e.IconFalse)
} else {
fmt.Fprintf(&b, " icon: %s\n", e.Icon)
}
if e.Module != "" {
fmt.Fprintf(&b, " module: %s\n", e.Module)
@@ -144,5 +163,32 @@ func renderKeySnippet(e keyEntry) string {
fmt.Fprintf(&b, " command: \"%s\"\n", e.Command)
}
if e.IsToggle {
b.WriteString(" poll:\n")
if e.PollModule != "" {
fmt.Fprintf(&b, " module: %s\n", e.PollModule)
fmt.Fprintf(&b, " function: %s\n", e.PollFunction)
if len(e.PollParams) > 0 {
b.WriteString(" params:\n")
pkeys := make([]string, 0, len(e.PollParams))
for k := range e.PollParams {
pkeys = append(pkeys, k)
}
sort.Strings(pkeys)
for _, k := range pkeys {
fmt.Fprintf(&b, " %s: \"%s\"\n", k, e.PollParams[k])
}
}
} else {
fmt.Fprintf(&b, " command: \"%s\"\n", e.PollCommand)
}
if e.PollMatch != "" {
fmt.Fprintf(&b, " match: \"%s\"\n", e.PollMatch)
}
if e.PollInterval != "" {
fmt.Fprintf(&b, " interval: \"%s\"\n", e.PollInterval)
}
}
return b.String()
}