Skip to content

Commit aa45e70

Browse files
committed
Revert "fastfetch: add the missing new-line in config files (#772)"
Fix #778 This reverts commit 4430b71.
1 parent 5374feb commit aa45e70

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/fastfetch.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@ static void run(FFdata* data)
821821
if (instance.state.resultDoc)
822822
{
823823
yyjson_mut_write_fp(stdout, instance.state.resultDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL);
824-
//TODO should use YYJSON_WRITE_NEWLINE_AT_END when it is available
825824
putchar('\n');
826825
}
827826
else
@@ -841,23 +840,24 @@ static void writeConfigFile(FFdata* data, const FFstrbuf* filename)
841840
ffOptionsGenerateLibraryJsonConfig(&instance.config.library, doc);
842841
ffMigrateCommandOptionToJsonc(data, doc);
843842

844-
FILE *fp = stdout;
845-
bool writeToStdout = ffStrbufEqualS(filename, "-");
846-
if (!writeToStdout)
847-
fp = fopen(filename->chars, "w");
848-
849-
bool ok = yyjson_mut_write_fp(fp, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL);
850-
//TODO should use YYJSON_WRITE_NEWLINE_AT_END when it is available
851-
fputc('\n', fp);
852-
if (!ok)
853-
{
854-
fprintf(stderr, "Error: failed to generate config in `%s`\n", writeToStdout ? "stdout" : filename->chars);
855-
exit(1);
856-
}
857-
if (ok && !writeToStdout)
843+
if (ffStrbufEqualS(filename, "-"))
844+
yyjson_mut_write_fp(stdout, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL);
845+
else
858846
{
859-
fclose(fp);
860-
printf("The generated config file has been written in `%s`\n", filename->chars);
847+
size_t len;
848+
FF_AUTO_FREE const char* str = yyjson_mut_write(doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, &len);
849+
if (!str)
850+
{
851+
printf("Error: failed to generate config file\n");
852+
exit(1);
853+
}
854+
if (ffWriteFileData(filename->chars, len, str))
855+
printf("The generated config file has been written in `%s`\n", filename->chars);
856+
else
857+
{
858+
printf("Error: failed to write file in `%s`\n", filename->chars);
859+
exit(1);
860+
}
861861
}
862862

863863
yyjson_mut_doc_free(doc);

0 commit comments

Comments
 (0)