mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] menu: fix double action when "\n\r" or "\r\n" is received
@ 2012-04-07  3:00 Jean-Christophe PLAGNIOL-VILLARD
  2012-04-07  3:00 ` [PATCH 2/2] menu: add color fancy support Jean-Christophe PLAGNIOL-VILLARD
  2012-04-10  8:00 ` [PATCH 1/2] menu: fix double action when "\n\r" or "\r\n" is received Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-07  3:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/menu.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/common/menu.c b/common/menu.c
index fd21e52..e85a320 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -296,7 +296,7 @@ int menu_show(struct menu *m)
 
 	do {
 		if (m->auto_select >= 0)
-			ch = KEY_ENTER;
+			ch = KEY_RETURN;
 		else
 			ch = getc();
 
@@ -339,7 +339,6 @@ int menu_show(struct menu *m)
 				m->selected->action(m, m->selected);
 			print_menu_entry(m, m->selected, 1);
 			break;
-		case KEY_ENTER:
 		case KEY_RETURN:
 			clear();
 			gotoXY(1,1);
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] menu: add color fancy support
  2012-04-07  3:00 [PATCH 1/2] menu: fix double action when "\n\r" or "\r\n" is received Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-07  3:00 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-10  8:00 ` [PATCH 1/2] menu: fix double action when "\n\r" or "\r\n" is received Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-07  3:00 UTC (permalink / raw)
  To: barebox

You can now use AINSI color in the display of the menu or menu_entry.
As the length of the string is not any more the same as the display simplify
the invertion display managemnent.

We just now invert the fontground and backgound on the string itself as done
in Kconfig.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/menu.c  |   50 +++++++++++++++++++++++++++++++++++++++++++++-----
 include/menu.h |    3 +++
 2 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/common/menu.c b/common/menu.c
index e85a320..50af36e 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -31,6 +31,7 @@
 #include <readkey.h>
 #include <clock.h>
 #include <linux/err.h>
+#include <libbb.h>
 
 static LIST_HEAD(menus);
 
@@ -52,6 +53,7 @@ void menu_free(struct menu *m)
 	free(m->name);
 	free(m->display);
 	free(m->auto_display);
+	free(m->display_buffer);
 
 	list_for_each_entry_safe(me, tmp, &m->entries, list)
 		menu_entry_free(me);
@@ -162,8 +164,6 @@ static void print_menu_entry(struct menu *m, struct menu_entry *me,
 			     int selected)
 {
 	gotoXY(me->num + 1, 3);
-	if (selected)
-		printf("\e[7m");
 
 	if (me->type == MENU_ENTRY_BOX) {
 		if (me->box_state)
@@ -174,10 +174,15 @@ static void print_menu_entry(struct menu *m, struct menu_entry *me,
 		puts("   ");
 	}
 
-	printf(" %d: %-*s", me->num, m->width, me->display);
+	process_escape_sequence(me->display, m->display_buffer,
+				m->display_buffer_size);
+	printf(" %d: ", me->num);
+	if (selected)
+		puts("\e[7m");
+	puts(m->display_buffer);
 
 	if (selected)
-		printf("\e[m");
+		puts("\e[m");
 }
 
 int menu_set_selected_entry(struct menu *m, struct menu_entry* me)
@@ -231,7 +236,9 @@ static void print_menu(struct menu *m)
 	clear();
 	gotoXY(1, 2);
 	if(m->display) {
-		puts(m->display);
+		process_escape_sequence(m->display, m->display_buffer,
+					m->display_buffer_size);
+		puts(m->display_buffer);
 	} else {
 		puts("Menu : ");
 		puts(m->name);
@@ -250,6 +257,34 @@ static void print_menu(struct menu *m)
 	print_menu_entry(m, m->selected, 1);
 }
 
+static int menu_alloc_display_buffer(struct menu *m)
+{
+	int min_size;
+
+	if (m->display)
+		min_size = max((int)strlen(m->display), m->width);
+	else
+		min_size = m->width;
+
+
+	if (m->display_buffer) {
+		if (m->display_buffer_size >= min_size)
+			return 0;
+		m->display_buffer = realloc(m->display_buffer, min_size * sizeof(char));
+	} else {
+		m->display_buffer = calloc(min_size, sizeof(char));
+	}
+
+	if (!m->display_buffer) {
+		perror("display_buffer");
+		return -ENOMEM;
+	}
+
+	m->display_buffer_size = min_size;
+
+	return 0;
+}
+
 int menu_show(struct menu *m)
 {
 	int ch;
@@ -257,10 +292,15 @@ int menu_show(struct menu *m)
 	int countdown;
 	int auto_display_len = 16;
 	uint64_t start, second;
+	int ret;
 
 	if(!m || list_empty(&m->entries))
 		return -EINVAL;
 
+	ret = menu_alloc_display_buffer(m);
+	if (ret)
+		return ret;
+
 	print_menu(m);
 
 	countdown = m->auto_select;
diff --git a/include/menu.h b/include/menu.h
index 6e7b555..136fe61 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -61,6 +61,9 @@ struct menu {
 
 	int nb_entries;
 	int width;
+	char *display_buffer;
+	int display_buffer_size;
+
 	struct menu_entry *selected;
 	void *priv;
 };
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] menu: fix double action when "\n\r" or "\r\n" is received
  2012-04-07  3:00 [PATCH 1/2] menu: fix double action when "\n\r" or "\r\n" is received Jean-Christophe PLAGNIOL-VILLARD
  2012-04-07  3:00 ` [PATCH 2/2] menu: add color fancy support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-10  8:00 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2012-04-10  8:00 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Sat, Apr 07, 2012 at 05:00:14AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Applied, thanks

Sascha

> ---
>  common/menu.c |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
> 
> diff --git a/common/menu.c b/common/menu.c
> index fd21e52..e85a320 100644
> --- a/common/menu.c
> +++ b/common/menu.c
> @@ -296,7 +296,7 @@ int menu_show(struct menu *m)
>  
>  	do {
>  		if (m->auto_select >= 0)
> -			ch = KEY_ENTER;
> +			ch = KEY_RETURN;
>  		else
>  			ch = getc();
>  
> @@ -339,7 +339,6 @@ int menu_show(struct menu *m)
>  				m->selected->action(m, m->selected);
>  			print_menu_entry(m, m->selected, 1);
>  			break;
> -		case KEY_ENTER:
>  		case KEY_RETURN:
>  			clear();
>  			gotoXY(1,1);
> -- 
> 1.7.9.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-10  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-07  3:00 [PATCH 1/2] menu: fix double action when "\n\r" or "\r\n" is received Jean-Christophe PLAGNIOL-VILLARD
2012-04-07  3:00 ` [PATCH 2/2] menu: add color fancy support Jean-Christophe PLAGNIOL-VILLARD
2012-04-10  8:00 ` [PATCH 1/2] menu: fix double action when "\n\r" or "\r\n" is received Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox