auto cover style: use sextants when fontconfig has a font with the glyphs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"image/color"
|
||||
_ "image/jpeg" // poster formats
|
||||
_ "image/png"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -138,9 +139,29 @@ func coverStyleFor(setting string, env func(string) string) coverStyle {
|
||||
if env("KITTY_WINDOW_ID") != "" || env("WEZTERM_PANE") != "" {
|
||||
return sextantStyle
|
||||
}
|
||||
// Other terminals (GNOME Terminal, Konsole, Alacritty...) draw glyphs their
|
||||
// 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() {
|
||||
return sextantStyle
|
||||
}
|
||||
return quadrantStyle
|
||||
}
|
||||
|
||||
// sextantFontAvailable reports whether fontconfig knows a font with the
|
||||
// sextant characters. It is a variable so tests can replace it.
|
||||
var sextantFontAvailable = func() bool {
|
||||
path, err := exec.LookPath("fc-list")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
out, err := exec.CommandContext(ctx, path, ":charset=1fb00", "family").Output()
|
||||
return err == nil && len(bytes.TrimSpace(out)) > 0
|
||||
}
|
||||
|
||||
// resolveCovers decides how posters are drawn: as real images through the
|
||||
// Kitty graphics protocol (graphics) or with block characters in the given
|
||||
// style. "kitty" asks for the protocol explicitly; "auto" uses it when the
|
||||
|
||||
Reference in New Issue
Block a user