Handle displaying control characters better

This commit is contained in:
Timothy Warren 2019-08-21 08:45:19 -04:00
parent f5ba357eac
commit 1c0db7e5da
1 changed files with 16 additions and 1 deletions

17
kilo.c
View File

@ -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)
{