TerminalFont: improves Ghostty config loading with fallback support

Fixes: #2500
This commit is contained in:
Carter Li
2026-08-08 22:38:53 +08:00
parent ac8fc63c28
commit 881730d0bd
+14 -3
View File
@@ -69,7 +69,7 @@ static void detectAlacritty(FFTerminalFontResult* terminalFont) {
ffFontInitMoveValues(&terminalFont->font, &fontFamily, &fontSize, &fontStyle);
}
static void parseGhosttyConfig(const FFstrbuf* path, FFstrbuf* fontName, FFstrbuf* fontNameFallback, FFstrbuf* fontSize, FFlist* configFiles /* list of FFstrbuf */) {
static void parseGhosttyConfig(FFstrbuf* path, FFstrbuf* fontName, FFstrbuf* fontNameFallback, FFstrbuf* fontSize, FFlist* configFiles /* list of FFstrbuf */) {
// Maximum number of `config-file` directives to follow, guarding against runaway includes
enum { FF_GHOSTTY_MAX_CONFIG_FILES = 16 };
@@ -79,7 +79,18 @@ static void parseGhosttyConfig(const FFstrbuf* path, FFstrbuf* fontName, FFstrbu
FF_STRBUF_AUTO_DESTROY temp = ffStrbufCreate();
if (!ffAppendFileBuffer(path->chars, &buffer)) {
FF_DEBUG("cannot read config: %s", path->chars);
return;
if (ffStrbufEndsWithS(path, ".ghostty")) {
FF_DEBUG("Trying to load config without .ghostty extension");
path->chars[path->length - strlen(".ghostty")] = '\0';
bool ok = ffAppendFileBuffer(path->chars, &buffer);
path->chars[path->length - strlen(".ghostty")] = '.';
if (!ok) {
FF_DEBUG("cannot read config: %s", path->chars);
return;
}
} else {
return;
}
}
char* line = nullptr;
@@ -394,7 +405,7 @@ static bool detectTerminalFontCommon(const FFTerminalResult* terminal, FFTermina
} else if (ffStrbufStartsWithIgnCaseS(&terminal->processName, "contour")) {
detectContour(&terminal->exe, terminalFont);
} else if (ffStrbufStartsWithIgnCaseS(&terminal->processName, "ghostty")) {
detectGhostty(terminalFont, "com.mitchellh.ghostty/config", "ghostty/config");
detectGhostty(terminalFont, "com.mitchellh.ghostty/config.ghostty", "ghostty/config.ghostty");
} else if (ffStrbufStartsWithIgnCaseS(&terminal->processName, "Muxy")) {
detectGhostty(terminalFont, "Muxy/ghostty.conf", "muxy/ghostty.conf");
} else if (ffStrbufStartsWithIgnCaseS(&terminal->processName, "rio")) {