Add mnemonic mute controls

This commit is contained in:
Storm Dragon committed 2026-09-05 00:57:37 -04:00
1 parent ef19a558d2
commit 97fcde7e96
13 files changed
+232 -17

No files matched your search

+16
View File
@@ -1,15 +1,31 @@
package uiterm
import (
"fmt"
"unicode"
"unicode/utf8"
)
// MarshalText implements the encoding.TextMarshaler interface for Key
// This allows TOML to serialize Key values as strings
func (i Key) MarshalText() ([]byte, error) {
if r := rune(i); r >= 0x21 && r <= unicode.MaxASCII && unicode.IsPrint(r) {
return []byte(string(r)), nil
}
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Key
// This allows TOML to deserialize strings back into Key values
func (i *Key) UnmarshalText(data []byte) error {
if r, size := utf8.DecodeRune(data); r != utf8.RuneError && size == len(data) && unicode.IsPrint(r) {
*i = Key(unicode.ToLower(r))
return nil
}
var err error
*i, err = KeyString(string(data))
if err != nil {
return fmt.Errorf("invalid key %q: %w", data, err)
}
return err
}
+35
View File
@@ -0,0 +1,35 @@
package uiterm
import "testing"
func TestPrintableKeyTextRoundTrip(t *testing.T) {
encoded, err := KeyM.MarshalText()
if err != nil {
t.Fatal(err)
}
if string(encoded) != "m" {
t.Fatalf("encoded key = %q, want m", encoded)
}
var decoded Key
if err := decoded.UnmarshalText([]byte("M")); err != nil {
t.Fatal(err)
}
if decoded != KeyM {
t.Fatalf("decoded key = %v, want %v", decoded, KeyM)
}
}
func TestNamedKeyTextStillRoundTrips(t *testing.T) {
encoded, err := KeyCtrlT.MarshalText()
if err != nil {
t.Fatal(err)
}
var decoded Key
if err := decoded.UnmarshalText(encoded); err != nil {
t.Fatal(err)
}
if decoded != KeyCtrlT {
t.Fatalf("decoded key = %v, want %v", decoded, KeyCtrlT)
}
}
+5
View File
@@ -0,0 +1,5 @@
package uiterm
// Printable keys normally arrive through a view's character handler rather
// than the special-key handler.
const KeyM Key = 'm'