diff --git a/src/rot8_viz.c b/src/rot8_viz.c index 8bd4ffc..07472ba 100644 --- a/src/rot8_viz.c +++ b/src/rot8_viz.c @@ -42,6 +42,7 @@ #define ANSI_BIT_OFF "\x1b[90m" #define ANSI_OUT "\x1b[36m" #define ANSI_IN "\x1b[33m" +#define ANSI_EOL "\x1b[K" /* erase to end of line */ #define ANSI_CLEAR "\x1b[2J\x1b[H" #define ANSI_HOME "\x1b[H" @@ -460,6 +461,15 @@ static void viz_inputs(rot8_viz *viz, FILE *out, bool color) { * produced, then either the prompt it is waiting on or the value it was just * given. The cursor is left right after "input> " so the number is typed * outside the window instead of in the middle of it. */ +/* console lines are not padded, so each one has to wipe the rest of its line: + * a shorter line would otherwise leave the tail of a longer one behind and the + * two read as a single garbled row */ +static void console_eol(rot8_viz *viz, FILE *out) { + if (viz->tty) { + fputs(ANSI_EOL, out); + } +} + static void viz_console(rot8_viz *viz, FILE *out, bool color) { size_t first, i; @@ -479,6 +489,7 @@ static void viz_console(rot8_viz *viz, FILE *out, bool color) { if (color) { fputs(ANSI_RESET, out); } + console_eol(viz, out); } for (i = first; i < viz->event_count; i++) { const struct viz_event *ev = &viz->events[i]; @@ -491,6 +502,7 @@ static void viz_console(rot8_viz *viz, FILE *out, bool color) { if (color) { fputs(ANSI_RESET, out); } + console_eol(viz, out); } if (viz->input_pending) { line_start(viz, out); @@ -501,6 +513,7 @@ static void viz_console(rot8_viz *viz, FILE *out, bool color) { if (color) { fputs(ANSI_RESET, out); } + console_eol(viz, out); } }