mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
TerminalFont (Linux): fix XTGETTCAP response is printed in console when query kitty term font
This commit is contained in:
@@ -259,31 +259,35 @@ static void detectFromWindowsTerminal(const FFstrbuf* terminalExe, FFTerminalFon
|
||||
|
||||
#endif //defined(_WIN32) || defined(__linux__)
|
||||
|
||||
static bool queryKittyTerm(const char* query, FFstrbuf* res)
|
||||
{
|
||||
// https://github.com/fastfetch-cli/fastfetch/discussions/1030#discussioncomment-9845233
|
||||
char buffer[64] = "";
|
||||
if (ffGetTerminalResponse(
|
||||
query, // kitty-query-font_family;kitty-query-font_size
|
||||
"\eP1+r%*[^=]=%64[^\e]\e\\", buffer) == NULL && *buffer)
|
||||
{
|
||||
// decode hex string
|
||||
for (const char* p = buffer; p[0] && p[1]; p += 2)
|
||||
{
|
||||
unsigned value;
|
||||
if (sscanf(p, "%2x", &value))
|
||||
ffStrbufAppendC(res, (char) value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static bool detectKitty(const FFstrbuf* exe, FFTerminalFontResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
|
||||
char fontHex[64] = "", sizeHex[64] = "";
|
||||
// https://github.com/fastfetch-cli/fastfetch/discussions/1030#discussioncomment-9845233
|
||||
if (ffGetTerminalResponse(
|
||||
"\eP+q6b697474792d71756572792d666f6e745f66616d696c79;6b697474792d71756572792d666f6e745f73697a65\e\\", // kitty-query-font_family;kitty-query-font_size
|
||||
"\eP1+r%*[^=]=%64[^\e]\e\\\eP1+r%*[^=]=%64[^\e]\e\\", fontHex, sizeHex) == NULL && *fontHex && *sizeHex)
|
||||
{
|
||||
// decode hex string
|
||||
for (const char* p = fontHex; p[0] && p[1]; p += 2)
|
||||
{
|
||||
unsigned value;
|
||||
if (sscanf(p, "%2x", &value))
|
||||
ffStrbufAppendC(&fontName, (char) value);
|
||||
}
|
||||
for (const char* p = sizeHex; p[0] && p[1]; p += 2)
|
||||
{
|
||||
unsigned value;
|
||||
if (sscanf(p, "%2x", &value))
|
||||
ffStrbufAppendC(&fontSize, (char) value);
|
||||
}
|
||||
}
|
||||
// Kitty generates response independently even if we query font family and size in one query
|
||||
// which may result in short read in `ffGetTerminalResponse`
|
||||
if (queryKittyTerm("\eP+q6b697474792d71756572792d666f6e745f66616d696c79\e\\", &fontName)) // kitty-query-font_family
|
||||
queryKittyTerm("\eP+q6b697474792d71756572792d666f6e745f73697a65\e\\", &fontSize); // kitty-query-font_size
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
|
||||
|
||||
Reference in New Issue
Block a user