Repository: fastfetch-cli/fastfetch
File: src/modules/terminalfont.c (C)

Code before:

    ffStrbufDestroy(&name);
    ffStrbufDestroy(&pretty);
}

static void printTerminalFontFromConfigFile(FFinstance* instance, const char* configFile, const char* regex)
{
    char font[128];
    ffParsePropFileConfig(instance, configFile, regex, font);
    if(font[0] == '\0')
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"%s\" in \"$XDG_CONFIG_HOME/%s\"", regex, configFile);
        return;
    }

    printTerminalFont(instance, font);
}

static void printXCFETerminal(FFinstance* instance)
{
    FFstrbuf fontName;
    ffStrbufInitA(&fontName, 256);

    ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem=%[^\n]", fontName.chars);

    if((fontName.chars[0] == '\0') || !ffStrbufCompS(&fontName, "FALSE"))
    {
        printTerminalFontFromConfigFile(instance, "xfce4/terminal/terminalrc", "FontName=%[^\n]");
        ffStrbufDestroy(&fontName);
        return;
    }

    FFstrbuf absolutePath;
    ffStrbufInitA(&absolutePath, 64);
    ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir);
    ffStrbufAppendC(&absolutePath, '/');
    ffStrbufAppendS(&absolutePath, ".config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml");

    FILE* file = fopen(absolutePath.chars, "r");
    if(file == NULL)
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't open \"%s\"", absolutePath.chars);
        ffStrbufDestroy(&absolutePath);
        ffStrbufDestroy(&fontName);

        return;
    }

    FFstrbuf matchText;
    ffStrbufInitAS(&matchText, 64, "<property name=\"MonospaceFontName\" type=\"string\" value=\"");


Review comment (suggestion):
* A `fontName.length == 0` is the better way to test for this when using strbufs.
* Maybe an `ffStrbufIgnCaseComp` would be more save to get it right?
* I think a `) == 0` is more readable as a `!` which implicitly casts an `uint32_t` to a `bool`

Code after:
    }

    ffStrbufDestroy(&name);
    ffStrbufDestroy(&pretty);
}

static void printTerminalFontFromConfigFile(FFinstance* instance, const char* configFile, const char* regex)
{
    char font[128];
    ffParsePropFileConfig(instance, configFile, regex, font);
    if(font[0] == '\0')
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"%s\" in \"$XDG_CONFIG_HOME/%s\"", regex, configFile);
        return;
    }

    printTerminalFont(instance, font);
}

static void printKonsole(FFinstance* instance)
{
    char profile[128];
    ffParsePropFileConfig(instance, "konsolerc", "DefaultProfile=%[^\n]", profile);
    if(profile[0] == '\0')
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"DefaultProfile=%[^\n]\" in \".config/konsolerc\"");
        return;
    }

    char profilePath[256];
    sprintf(profilePath, ".local/share/konsole/%s", profile);

    char font[128];
    ffParsePropFileHome(instance, profilePath, "Font=%[^\n]", font);
    if(font[0] == '\0')
    {
        ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
        return;
    }

    printTerminalFont(instance, font);
}

static void printTilixTerminal(FFinstance* instance)
{    // Note - Subject to change when DConf/GSettings fix their implementations of defaults/relocatable schemas respectively
    const char* fontName = NULL;

    const char* defaultProfile = ffSettingsGetGsettings(instance, "com.gexperts.Tilix.ProfilesList", NULL, "default", FF_VARIANT_TYPE_STRING).strValue;

    if(!defaultProfile)
    {