mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Some small menu updates
@ 2013-06-19 20:53 Sascha Hauer
  2013-06-19 20:53 ` [PATCH 1/3] menu: Align entries Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2013-06-19 20:53 UTC (permalink / raw)
  To: barebox


Some minor fixes to the menu code.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      menu: Align entries
      Fix gotoXY argument order
      menu: Make action callback optional

 common/menu.c     | 15 ++++++++-------
 include/readkey.h |  2 +-
 2 files changed, 9 insertions(+), 8 deletions(-)


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

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

* [PATCH 1/3] menu: Align entries
  2013-06-19 20:53 Some small menu updates Sascha Hauer
@ 2013-06-19 20:53 ` Sascha Hauer
  2013-06-19 20:53 ` [PATCH 2/3] Fix gotoXY argument order Sascha Hauer
  2013-06-19 20:53 ` [PATCH 3/3] menu: Make action callback optional Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2013-06-19 20:53 UTC (permalink / raw)
  To: barebox

More than 9 menu entries in are single menu are not aligned anymore, like
this:

8 entry8
9 entry9
10 entry10

Use %2d in the printf format specifier to align more than 9 entries.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/menu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/menu.c b/common/menu.c
index a672e59..1f0ffec 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -175,7 +175,7 @@ static void print_menu_entry(struct menu *m, struct menu_entry *me,
 		puts("   ");
 	}
 
-	printf(" %d: ", me->num);
+	printf(" %2d: ", me->num);
 	if (selected)
 		puts("\e[7m");
 
-- 
1.8.3.1


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

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

* [PATCH 2/3] Fix gotoXY argument order
  2013-06-19 20:53 Some small menu updates Sascha Hauer
  2013-06-19 20:53 ` [PATCH 1/3] menu: Align entries Sascha Hauer
@ 2013-06-19 20:53 ` Sascha Hauer
  2013-06-19 20:53 ` [PATCH 3/3] menu: Make action callback optional Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2013-06-19 20:53 UTC (permalink / raw)
  To: barebox

gotoXY has the argument order (y, x). Change this so that usage of this
function feels more natural.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/menu.c     | 10 +++++-----
 include/readkey.h |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/common/menu.c b/common/menu.c
index 1f0ffec..d516db4 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -164,7 +164,7 @@ static void __print_entry(const char *str)
 static void print_menu_entry(struct menu *m, struct menu_entry *me,
 			     int selected)
 {
-	gotoXY(me->num + 1, 3);
+	gotoXY(3, me->num + 1);
 
 	if (me->type == MENU_ENTRY_BOX) {
 		if (me->box_state)
@@ -234,7 +234,7 @@ static void print_menu(struct menu *m)
 	struct menu_entry *me;
 
 	clear();
-	gotoXY(1, 2);
+	gotoXY(2, 1);
 	if(m->display) {
 		__print_entry(m->display);
 	} else {
@@ -269,7 +269,7 @@ int menu_show(struct menu *m)
 
 	countdown = m->auto_select;
 	if (m->auto_select >= 0) {
-		gotoXY(m->nb_entries + 2, 3);
+		gotoXY(3, m->nb_entries + 2);
 		if (!m->auto_display) {
 			printf("Auto Select in");
 		} else {
@@ -293,10 +293,10 @@ int menu_show(struct menu *m)
 		}
 	}
 
-	gotoXY(m->nb_entries + 2, 3);
+	gotoXY(3, m->nb_entries + 2);
 	printf("%*c", auto_display_len + 4, ' ');
 
-	gotoXY(m->selected->num + 1, 3);
+	gotoXY(3, m->selected->num + 1);
 
 	do {
 		struct menu_entry *old_selected = m->selected;
diff --git a/include/readkey.h b/include/readkey.h
index f134846..2793f3f 100644
--- a/include/readkey.h
+++ b/include/readkey.h
@@ -28,7 +28,7 @@
 
 #define printf_reverse(fmt,args...)	printf("\e[7m" fmt "\e[m",##args)
 #define puts_reverse(fmt)		puts("\e[7m" fmt "\e[m")
-#define gotoXY(row, col)		printf("\e[%d;%dH", row, col)
+#define gotoXY(row, col)		printf("\e[%d;%dH", col, row)
 #define clear()				puts("\e[2J")
 
 int read_key(void);
-- 
1.8.3.1


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

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

* [PATCH 3/3] menu: Make action callback optional
  2013-06-19 20:53 Some small menu updates Sascha Hauer
  2013-06-19 20:53 ` [PATCH 1/3] menu: Align entries Sascha Hauer
  2013-06-19 20:53 ` [PATCH 2/3] Fix gotoXY argument order Sascha Hauer
@ 2013-06-19 20:53 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2013-06-19 20:53 UTC (permalink / raw)
  To: barebox

Someone calling menu_show might only be interested in the entry the user
selected without having something in the action callback. Make it optional.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/menu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/menu.c b/common/menu.c
index d516db4..ef56190 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -361,7 +361,8 @@ int menu_show(struct menu *m)
 				break;
 			clear();
 			gotoXY(1,1);
-			m->selected->action(m, m->selected);
+			if (m->selected->action)
+				m->selected->action(m, m->selected);
 			if (m->selected->non_re_ent)
 				return m->selected->num;
 			else
-- 
1.8.3.1


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

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

end of thread, other threads:[~2013-06-19 20:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-19 20:53 Some small menu updates Sascha Hauer
2013-06-19 20:53 ` [PATCH 1/3] menu: Align entries Sascha Hauer
2013-06-19 20:53 ` [PATCH 2/3] Fix gotoXY argument order Sascha Hauer
2013-06-19 20:53 ` [PATCH 3/3] menu: Make action callback optional Sascha Hauer

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