From 34417ae69299696e7325564c8df405d062cdbd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 2 Sep 2023 08:07:28 -0400 Subject: [PATCH] TerminalFont: support contour --- CHANGELOG.md | 1 + src/detection/terminalfont/terminalfont.c | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2b089d0b..7b9597dc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Features: * Add fast path for xfce4 version detection (DE, FreeBSD) +* Add contour terminal version and font detection (Terminal / TerminalFont) Bugfixes: * Fix `fastfetch --config verbose` doesn't work (#547) diff --git a/src/detection/terminalfont/terminalfont.c b/src/detection/terminalfont/terminalfont.c index 8fcb7db6c..01931b861 100644 --- a/src/detection/terminalfont/terminalfont.c +++ b/src/detection/terminalfont/terminalfont.c @@ -338,6 +338,35 @@ static bool detectTabby(FFTerminalFontResult* result) return true; } +static bool detectContour(const FFstrbuf* exe, FFTerminalFontResult* result) +{ + FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); + if(ffProcessAppendStdOut(&buf, (char* const[]){ + exe->chars, + "font-locator", + NULL + })) + { + ffStrbufAppendS(&result->error, "`contour font-locator` failed"); + return false; + } + + //[error] Missing key .logging.enabled. Using default: false. + //[error] ... + //Matching fonts using : Fontconfig + //Font description : (family=Sarasa Term SC Nerd weight=Regular slant=Roman spacing=Monospace, strict_spacing=yes) + //Number of fonts found : 49 + // path /usr/share/fonts/google-noto/NotoSansMono-Regular.ttf Regular Roman + // path ... + + uint32_t index = ffStrbufFirstIndexS(&buf, "Font description : (family="); + if(index >= buf.length) return false; + index += strlen("Font description : (family="); + ffStrbufSubstrBefore(&buf, ffStrbufNextIndexS(&buf, index, " weight=")); + ffFontInitCopy(&result->font, buf.chars + index); + return true; +} + void ffDetectTerminalFontPlatform(const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont); static bool detectTerminalFontCommon(const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont) @@ -350,6 +379,8 @@ static bool detectTerminalFontCommon(const FFTerminalShellResult* terminalShell, detectWezterm(terminalFont); else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalProcessName, "tabby")) detectTabby(terminalFont); + else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalProcessName, "contour")) + detectContour(&terminalShell->terminalExe, terminalFont); #ifndef _WIN32 else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/pts/"))