Ask the terminal before using Kitty graphics; no fontconfig-based sextants on macOS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019reK4DUGYqDUjniWYJvwUW
This commit is contained in:
@@ -165,6 +165,8 @@ func TestPlaceholderCell(t *testing.T) {
|
||||
func TestKittyTerminalDetection(t *testing.T) {
|
||||
defer func(old func() bool) { sextantFontAvailable = old }(sextantFontAvailable)
|
||||
sextantFontAvailable = func() bool { return false } // not what these cases are about
|
||||
defer func(old func() bool) { kittyGraphicsSupported = old }(kittyGraphicsSupported)
|
||||
kittyGraphicsSupported = func() bool { return true } // the terminal confirms
|
||||
env := func(m map[string]string) func(string) string { return func(k string) string { return m[k] } }
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
@@ -368,3 +370,26 @@ func TestGraphicsDebugReportsUploads(t *testing.T) {
|
||||
t.Errorf("debug lines = %q", lines)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGraphicsNeedTheTerminalsConfirmation(t *testing.T) {
|
||||
defer func(old func() bool) { kittyGraphicsSupported = old }(kittyGraphicsSupported)
|
||||
env := func(m map[string]string) func(string) string { return func(k string) string { return m[k] } }
|
||||
ghostty := env(map[string]string{"TERM": "xterm-ghostty"})
|
||||
|
||||
kittyGraphicsSupported = func() bool { return false } // e.g. a terminal that claims kitty but prints APC as text
|
||||
if _, gfx := resolveCovers("auto", ghostty); gfx {
|
||||
t.Error("auto must not use real images when the terminal does not answer the query")
|
||||
}
|
||||
if _, gfx := resolveCovers("kitty", ghostty); gfx {
|
||||
t.Error("even an explicit kitty setting must not send graphics a terminal does not understand")
|
||||
}
|
||||
|
||||
asked := false
|
||||
kittyGraphicsSupported = func() bool { asked = true; return true }
|
||||
if _, gfx := resolveCovers("auto", env(map[string]string{"TERM": "xterm-256color", "TERM_PROGRAM": "Apple_Terminal"})); gfx || asked {
|
||||
t.Error("a terminal not known for the protocol is not even asked (it might print the query)")
|
||||
}
|
||||
if _, gfx := resolveCovers("auto", ghostty); !gfx || !asked {
|
||||
t.Error("a known terminal that answers gets real images")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user