diag: adjust pretty print formatting

This commit is contained in:
2025-05-08 22:24:50 +01:00
parent 592acc693f
commit 92f101e500

View File

@@ -5,6 +5,7 @@
#include <assert.h>
#include <blue/core/stringstream.h>
#include <blue/term/print.h>
#include <blue/term/tty.h>
#include <ctype.h>
#include <ivy/line-source.h>
@@ -136,10 +137,19 @@ static void print_msg(
struct ivy_diag_ctx *ctx, struct ivy_diag *diag, struct diag_c_msg *msg,
struct ivy_diag_stream *stream)
{
if (stream->s_type == IVY_DIAG_STREAM_TTY) {
b_paragraph_format format = {
.p_left_margin = 2,
.p_right_margin = 2,
};
b_print_paragraph(msg->msg_content, stream->s_tty, &format);
} else {
diag_stream_puts(stream, " ");
diag_stream_puts(stream, msg->msg_content);
diag_stream_putc(stream, '\n');
}
}
static bool highlight_contains_cell(
const struct ivy_diag_highlight *hl, size_t row, size_t col)
@@ -375,10 +385,8 @@ static void update_underline(struct snippet_print_ctx *ctx)
switch (ctx->ctx_hl->h_type) {
case IVY_DIAG_HIGHLIGHT_ERROR:
case IVY_DIAG_HIGHLIGHT_WARNING:
b_stringstream_add(&ctx->ctx_underline, "^");
break;
case IVY_DIAG_HIGHLIGHT_HINT:
b_stringstream_add(&ctx->ctx_underline, "-");
b_stringstream_add(&ctx->ctx_underline, "^");
break;
default:
b_stringstream_add(&ctx->ctx_underline, " ");
@@ -393,7 +401,7 @@ static void write_underline(struct snippet_print_ctx *ctx)
}
STREAM_COLOUR_ACCENT(ctx->ctx_stream);
diag_stream_puts(ctx->ctx_stream, " | ");
diag_stream_puts(ctx->ctx_stream, " : ");
diag_stream_puts(ctx->ctx_stream, ctx->ctx_underline_buf);
STREAM_COLOUR_RESET(ctx->ctx_stream);
diag_stream_putc(ctx->ctx_stream, '\n');