Skip to content

Commit

Permalink
fastfetch: add the missing new-line in config files (fastfetch-cli#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
apocelipes authored Apr 3, 2024
1 parent 898859c commit 4430b71
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/fastfetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ static void run(FFdata* data)
if (instance.state.resultDoc)
{
yyjson_mut_write_fp(stdout, instance.state.resultDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL);
//TODO should use YYJSON_WRITE_NEWLINE_AT_END when it is available
putchar('\n');
}
else
Expand All @@ -840,24 +841,23 @@ static void writeConfigFile(FFdata* data, const FFstrbuf* filename)
ffOptionsGenerateLibraryJsonConfig(&instance.config.library, doc);
ffMigrateCommandOptionToJsonc(data, doc);

if (ffStrbufEqualS(filename, "-"))
yyjson_mut_write_fp(stdout, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL);
else
FILE *fp = stdout;
bool writeToStdout = ffStrbufEqualS(filename, "-");
if (!writeToStdout)
fp = fopen(filename->chars, "w");

bool ok = yyjson_mut_write_fp(fp, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL);
//TODO should use YYJSON_WRITE_NEWLINE_AT_END when it is available
fputc('\n', fp);
if (!ok)
{
size_t len;
FF_AUTO_FREE const char* str = yyjson_mut_write(doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, &len);
if (!str)
{
printf("Error: failed to generate config file\n");
exit(1);
}
if (ffWriteFileData(filename->chars, len, str))
printf("The generated config file has been written in `%s`\n", filename->chars);
else
{
printf("Error: failed to write file in `%s`\n", filename->chars);
exit(1);
}
fprintf(stderr, "Error: failed to generate config in `%s`\n", writeToStdout ? "stdout" : filename->chars);
exit(1);
}
if (ok && !writeToStdout)
{
fclose(fp);
printf("The generated config file has been written in `%s`\n", filename->chars);
}

yyjson_mut_doc_free(doc);
Expand Down

0 comments on commit 4430b71

Please sign in to comment.