fastfetch: add the missing new-line in config files (#772)

This commit is contained in:
apocelipes 2024-04-03 20:02:38 +08:00 committed by GitHub
parent 898859cc7a
commit 4430b7145e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -821,6 +821,7 @@ static void run(FFdata* data)
if (instance.state.resultDoc) 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); 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'); putchar('\n');
} }
else else
@ -840,24 +841,23 @@ static void writeConfigFile(FFdata* data, const FFstrbuf* filename)
ffOptionsGenerateLibraryJsonConfig(&instance.config.library, doc); ffOptionsGenerateLibraryJsonConfig(&instance.config.library, doc);
ffMigrateCommandOptionToJsonc(data, doc); ffMigrateCommandOptionToJsonc(data, doc);
if (ffStrbufEqualS(filename, "-")) FILE *fp = stdout;
yyjson_mut_write_fp(stdout, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); bool writeToStdout = ffStrbufEqualS(filename, "-");
else 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; fprintf(stderr, "Error: failed to generate config in `%s`\n", writeToStdout ? "stdout" : filename->chars);
FF_AUTO_FREE const char* str = yyjson_mut_write(doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, &len); exit(1);
if (!str) }
{ if (ok && !writeToStdout)
printf("Error: failed to generate config file\n"); {
exit(1); fclose(fp);
} printf("The generated config file has been written in `%s`\n", filename->chars);
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);
}
} }
yyjson_mut_doc_free(doc); yyjson_mut_doc_free(doc);