83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
//go:build linux && cgo
|
|
|
|
package terminal
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"testing"
|
|
|
|
"git.stormux.org/storm/fenrir/internal/applicationoverrides/ninjam"
|
|
"git.stormux.org/storm/fenrir/internal/command"
|
|
"git.stormux.org/storm/fenrir/internal/reader"
|
|
)
|
|
|
|
// Exercise actual libvterm attribute decoding, including ncurses' monochrome
|
|
// standout path. These are source-derived terminal writes, not a running client.
|
|
func TestNinjamOverrideTerminalPresentation(t *testing.T) {
|
|
for _, monochrome := range []bool{false, true} {
|
|
t.Run(fmt.Sprint(monochrome), func(t *testing.T) {
|
|
e, err := new_emulator(24, 100)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer e.close()
|
|
r, a := reader.New(), &ninjam.Adapter{}
|
|
paint := func(selected int, volume, chat string) []string {
|
|
e.feed([]byte("\x1b[0m\x1b[2J\x1b[HLOCAL\x1b[2;1H"))
|
|
field := 0
|
|
for _, char := range " master: [ ]mute [" + volume + "] | metronome: [ ]mute [0.0dB center]" {
|
|
if char == ']' {
|
|
e.feed([]byte("\x1b[0m"))
|
|
}
|
|
e.feed([]byte(string(char)))
|
|
if char == '[' {
|
|
style := "\x1b[1m"
|
|
if field == selected {
|
|
style = "\x1b[0;30;47m"
|
|
if monochrome {
|
|
style = "\x1b[0;7m"
|
|
}
|
|
}
|
|
e.feed([]byte(style))
|
|
field++
|
|
}
|
|
}
|
|
e.feed([]byte("\x1b[17;1HCHAT\x1b[20;1H<Username> old\x1b[21;1H" + chat + "\x1b[23;1H#####\x1b[24;1H[QUIT NINJAM] : fixture.invalid : 120.0BPM 16BPI\x1b[24;1H"))
|
|
s := e.snapshot(true, false)
|
|
var result []string
|
|
for _, message := range r.Update_application(s, a.Observe(s)) {
|
|
if message.Text != "" {
|
|
result = append(result, message.Text)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
if got := paint(0, "0.0dB center", ""); !slices.Equal(got, []string{"Master unmuted"}) {
|
|
t.Fatal(got)
|
|
}
|
|
r.Command(command.CurrentLine)
|
|
r.Note_input(true, false, false)
|
|
if got := paint(1, "0.0dB center", "<Username> new"); !slices.Equal(got, []string{"Master Volume and pan 0.0dB center", "<Username> new"}) {
|
|
t.Fatal(got)
|
|
}
|
|
if got := paint(1, "-0.5dB center", "<Username> new"); !slices.Equal(got, []string{"minus 0.5dB"}) {
|
|
t.Fatal(got)
|
|
}
|
|
for _, trial := range []struct{ value, want string }{
|
|
{"-0.5dB 1%L", "1 percent left"},
|
|
{"-0.5dB center", "center"},
|
|
{"-0.5dB 1%R", "1 percent right"},
|
|
{"+0.5dB 1%R", "plus 0.5dB"},
|
|
} {
|
|
if got := paint(1, trial.value, "<Username> new"); !slices.Equal(got, []string{trial.want}) {
|
|
t.Fatal(trial.value, got)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|