[U-Boot] [PATCH 05/16] common/main.c: Fix function readline

2011-12-17 Thread Pali Rohár
 * Ignore ANSI escape sequences for moving cursor, which are generated by 
keyboard

Signed-off-by: Pali Rohár 
---
 common/main.c |   49 +
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/common/main.c b/common/main.c
index e96c95a..5531130 100644
--- a/common/main.c
+++ b/common/main.c
@@ -958,6 +958,7 @@ int readline_into_buffer (const char *const prompt, char * 
buffer)
int n = 0;  /* buffer index */
int plen = 0;   /* prompt length*/
int col;/* output column cnt*/
+   int esc = 0;/* ansi escape char */
charc;
 
/* print prompt */
@@ -1024,7 +1025,55 @@ int readline_into_buffer (const char *const prompt, char 
* buffer)
p=delete_char(p_buf, p, &col, &n, plen);
continue;
 
+   case '\e':  /* ANSI escape char 
*/
+   esc = 1;
+   continue;
+
default:
+
+   /*
+* Check for ANSI escape chars
+*/
+   if (esc == 0 && c == '\e') {
+   esc = 1;
+   continue;
+   } else if (esc == 1) {
+   if (c == '[') {
+   esc = 2;
+   continue;
+   }
+   if (n < CONFIG_SYS_CBSIZE-2) {
+   ++n;
+   *p++ = '\e';
+   putc('\e');
+   }
+   esc = 0;
+   } else if (esc == 2 || esc == 3) {
+   if (esc == 2 && c == '1') {
+   esc = 3;
+   continue;
+   }
+   /* Ignore ANSI escape sequences generated by 
keyboard */
+   /* \e [ 1 A-D and \e [ A-D */
+   if ( c >= 'A' && c <= 'D' ) {
+   esc = 0;
+   continue;
+   }
+   if (esc == 2 && n < CONFIG_SYS_CBSIZE-3) {
+   n += 2;
+   *p++ = '\e';
+   *p++ = '[';
+   puts("\e[");
+   } else if (esc == 3 && n < CONFIG_SYS_CBSIZE-4) 
{
+   n += 3;
+   *p++ = '\e';
+   *p++ = '[';
+   *p++ = '1';
+   puts("\e[1");
+   }
+   esc = 0;
+   }
+
/*
 * Must be a normal character then
 */
-- 
1.7.5.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 05/16] common/main.c: Fix function readline

2011-12-18 Thread Mike Frysinger
On Saturday 17 December 2011 12:03:07 Pali Rohár wrote:
>  * Ignore ANSI escape sequences for moving cursor, which are generated by
> keyboard

you need to line wrap your changelogs
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 05/16] common/main.c: Fix function readline

2011-12-18 Thread Pali Rohár
On Sunday 18 December 2011 13:58:30 Mike Frysinger wrote:
> On Saturday 17 December 2011 12:03:07 Pali Rohár wrote:
> >  * Ignore ANSI escape sequences for moving cursor, which are generated
> >  by
> >
> > keyboard
>
> you need to line wrap your changelogs
> -mike

I will fix all commit messages.

--
Pali Rohár
pali.ro...@gmail.com

signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot