Detail panes: poster top right, title and facts left, plot below; sextant rendering
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -94,7 +94,7 @@ func TestQuadCell(t *testing.T) {
|
||||
{"one corner", [4]color.RGBA{red, blue, blue, blue}, '▘', red, blue, false},
|
||||
{"diagonal", [4]color.RGBA{red, black, black, red}, '▞', black, red, false},
|
||||
} {
|
||||
ch, fg, bg := quadCell(tc.px)
|
||||
ch, fg, bg := quadrantStyle.bestCell(tc.px[:])
|
||||
if ch != tc.wantCh || fg != tc.wantFg || bg != tc.wantBg {
|
||||
t.Errorf("%s: %q fg=%v bg=%v, want %q fg=%v bg=%v", tc.name, ch, fg, bg, tc.wantCh, tc.wantFg, tc.wantBg)
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func TestQuadCell(t *testing.T) {
|
||||
// Nearly flat noise stays a flat cell instead of a distracting pattern.
|
||||
n := color.RGBA{100, 100, 100, 255}
|
||||
m := color.RGBA{102, 100, 101, 255}
|
||||
if ch, _, _ := quadCell([4]color.RGBA{n, m, n, n}); ch != ' ' {
|
||||
if ch, _, _ := quadrantStyle.bestCell([]color.RGBA{n, m, n, n}); ch != ' ' {
|
||||
t.Errorf("noise rendered as %q", ch)
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func TestCoverViewDraws(t *testing.T) {
|
||||
defer screen.Fini()
|
||||
screen.SetSize(30, 10)
|
||||
|
||||
c := newCoverView()
|
||||
c := newCoverView(quadrantStyle)
|
||||
c.setImage(stripes(40, 60)) // red above blue
|
||||
c.SetRect(0, 0, 30, 10) // fits 13 columns × 10 rows
|
||||
|
||||
@@ -142,14 +142,15 @@ func TestCoverViewDraws(t *testing.T) {
|
||||
return ch, rgba(fg), rgba(bg)
|
||||
}
|
||||
red, blue := color.RGBA{255, 0, 0, 255}, color.RGBA{0, 0, 255, 255}
|
||||
if _, fg, bg := cell(0, 0); fg != red || bg != red {
|
||||
// The poster is 13 columns wide and sits against the right edge (x 17..29).
|
||||
if _, fg, bg := cell(17, 0); fg != red || bg != red {
|
||||
t.Errorf("top row = fg %v bg %v, want red", fg, bg)
|
||||
}
|
||||
if _, fg, bg := cell(12, 9); fg != blue || bg != blue {
|
||||
if _, fg, bg := cell(29, 9); fg != blue || bg != blue {
|
||||
t.Errorf("bottom right = fg %v bg %v, want blue", fg, bg)
|
||||
}
|
||||
// Outside the poster's footprint nothing is drawn.
|
||||
if ch, _, _, _ := screen.GetContent(13, 0); ch != ' ' {
|
||||
// Left of the poster's footprint nothing is drawn.
|
||||
if ch, _, _, _ := screen.GetContent(16, 0); ch != ' ' {
|
||||
t.Errorf("poster stretched beyond its aspect ratio: %q", ch)
|
||||
}
|
||||
}
|
||||
@@ -188,3 +189,58 @@ func TestLoadCoverRemembersFailures(t *testing.T) {
|
||||
t.Error("expected an error for a recently failed cover")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSextantGlyphs(t *testing.T) {
|
||||
seen := map[rune]int{}
|
||||
for mask := 0; mask < 64; mask++ {
|
||||
r := sextantGlyph(mask)
|
||||
if prev, dup := seen[r]; dup {
|
||||
t.Fatalf("masks %d and %d share the glyph %q", prev, mask, r)
|
||||
}
|
||||
seen[r] = mask
|
||||
if mask > 0 && mask < 63 && mask != 21 && mask != 42 && (r < 0x1FB00 || r > 0x1FB3B) {
|
||||
t.Errorf("mask %d: %U outside the sextant block", mask, r)
|
||||
}
|
||||
}
|
||||
for mask, want := range map[int]rune{1: 0x1FB00, 2: 0x1FB01, 20: 0x1FB13, 22: 0x1FB14, 43: 0x1FB28, 62: 0x1FB3B, 21: '▌', 42: '▐', 63: '█', 0: ' '} {
|
||||
if got := sextantGlyph(mask); got != want {
|
||||
t.Errorf("sextantGlyph(%d) = %U, want %U", mask, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSextantCell(t *testing.T) {
|
||||
red, blue := color.RGBA{255, 0, 0, 255}, color.RGBA{0, 0, 255, 255}
|
||||
// Two rows of red above one row of blue.
|
||||
ch, fg, bg := sextantStyle.bestCell([]color.RGBA{red, red, red, red, blue, blue})
|
||||
if ch != sextantGlyph(15) || fg != red || bg != blue {
|
||||
t.Errorf("got %U fg=%v bg=%v", ch, fg, bg)
|
||||
}
|
||||
// One row each: red, blue, red.
|
||||
ch, fg, bg = sextantStyle.bestCell([]color.RGBA{red, red, blue, blue, red, red})
|
||||
if ch != sextantGlyph(0b001100) || fg != blue || bg != red {
|
||||
t.Errorf("three bands: %U fg=%v bg=%v", ch, fg, bg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoverStyleFor(t *testing.T) {
|
||||
env := func(m map[string]string) func(string) string { return func(k string) string { return m[k] } }
|
||||
for _, tc := range []struct {
|
||||
setting string
|
||||
env map[string]string
|
||||
want string
|
||||
}{
|
||||
{"auto", map[string]string{"TERM": "xterm-kitty"}, "sextant"},
|
||||
{"", map[string]string{"TERM_PROGRAM": "WezTerm"}, "sextant"},
|
||||
{"auto", map[string]string{"TERM": "foot"}, "sextant"},
|
||||
{"auto", map[string]string{"KITTY_WINDOW_ID": "3", "TERM": "screen"}, "sextant"},
|
||||
{"auto", map[string]string{"TERM": "xterm-256color"}, "quadrant"},
|
||||
{"auto", nil, "quadrant"},
|
||||
{"quadrant", map[string]string{"TERM": "xterm-kitty"}, "quadrant"},
|
||||
{"sextant", nil, "sextant"},
|
||||
} {
|
||||
if got := coverStyleFor(tc.setting, env(tc.env)).name; got != tc.want {
|
||||
t.Errorf("%q %v = %s, want %s", tc.setting, tc.env, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user