summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-08-20 10:22:47 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-08-30 20:57:20 +0200
commitb712b26632d4af1e1c9454a3b330ed7b401e165b (patch)
treedecefbfa56cfc958731d7455cf0aab6605e5d5e4 /include
parent0db2f6367712cafd91460af7816f1180fa1b5446 (diff)
downloadbarebox-b712b26632d4af1e1c9454a3b330ed7b401e165b.tar.gz
barebox-b712b26632d4af1e1c9454a3b330ed7b401e165b.tar.xz
Add Menu Framework
Introduce a menu framework that allow us to create list menu to simplify barebox and make it more user-frendly This kind of menu is very usefull when you do not have a keyboard or a serial console attached to your board to allow you to interract with barebox For the develloper part, The framework introduce two API 1) C that allow you to create menu, submenu, entry and complex menu action 2) Command that allow you as the C API to create menu, submenu, entry and complex menu action but this time the actions will be store in a function and then be evaluated and excecuted at runtime. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/menu.h87
-rw-r--r--include/readkey.h5
2 files changed, 92 insertions, 0 deletions
diff --git a/include/menu.h b/include/menu.h
new file mode 100644
index 0000000000..29f18f206a
--- /dev/null
+++ b/include/menu.h
@@ -0,0 +1,87 @@
+/*
+ * (C) Copyright 2009-2010 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of
+ * the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __MENU_H__
+#define __MENU_H__
+
+#include <linux/list.h>
+#include <malloc.h>
+
+struct menu;
+
+struct menu_entry {
+ int num;
+ char *display;
+ void (*action)(struct menu *m, struct menu_entry *me);
+ int non_re_ent;
+
+ struct list_head list;
+ void *priv;
+};
+
+struct menu {
+ char *name;
+ char *display;
+
+ struct list_head list;
+ struct menu_entry entries;
+ int nb_entries;
+ int width;
+ struct menu_entry *selected;
+ void *priv;
+};
+
+/*
+ * menu functions
+ */
+static inline struct menu* menu_alloc(void)
+{
+ return calloc(1, sizeof(struct menu));
+}
+void menu_free(struct menu *m);
+int menu_add(struct menu* m);
+void menu_remove(struct menu *m);
+struct menu* menu_get_by_name(char *name);
+int menu_show(struct menu *m);
+int menu_set_selected_entry(struct menu *m, struct menu_entry* me);
+int menu_set_selected(struct menu *m, int num);
+struct menu* menu_get_menus(void);
+
+/*
+ * menu entry functions
+ */
+static inline struct menu_entry* menu_entry_alloc(void)
+{
+ return calloc(1, sizeof(struct menu_entry));
+}
+void menu_entry_free(struct menu_entry *me);
+int menu_add_entry(struct menu *m, struct menu_entry* me);
+void menu_remove_entry(struct menu *m, struct menu_entry *me);
+struct menu_entry* menu_entry_get_by_num(struct menu* m, int num);
+
+/*
+ * menu entry action functions
+ */
+void menu_action_run(struct menu *m, struct menu_entry *me);
+void menu_action_exit(struct menu *m, struct menu_entry *me);
+
+#endif /* __MENU_H__ */
diff --git a/include/readkey.h b/include/readkey.h
index 919af6421b..aabb835e89 100644
--- a/include/readkey.h
+++ b/include/readkey.h
@@ -22,6 +22,11 @@
#define ANSI_CLEAR_SCREEN "\e[2J\e[;H"
+#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 clear() puts("\e[2J")
+
int read_key(void);
#endif /* READKEY_H */