Split into category packages; module github.com/ZacharyZhang-NY/MujicaUI

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 16:18:48 -04:00
1 parent 5a7e921c7e
commit 22b53e9e9e
1822 files changed
+24568 -21314

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/egoist/mygo/ui"
"mujicaui/theme"
"github.com/ZacharyZhang-NY/MujicaUI/theme"
)
// Linear maps domain D0..D1 onto pixels R0..R1.
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"testing"
"time"
"mujicaui/theme"
"github.com/ZacharyZhang-NY/MujicaUI/theme"
)
func TestNiceAndTicks(t *testing.T) {
+2 -2
View File
@@ -3,8 +3,8 @@ package internal
import (
"github.com/egoist/mygo/ui"
"mujicaui/icons"
"mujicaui/theme"
"github.com/ZacharyZhang-NY/MujicaUI/icons"
"github.com/ZacharyZhang-NY/MujicaUI/theme"
)
// CheckState is what a drawn check box shows.
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"github.com/egoist/mygo/ui"
"mujicaui/theme"
"github.com/ZacharyZhang-NY/MujicaUI/theme"
)
// CodeSpans colors a code line; inBlock carries block comments.
+1 -1
View File
@@ -3,7 +3,7 @@ package internal
import (
"testing"
"mujicaui/theme"
"github.com/ZacharyZhang-NY/MujicaUI/theme"
)
func TestAnsiPaletteReadable(t *testing.T) {
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"github.com/egoist/mygo/ui"
"mujicaui/theme"
"github.com/ZacharyZhang-NY/MujicaUI/theme"
)
// FocusRing strokes the keyboard ring outside r, leaving the focus gap.
+116
View File
@@ -0,0 +1,116 @@
// Package snaptest compares rendered views with the PNG goldens in testdata/snapshots.
package snaptest
import (
"bytes"
"flag"
"image"
"image/png"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
"testing"
"github.com/egoist/mygo/ui"
)
var update = flag.Bool("update", false, "rewrite snapshots")
// Modes names the two themes a snapshot covers, in capture order.
var Modes = []string{"light", "dark"}
// child marks a process that renders snapshots itself.
const child = "MUJICA_SNAPSHOT_CHILD"
var ran sync.Map
// dir is the module's testdata/snapshots/<os>, whatever package runs the test.
var dir = func() string {
_, file, _, ok := runtime.Caller(0)
if !ok {
panic("snaptest: no caller")
}
return filepath.Join(filepath.Dir(file), "..", "..", "testdata", "snapshots", runtime.GOOS)
}()
// Run compares view, themed by theme for each of Modes, with testdata/snapshots/<os>/<name>-<mode>.png.
// drive, when non-nil, sends input before the capture.
func Run(t *testing.T, name string, w, h int, theme func(c *ui.Context, mode string), view func(c *ui.Context), drive func(tt *ui.Tester)) {
t.Helper()
if os.Getenv(child) == "" {
inChild(t)
return
}
for _, m := range Modes {
ready := false
tt := ui.NewTester(func(c *ui.Context) {
theme(c, m)
if ready {
view(c)
}
}, w, h)
// Animations must not paint before ReduceMotion applies.
tt.SetPreferences(ui.Preferences{ReduceMotion: true, TextScale: 1})
ready = true
tt.Frame()
if drive != nil {
drive(tt)
}
got := Encode(t, tt.Image())
path := filepath.Join(dir, name+"-"+m+".png")
if *update {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, got, 0o644); err != nil {
t.Fatal(err)
}
continue
}
want, err := os.ReadFile(path)
if err != nil {
t.Fatalf("%v (run go test -update)", err)
}
if !bytes.Equal(got, want) {
if err := os.WriteFile(path+".got.png", got, 0o644); err != nil {
t.Fatal(err)
}
t.Errorf("%s differs; see %s.got.png", path, path)
}
}
}
// inChild reruns the test alone in a fresh process; MyGo's path cache is process-wide.
func inChild(t *testing.T) {
t.Helper()
if _, done := ran.LoadOrStore(t.Name(), true); done {
return
}
parts := strings.Split(t.Name(), "/")
for i, p := range parts {
parts[i] = "^" + regexp.QuoteMeta(p) + "$"
}
args := []string{"-test.run=" + strings.Join(parts, "/"), "-test.count=1"}
if *update {
args = append(args, "-update")
}
cmd := exec.Command(os.Args[0], args...)
cmd.Env = append(os.Environ(), child+"=1")
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("snapshot child failed: %v\n%s", err, out)
}
}
// Encode returns img as PNG bytes.
func Encode(t *testing.T, img image.Image) []byte {
t.Helper()
var b bytes.Buffer
if err := png.Encode(&b, img); err != nil {
t.Fatal(err)
}
return b.Bytes()
}