tool: diag: output formatting fixes
This commit is contained in:
@@ -19,8 +19,9 @@ struct snippet_print_ctx {
|
|||||||
struct mie_line_source *ctx_line_source;
|
struct mie_line_source *ctx_line_source;
|
||||||
|
|
||||||
size_t ctx_row, ctx_col;
|
size_t ctx_row, ctx_col;
|
||||||
|
size_t ctx_indent_offset;
|
||||||
|
|
||||||
bool ctx_has_underline;
|
bool ctx_has_underline, ctx_in_content;
|
||||||
b_stringstream *ctx_underline;
|
b_stringstream *ctx_underline;
|
||||||
const b_string *ctx_linebuf;
|
const b_string *ctx_linebuf;
|
||||||
const b_iterator *ctx_linebuf_ptr;
|
const b_iterator *ctx_linebuf_ptr;
|
||||||
@@ -224,18 +225,22 @@ static void update_amendment(struct snippet_print_ctx *ctx)
|
|||||||
{
|
{
|
||||||
if (ctx->ctx_amendment
|
if (ctx->ctx_amendment
|
||||||
&& amendment_contains_cell(
|
&& amendment_contains_cell(
|
||||||
ctx->ctx_amendment, ctx->ctx_row, ctx->ctx_col)) {
|
ctx->ctx_amendment, ctx->ctx_row,
|
||||||
|
ctx->ctx_col + ctx->ctx_indent_offset)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->ctx_amendment
|
ctx->ctx_amendment = find_amendment(
|
||||||
= find_amendment(ctx->ctx_snippet, ctx->ctx_row, ctx->ctx_col);
|
ctx->ctx_snippet, ctx->ctx_row,
|
||||||
|
ctx->ctx_col + ctx->ctx_indent_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_highlighting(struct snippet_print_ctx *ctx)
|
static void update_highlighting(struct snippet_print_ctx *ctx)
|
||||||
{
|
{
|
||||||
if (ctx->ctx_hl
|
if (ctx->ctx_hl
|
||||||
&& highlight_contains_cell(ctx->ctx_hl, ctx->ctx_row, ctx->ctx_col)) {
|
&& highlight_contains_cell(
|
||||||
|
ctx->ctx_hl, ctx->ctx_row,
|
||||||
|
ctx->ctx_col + ctx->ctx_indent_offset)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,8 +248,9 @@ static void update_highlighting(struct snippet_print_ctx *ctx)
|
|||||||
|
|
||||||
STREAM_COLOUR_RESET(ctx->ctx_stream);
|
STREAM_COLOUR_RESET(ctx->ctx_stream);
|
||||||
|
|
||||||
const struct mie_diag_highlight *new_hl
|
const struct mie_diag_highlight *new_hl = find_highlight(
|
||||||
= find_highlight(ctx->ctx_snippet, ctx->ctx_row, ctx->ctx_col);
|
ctx->ctx_snippet, ctx->ctx_row,
|
||||||
|
ctx->ctx_col + ctx->ctx_indent_offset);
|
||||||
|
|
||||||
if (!new_hl) {
|
if (!new_hl) {
|
||||||
return;
|
return;
|
||||||
@@ -299,7 +305,8 @@ static int get_char_amendment(struct snippet_print_ctx *ctx)
|
|||||||
|
|
||||||
switch (a->a_type) {
|
switch (a->a_type) {
|
||||||
case MIE_DIAG_AMENDMENT_ADD:
|
case MIE_DIAG_AMENDMENT_ADD:
|
||||||
i = ctx->ctx_col - a->a_add.a_loc.c_row;
|
i = ctx->ctx_col - ctx->ctx_indent_offset - a->a_add.a_loc.c_row
|
||||||
|
- 1;
|
||||||
return a->a_add.a_str[i];
|
return a->a_add.a_str[i];
|
||||||
case MIE_DIAG_AMENDMENT_REMOVE:
|
case MIE_DIAG_AMENDMENT_REMOVE:
|
||||||
b_iterator_move_next(ctx->ctx_linebuf_ptr);
|
b_iterator_move_next(ctx->ctx_linebuf_ptr);
|
||||||
@@ -334,13 +341,24 @@ static int get_char(struct snippet_print_ctx *ctx)
|
|||||||
return get_char_amendment(ctx);
|
return get_char_amendment(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
b_wchar c = b_iterator_get_cvalue(ctx->ctx_linebuf_ptr).v_int;
|
b_wchar c = B_WCHAR_INVALID;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
c = b_iterator_get_cvalue(ctx->ctx_linebuf_ptr).v_int;
|
||||||
if (c == B_WCHAR_INVALID) {
|
if (c == B_WCHAR_INVALID) {
|
||||||
return GET_CHAR_STOP;
|
return GET_CHAR_STOP;
|
||||||
};
|
}
|
||||||
|
|
||||||
b_iterator_move_next(ctx->ctx_linebuf_ptr);
|
b_iterator_move_next(ctx->ctx_linebuf_ptr);
|
||||||
|
|
||||||
|
if (isspace(c) && !ctx->ctx_in_content) {
|
||||||
|
ctx->ctx_indent_offset++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->ctx_in_content = true;
|
||||||
return c;
|
return c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_underline(struct snippet_print_ctx *ctx)
|
static void update_underline(struct snippet_print_ctx *ctx)
|
||||||
@@ -414,6 +432,10 @@ static void print_snippet(
|
|||||||
|
|
||||||
update_highlighting(&printer);
|
update_highlighting(&printer);
|
||||||
|
|
||||||
|
if (c == '[') {
|
||||||
|
b_tty_putc(stream, 0, c);
|
||||||
|
}
|
||||||
|
|
||||||
b_tty_putc(stream, 0, c);
|
b_tty_putc(stream, 0, c);
|
||||||
|
|
||||||
update_underline(&printer);
|
update_underline(&printer);
|
||||||
|
|||||||
Reference in New Issue
Block a user