summaryrefslogtreecommitdiff
path: root/tprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'tprintf.c')
-rw-r--r--tprintf.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/tprintf.c b/tprintf.c
index 0ca2375..43f862a 100644
--- a/tprintf.c
+++ b/tprintf.c
@@ -66,6 +66,7 @@ static void __tprintf_flush(void)
size_t i;
static ssize_t line_count = 0;
ssize_t term_len = term_curr_size;
+ size_t color_open = 0;
for (i = 0; i < buffer_use; ++i) {
if (buffer[i] == '\n') {
@@ -73,7 +74,13 @@ static void __tprintf_flush(void)
line_count = -1;
}
- if (line_count == term_len) {
+ /* Start of an color escape sequence? */
+ if (buffer[i] == 033) {
+ if ((i + 1) < buffer_use && buffer[i + 1] == '[')
+ color_open++;
+ }
+
+ if (color_open == 0 && line_count >= term_len) {
__tprintf_flush_newline();
line_count = term_starting_size;
@@ -82,6 +89,10 @@ static void __tprintf_flush(void)
i++;
}
+ /* End of the color escape sequence? */
+ if (color_open > 0 && buffer[i] == 'm')
+ color_open--;
+
fputc(buffer[i], stdout);
line_count++;
}