Touch ups and additional capabilities added to fifo functionality. Sample Fenrir scripts in extra

This commit is contained in:
Storm Dragon committed 2026-09-06 17:55:21 -04:00
1 parent 4ef8553c7d
commit 6817ecd90b
7 files changed
+75 -37

No files matched your search

+10 -3
View File
@@ -210,25 +210,32 @@ func (ui *Ui) onKeyEvent(key Key) {
}
func (ui *Ui) onCommandEvent(cmd string) {
ui.DispatchCommand(cmd)
}
// DispatchCommand sends a command to its registered listeners and reports
// whether any listener accepted it.
func (ui *Ui) DispatchCommand(cmd string) bool {
ta := strings.SplitN(cmd, " ", 2)
t := ta[0]
rest := ""
if len(ta) == 2 {
rest = ta[1]
}
handled := false
if ui.commandListeners[t] != nil {
handled = true
for _, listener := range ui.commandListeners[t] {
listener(ui, rest)
}
}
if ui.commandListeners["*"] != nil {
handled = true
for _, listener := range ui.commandListeners["*"] {
listener(ui, cmd)
}
}
// if ui.activeElement != nil {
// ui.activeElement.View.uiKeyEvent(key)
// }
return handled
}
func (ui *Ui) Add(name string, view View) error {
+18
View File
@@ -43,3 +43,21 @@ func TestSafeRuneRemovesTerminalControlCharacters(t *testing.T) {
t.Fatalf("safeRune altered printable text: %U", got)
}
}
func TestDispatchCommandReportsMatchesAndPreservesArguments(t *testing.T) {
ui := New(nil)
got := ""
ui.AddCommandListener(func(_ *Ui, command string) {
got = command
}, "record")
if !ui.DispatchCommand("record start") {
t.Fatal("registered command was not handled")
}
if got != "start" {
t.Fatalf("command argument = %q, want start", got)
}
if ui.DispatchCommand("unknown") {
t.Fatal("unknown command was reported as handled")
}
}