From 348e64ec976ae63ee88b13f52e706fb90a2ebb30 Mon Sep 17 00:00:00 2001 From: dsh Date: Sat, 7 Nov 2026 11:20:11 +0800 Subject: [PATCH] Centre the caret inside the cell it points at --- src/rot8_viz.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rot8_viz.c b/src/rot8_viz.c index b04e6b0..3505906 100644 --- a/src/rot8_viz.c +++ b/src/rot8_viz.c @@ -494,22 +494,22 @@ static void viz_grid(rot8_viz *viz, rot8_iter *iter, FILE *out, bool color) { /* A caret under the tape pointer, for terminals without colour. One * field is digits + 1 characters wide, exactly like a hex cell, or the - * caret walks left of its cell as the columns add up. */ + * caret walks left of its cell as the columns add up. The mark sits in + * the middle of the digits: two carets for an even digit count, one for + * an odd one, so it stays centred instead of leaning to one side. */ if (ptr >= 0 && (size_t)ptr / (size_t)cols == first_row + row) { line_open(&ln, viz, out, color); snprintf(label, sizeof label, "%*s| ", addr + 3, ""); line_put(&ln, label); for (col = 0; col < cols; col++) { bool here = (size_t)ptr == base + (size_t)col; - const char *mark = ""; + const char *mark = digits % 2 == 0 ? "^^" : "^"; char field[16]; - int pad; + int pad = digits; if (here) { - mark = digits > 1 ? "^^" : "^"; - } - pad = digits - (int)strlen(mark); - if (pad < 0) { - pad = 0; + pad = (digits - (int)strlen(mark)) / 2; + } else { + mark = ""; } snprintf(field, sizeof field, "%*s%s ", pad, "", mark); line_style(&ln, field, here ? ANSI_PTR : NULL);