|  | 
| 1 | 1 | #include "terminalfont.h" | 
|  | 2 | +#include "common/io/io.h" | 
| 2 | 3 | #include "common/properties.h" | 
| 3 | 4 | #include "common/processing.h" | 
| 4 | 5 | #include "detection/terminalshell/terminalshell.h" | 
| @@ -256,42 +257,62 @@ static void detectFromWindowsTerminal(const FFstrbuf* terminalExe, FFTerminalFon | 
| 256 | 257 |     } | 
| 257 | 258 | } | 
| 258 | 259 | 
 | 
| 259 |  | - | 
| 260 |  | - | 
| 261 | 260 | #endif //defined(_WIN32) || defined(__linux__) | 
| 262 | 261 | 
 | 
| 263 | 262 | FF_MAYBE_UNUSED static bool detectKitty(const FFstrbuf* exe, FFTerminalFontResult* result) | 
| 264 | 263 | { | 
| 265 | 264 |     FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate(); | 
| 266 | 265 |     FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate(); | 
| 267 | 266 | 
 | 
| 268 |  | -    FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); | 
| 269 |  | -    if(!ffProcessAppendStdOut(&buf, (char* const[]){ | 
| 270 |  | -        exe->chars, | 
| 271 |  | -        "+kitten", | 
| 272 |  | -        "query-terminal", | 
| 273 |  | -        NULL, | 
| 274 |  | -    })) | 
|  | 267 | +    char fontHex[64] = "", sizeHex[64] = ""; | 
|  | 268 | +    // https://github.com/fastfetch-cli/fastfetch/discussions/1030#discussioncomment-9845233 | 
|  | 269 | +    if (ffGetTerminalResponse( | 
|  | 270 | +        "\eP+q6b697474792d71756572792d666f6e745f66616d696c79;6b697474792d71756572792d666f6e745f73697a65\e\\", // kitty-query-font_family;kitty-query-font_size | 
|  | 271 | +        "\eP1+r%*[^=]=%64[^\e]\e\\\eP1+r%*[^=]=%64[^\e]\e\\", fontHex, sizeHex) == NULL && *fontHex && *sizeHex) | 
| 275 | 272 |     { | 
| 276 |  | -        ffParsePropLines(buf.chars, "font_family: ", &fontName); | 
| 277 |  | -        ffParsePropLines(buf.chars, "font_size: ", &fontSize); | 
|  | 273 | +        // decode hex string | 
|  | 274 | +        for (const char* p = fontHex; p[0] && p[1]; p += 2) | 
|  | 275 | +        { | 
|  | 276 | +            unsigned value; | 
|  | 277 | +            if (sscanf(p, "%2x", &value)) | 
|  | 278 | +                ffStrbufAppendC(&fontName, (char) value); | 
|  | 279 | +        } | 
|  | 280 | +        for (const char* p = sizeHex; p[0] && p[1]; p += 2) | 
|  | 281 | +        { | 
|  | 282 | +            unsigned value; | 
|  | 283 | +            if (sscanf(p, "%2x", &value)) | 
|  | 284 | +                ffStrbufAppendC(&fontSize, (char) value); | 
|  | 285 | +        } | 
| 278 | 286 |     } | 
| 279 | 287 |     else | 
| 280 | 288 |     { | 
| 281 |  | -        FFpropquery fontQuery[] = { | 
| 282 |  | -            {"font_family ", &fontName}, | 
| 283 |  | -            {"font_size ", &fontSize}, | 
| 284 |  | -        }; | 
|  | 289 | +        FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); | 
|  | 290 | +        if(!ffProcessAppendStdOut(&buf, (char* const[]){ | 
|  | 291 | +            exe->chars, | 
|  | 292 | +            "+kitten", | 
|  | 293 | +            "query-terminal", | 
|  | 294 | +            NULL, | 
|  | 295 | +        })) | 
|  | 296 | +        { | 
|  | 297 | +            ffParsePropLines(buf.chars, "font_family: ", &fontName); | 
|  | 298 | +            ffParsePropLines(buf.chars, "font_size: ", &fontSize); | 
|  | 299 | +        } | 
|  | 300 | +        else | 
|  | 301 | +        { | 
|  | 302 | +            FFpropquery fontQuery[] = { | 
|  | 303 | +                {"font_family ", &fontName}, | 
|  | 304 | +                {"font_size ", &fontSize}, | 
|  | 305 | +            }; | 
| 285 | 306 | 
 | 
| 286 |  | -        ffParsePropFileConfigValues("kitty/kitty.conf", 2, fontQuery); | 
|  | 307 | +            ffParsePropFileConfigValues("kitty/kitty.conf", 2, fontQuery); | 
| 287 | 308 | 
 | 
| 288 |  | -        if(fontName.length == 0) | 
| 289 |  | -            ffStrbufSetS(&fontName, "monospace"); | 
| 290 |  | -        if(fontSize.length == 0) | 
| 291 |  | -            ffStrbufSetS(&fontSize, "11.0"); | 
|  | 309 | +            if(fontName.length == 0) | 
|  | 310 | +                ffStrbufSetS(&fontName, "monospace"); | 
|  | 311 | +            if(fontSize.length == 0) | 
|  | 312 | +                ffStrbufSetS(&fontSize, "11.0"); | 
|  | 313 | +        } | 
| 292 | 314 |     } | 
| 293 | 315 | 
 | 
| 294 |  | - | 
| 295 | 316 |     ffFontInitValues(&result->font, fontName.chars, fontSize.chars); | 
| 296 | 317 | 
 | 
| 297 | 318 |     return true; | 
|  | 
0 commit comments