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:
+21
-3
@@ -13,7 +13,9 @@ import (
|
||||
_ "golang.org/x/image/webp"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -147,7 +149,9 @@ func coverStyleFor(setting string, env func(string) string) coverStyle {
|
||||
// font lacks from a fallback font, so sextants work if some installed font
|
||||
// has them. Over SSH the installed fonts are the remote machine's, which
|
||||
// says nothing about the terminal, so keep the safe style there.
|
||||
if env("SSH_CONNECTION") == "" && env("SSH_TTY") == "" && sextantFontAvailable() {
|
||||
// macOS terminals do not draw missing glyphs from fontconfig's fonts, so a
|
||||
// font found there says nothing about them.
|
||||
if runtime.GOOS != "darwin" && env("SSH_CONNECTION") == "" && env("SSH_TTY") == "" && sextantFontAvailable() {
|
||||
return sextantStyle
|
||||
}
|
||||
return quadrantStyle
|
||||
@@ -174,13 +178,27 @@ var sextantFontAvailable = func() bool {
|
||||
func resolveCovers(setting string, env func(string) string) (blocks coverStyle, graphics bool) {
|
||||
switch setting {
|
||||
case "kitty":
|
||||
return coverStyleFor("auto", env), true
|
||||
// Asked for explicitly, but a terminal without the protocol prints the
|
||||
// commands as text, so it is still confirmed.
|
||||
return coverStyleFor("auto", env), kittyGraphicsSupported()
|
||||
case "auto", "":
|
||||
return coverStyleFor("auto", env), kittyTerminal(env)
|
||||
return coverStyleFor("auto", env), kittyTerminal(env) && kittyGraphicsSupported()
|
||||
}
|
||||
return coverStyleFor(setting, env), false
|
||||
}
|
||||
|
||||
var (
|
||||
kittyProbeOnce sync.Once
|
||||
kittyProbeResult bool
|
||||
)
|
||||
|
||||
// kittyGraphicsSupported asks the terminal once (see probeKittyGraphics) and
|
||||
// remembers the answer. It is a variable so tests can replace it.
|
||||
var kittyGraphicsSupported = func() bool {
|
||||
kittyProbeOnce.Do(func() { kittyProbeResult = probeKittyGraphics(300 * time.Millisecond) })
|
||||
return kittyProbeResult
|
||||
}
|
||||
|
||||
// flatPixelError is the squared RGB distance per pixel below which a cell is
|
||||
// drawn flat: smooth areas and noise should not turn into patterns.
|
||||
const flatPixelError = 150
|
||||
|
||||
Reference in New Issue
Block a user