drivers/cfb_console.c: added processing of ANSI escape sequences \e[2J, \e[m, \e[7m, and \e[row;colH drivers/cfb_console.c (video_putc): make \r return to the beginning of the line - Werner Almesberger Index: u-boot/drivers/video/cfb_console.c =================================================================== --- u-boot.orig/drivers/video/cfb_console.c +++ u-boot/drivers/video/cfb_console.c @@ -185,6 +185,7 @@ #include #include +#include #include #include @@ -691,10 +692,95 @@ /*****************************************************************************/ + +static enum { + CS_NORMAL = 0, + CS_ESC, + CS_NUM1, + CS_NUM2, +} state = 0; + +static int num1, num2; + + +static void swap_drawing_colors(void) +{ + eorx = fgx; + fgx = bgx; + bgx = eorx; + eorx = fgx ^ bgx; +} + + +static void process_sequence(char c) +{ + static int inverted = 0; + int inv; + + switch (c) { + case 'J': + /* assume num1 == 2 */ + memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE >> 2, + CONSOLE_BG_COL); + break; + case 'H': + if (num1 > CONSOLE_ROWS || num2 > CONSOLE_COLS) + break; + console_col = num2 ? num2-1 : 0; + console_row = num1 ? num1-1 : 0; + break; + case 'm': + inv = num1 == 7; + if (num1 && !inv) + break; + if (inverted != inv) + swap_drawing_colors(); + inverted = inv; + break; + } +} + + +static void escape_sequence(char c) +{ + switch (state) { + case CS_ESC: + state = c == '[' ? CS_NUM1 : CS_NORMAL; + num1 = num2 = 0; + break; + case CS_NUM1: + if (isdigit(c)) + num1 = num1*10+c-'0'; + else if (c == ';') + state = CS_NUM2; + else { + process_sequence(c); + state = CS_NORMAL; + } + break; + case CS_NUM2: + if (isdigit(c)) + num2 = num2*10+c-'0'; + else { + process_sequence(c); + state = CS_NORMAL; + } + default: + /* can't happen */; + } +} + + void video_putc (const char c) { static int nl = 1; + if (state) { + escape_sequence(c); + CURSOR_SET; + return; + } + switch (c) { case 13: /* back to first column */ console_cr (); @@ -718,6 +804,10 @@ console_back (); break; + case '\e': + state = CS_ESC; + break; + default: /* draw the char */ video_putchar (console_col * VIDEO_FONT_WIDTH, console_row * VIDEO_FONT_HEIGHT,