[U-Boot] [PATCH 2/2] lcd: add ANSI escape support
Wolfgang Denk
wd at denx.de
Sun Jul 5 00:23:40 CEST 2009
Dear Jean-Christophe PLAGNIOL-VILLARD,
In message <1245613942-10693-2-git-send-email-plagnioj at jcrosoft.com> you wrote:
> to use the new menu framework, clear and advance echo we need to add
> the following escape ansi support \e[%dJ, \e[m, \e[%dm, and \e[%d;%dH
>
> Tested on at91sam9263ek
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
> ---
> common/lcd.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 71 insertions(+), 0 deletions(-)
>
> diff --git a/common/lcd.c b/common/lcd.c
> index b5e81f1..dbad380 100644
> --- a/common/lcd.c
> +++ b/common/lcd.c
> @@ -34,6 +34,7 @@
> #include <command.h>
> #include <stdarg.h>
> #include <linux/types.h>
> +#include <linux/ctype.h>
> #include <devices.h>
> #if defined(CONFIG_POST)
> #include <post.h>
> @@ -172,6 +173,23 @@ static inline void console_newline (void)
>
> /*----------------------------------------------------------------------*/
>
> +static void invert_fg_bg_color(void)
> +{
> + int tmp;
> +
> + tmp = lcd_color_fg;
> + lcd_color_fg = lcd_color_bg;
> + lcd_color_bg = tmp;
> +}
> +
> +struct ansi_parsing_state {
> + int inprogress;
> + /* is FG/BG inverted */
> + int inverted;
> + int *pos;
> + int val[2];
> +} state;
Please make this configurable, so we don't have to add this for all
systems that don't need it.
> void lcd_putc (const char c)
> {
> if (!lcd_is_enabled) {
> @@ -179,6 +197,55 @@ void lcd_putc (const char c)
> return;
> }
>
> + if (state.inprogress) {
> + switch (c) {
> + case '[': state.val[0] = state.val[1] = 0;
> + state.pos = state.val;
> + return;
> + case ';':
> + state.pos++;
> + return;
> + case 'H':
> + state.inprogress = 0;
> + if (state.val[0] > CONSOLE_ROWS ||
> + state.val[1] > CONSOLE_COLS) {
> + return;
> + }
> +
> + if (state.val[0])
> + console_row = state.val[0] - 1;
> + else
> + console_row = 0;
Empty line here, please.
> + if (state.val[1])
> + console_col = state.val[1] - 1;
> + else
> + console_col = 0;
> + return;
> + case 'J':
> + if (state.val[0] == 2)
> + lcd_clear(0);
> + state.inprogress = 0;
> + return;
> + case 'm':
> + if ((state.val[0] == 7) ||
> + (state.val[0] == 0 && state.inverted)) {
> + invert_fg_bg_color();
> + state.inverted = (state.val[0] == 7);
> + }
> + state.inprogress = 0;
> + return;
> + default:
> + if(!isdigit(c)) {
Please don't use negative logic - use "if (isdigit(c))" and swap the
branches. And mind the space after "if", please.
Thanks.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Ever try. Ever fail. No matter. Try again. Fail again. Fail better.
-- S. Beckett
More information about the U-Boot
mailing list