Repository: fastfetch-cli/fastfetch
File: src/common/logo.c (C)

Code before:
    sprintf(logo->chars[2],  FASTFETCH_TEXT_MODIFIER_BOLT"%s              .8Xxd                8X:.       "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[3],  FASTFETCH_TEXT_MODIFIER_BOLT"%s            .8Xx;                    8x:.     "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[4],  FASTFETCH_TEXT_MODIFIER_BOLT"%s          .tt8x          .d            x88;   "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[5],  FASTFETCH_TEXT_MODIFIER_BOLT"%s       .@8x8;          .db:              xx@; "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[6],  FASTFETCH_TEXT_MODIFIER_BOLT"%s     ,tSXX°          .bbbbbbbbbbbbbbbbbbbB8x@;"FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[7],  FASTFETCH_TEXT_MODIFIER_BOLT"%s   .SXxx            bBBBBBBBBBBBBBBBBBBBbSBX8;"FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[8],  FASTFETCH_TEXT_MODIFIER_BOLT"%s ,888S                                     pd!"FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[9],  FASTFETCH_TEXT_MODIFIER_BOLT"%s8X88/                                       qp"FASTFETCH_TEXT_MODIFIER_RESET, color);                                                                                                                                                                                                                                                                                                                                                                                                         
    sprintf(logo->chars[10], FASTFETCH_TEXT_MODIFIER_BOLT"%s8X88/                                         "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[11], FASTFETCH_TEXT_MODIFIER_BOLT"%sGBB.                                          "FASTFETCH_TEXT_MODIFIER_RESET, color);                                                                                                                                                       
    sprintf(logo->chars[12], FASTFETCH_TEXT_MODIFIER_BOLT"%s x%%88        d888@8@X@X@X88X@@XX@@X@8@X.      "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[13], FASTFETCH_TEXT_MODIFIER_BOLT"%s   dxXd    dB8b8b8B8B08bB88b998888b88x.       "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[14], FASTFETCH_TEXT_MODIFIER_BOLT"%s    dxx8o                      .@@;.          "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[15], FASTFETCH_TEXT_MODIFIER_BOLT"%s      dx88                   .t@x.            "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[16], FASTFETCH_TEXT_MODIFIER_BOLT"%s        d:SS@8ba89aa67a853Sxxad.              "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[17], FASTFETCH_TEXT_MODIFIER_BOLT"%s          .d988999889889899dd.                "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[18], FASTFETCH_TEXT_MODIFIER_BOLT"%s                                              "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[19], FASTFETCH_TEXT_MODIFIER_BOLT"%s                                              "FASTFETCH_TEXT_MODIFIER_RESET, color);
}

static void loadLogoFromFile(FFlogo* logo, bool doColor, char* pathToFile)
{
    strcpy(logo->name, "amogus");

    const char* color = doColor ? "\033[91m" : "";
    strcpy(logo->color, "\033[91m");

    FILE* fp = fopen(pathToFile, "r");
    char buff[255];
    char* normalizedBuff;
    int len;

    int logoWidth = 0, logoHeight = 0;
    while(!feof(fp)) {
        fgets(buff, sizeof(buff), fp);
        normalizedBuff = strtok(buff, "\n");
        
        sprintf(logo->chars[logoHeight++],   FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET, color, normalizedBuff);

        len = utf8_strlen(normalizedBuff);
        logoWidth = len > logoWidth
            ? len
            : logoWidth;
    }

    fclose(fp);

    logo->width = logoWidth;
    logo->height = logoHeight;
}


Review comment (suggestion):
I don't think we should set the same color for every logo loaded from file. Use the `--color` option to set it.

Code after:
    sprintf(logo->chars[2],  FASTFETCH_TEXT_MODIFIER_BOLT"%s              .8Xxd                8X:.       "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[3],  FASTFETCH_TEXT_MODIFIER_BOLT"%s            .8Xx;                    8x:.     "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[4],  FASTFETCH_TEXT_MODIFIER_BOLT"%s          .tt8x          .d            x88;   "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[5],  FASTFETCH_TEXT_MODIFIER_BOLT"%s       .@8x8;          .db:              xx@; "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[6],  FASTFETCH_TEXT_MODIFIER_BOLT"%s     ,tSXX°          .bbbbbbbbbbbbbbbbbbbB8x@;"FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[7],  FASTFETCH_TEXT_MODIFIER_BOLT"%s   .SXxx            bBBBBBBBBBBBBBBBBBBBbSBX8;"FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[8],  FASTFETCH_TEXT_MODIFIER_BOLT"%s ,888S                                     pd!"FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[9],  FASTFETCH_TEXT_MODIFIER_BOLT"%s8X88/                                       qp"FASTFETCH_TEXT_MODIFIER_RESET, color);                                                                                                                                                                                                                                                                                                                                                                                                         
    sprintf(logo->chars[10], FASTFETCH_TEXT_MODIFIER_BOLT"%s8X88/                                         "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[11], FASTFETCH_TEXT_MODIFIER_BOLT"%sGBB.                                          "FASTFETCH_TEXT_MODIFIER_RESET, color);                                                                                                                                                       
    sprintf(logo->chars[12], FASTFETCH_TEXT_MODIFIER_BOLT"%s x%%88        d888@8@X@X@X88X@@XX@@X@8@X.      "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[13], FASTFETCH_TEXT_MODIFIER_BOLT"%s   dxXd    dB8b8b8B8B08bB88b998888b88x.       "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[14], FASTFETCH_TEXT_MODIFIER_BOLT"%s    dxx8o                      .@@;.          "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[15], FASTFETCH_TEXT_MODIFIER_BOLT"%s      dx88                   .t@x.            "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[16], FASTFETCH_TEXT_MODIFIER_BOLT"%s        d:SS@8ba89aa67a853Sxxad.              "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[17], FASTFETCH_TEXT_MODIFIER_BOLT"%s          .d988999889889899dd.                "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[18], FASTFETCH_TEXT_MODIFIER_BOLT"%s                                              "FASTFETCH_TEXT_MODIFIER_RESET, color);
    sprintf(logo->chars[19], FASTFETCH_TEXT_MODIFIER_BOLT"%s                                              "FASTFETCH_TEXT_MODIFIER_RESET, color);
}

static void loadLogoFromFile(FFlogo* logo, bool doColor, FFstrbuf* configColor, const char* pathToFile)
{
    const char* color = doColor ? configColor->chars : "";
    strcpy(logo->color, color);

    FILE* fp = fopen(pathToFile, "r");
    char* buff = NULL;
    size_t buffLen = 0;
    int lineBytes;
    int lineLength;

    int logoWidth = 0, logoHeight = 0;
    while( (lineBytes=getline(&buff, &buffLen, fp)) != -1 ) {
        // Remove trailing newline
        if(buff[lineBytes-1] == '\n')
            buff[lineBytes-1] = '\0';
        
        sprintf(logo->chars[logoHeight++],   FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET, color, buff);

        lineLength = utf8_strlen(buff);
        logoWidth = lineLength > logoWidth
            ? lineLength
            : logoWidth;
    }

    // Clean up
    fclose(fp);
    if(buff != NULL)
        free(buff);

    logo->width = logoWidth;