From 1c0db7e5da3dc0398820405b8646577adefb41e3 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 21 Aug 2019 08:45:19 -0400 Subject: [PATCH] Handle displaying control characters better --- kilo.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kilo.c b/kilo.c index 7bf97ff..fdfca31 100644 --- a/kilo.c +++ b/kilo.c @@ -997,7 +997,22 @@ void editorDrawRows(struct abuf *ab) int j; for (j = 0; j < len; j++) { - if (hl[j] == HL_NORMAL) + // Make control characters "readable" + if (iscntrl(c[j])) + { + char sym = (c[j] <= 26) ? '@' + c[j] : '?'; + abAppend(ab, "\x1b[7m", 4); + abAppend(ab, &sym, 1); + abAppend(ab, "\x1b[m", 3); + // Restore the previous highlighting color + if (current_color != -1) + { + char buf[16]; + int clen = snprintf(buf, sizeof(buf), "\x1b[%dm", current_color); + abAppend(ab, buf, clen); + } + } + else if (hl[j] == HL_NORMAL) { if (current_color != -1) {