From bb4ce15997a3023c5c4f2bb434b37699797272da Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 6 Jul 2025 22:47:01 +0200 Subject: Make multiline output look better --- lib/output.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'lib/output.c') diff --git a/lib/output.c b/lib/output.c index 61fbf832..fbde490e 100644 --- a/lib/output.c +++ b/lib/output.c @@ -332,7 +332,37 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch mp_subcheck_list *subchecks = NULL; switch (output_format) { - case MP_FORMAT_MULTI_LINE: + case MP_FORMAT_MULTI_LINE: { + char *tmp_string = NULL; + if ((tmp_string = strchr(check.output, '\n')) != NULL) { + // This is a multiline string, put the correct indentation in before proceeding + char *intermediate_string = ""; + bool have_residual_chars = false; + + while (tmp_string != NULL) { + *tmp_string = '\0'; + xasprintf(&intermediate_string, "%s%s\n%s", intermediate_string,check.output, generate_indentation_string(indentation+1)); // one more indentation to make it look better + + if (*(tmp_string + 1) != '\0') { + check.output = tmp_string + 1; + have_residual_chars = true; + } else { + // Null after the \n, so this is the end + have_residual_chars = false; + break; + } + + tmp_string = strchr(check.output, '\n'); + } + + // add the rest (if any) + if (have_residual_chars) { + char *tmp = check.output; + xasprintf(&check.output, "%s\n%s%s", intermediate_string, generate_indentation_string(indentation+1), tmp); + } else { + check.output = intermediate_string; + } + } asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation), state_text(mp_compute_subcheck_state(check)), check.output); @@ -343,6 +373,7 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch subchecks = subchecks->next; } return result; + } default: die(STATE_UNKNOWN, "Invalid format"); } -- cgit v1.2.3-74-g34f1