summaryrefslogtreecommitdiff
path: root/payloads/bayou/menu.c
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2008-11-02 17:01:06 +0000
committerUwe Hermann <uwe@hermann-uwe.de>2008-11-02 17:01:06 +0000
commit7eb845e815924984b301aaf674b090cde28c1c6a (patch)
treed85a1080fd20b0ad8e1859d012fe90ba9cdf1cd9 /payloads/bayou/menu.c
parent91df5619dbb7d2064f9947f2fbc56477f7b707c3 (diff)
downloadcoreboot-7eb845e815924984b301aaf674b090cde28c1c6a.tar.xz
Import a slightly modified Bayou version into svn. This is based
on the last snapshot posted by Jordan Crouse. This commit is long overdue. Changes by me include: - Rename 'utils' to 'util' for consistency with our other projects. - Move the main code out of src/* into the top-level directory. - Add missing license headers to the following files: Makefile, pbuilder/liblar/Makefile, util/pbuilder/Makefile. - Dropped the util/pbuilder/lzma completely. I'm working on reusing the lzma/ dir from v3 via svn:externals. Alas, this also means that Bayou won't yet compile out of the box. - Coding-style and white-space fixes (indent) for all files. Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3719 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads/bayou/menu.c')
-rw-r--r--payloads/bayou/menu.c155
1 files changed, 155 insertions, 0 deletions
diff --git a/payloads/bayou/menu.c b/payloads/bayou/menu.c
new file mode 100644
index 0000000000..97f6c14d7d
--- /dev/null
+++ b/payloads/bayou/menu.c
@@ -0,0 +1,155 @@
+/*
+ * This file is part of the bayou project.
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <libpayload.h>
+#include <curses.h>
+#include "bayou.h"
+
+#define SCREEN_X 80
+#define SCREEN_Y 25
+
+static int menu_width = 0;
+static struct payload *mpayloads[BAYOU_MAX_ENTRIES];
+static int m_entries = 0;
+static unsigned int selected = 0;
+static WINDOW *menuwin, *status;
+
+void create_menu(void)
+{
+ int i;
+
+ for (i = 0; i < bayoucfg.n_entries; i++) {
+ struct payload *p = &(bayoucfg.entries[i]);
+ char *name;
+
+ if ((p->pentry.parent != 0) ||
+ (p->pentry.flags & BPT_FLAG_NOSHOW))
+ continue;
+
+ mpayloads[m_entries++] = p;
+
+ name = payload_get_name(p);
+
+ if (strlen(name) > menu_width)
+ menu_width = strlen(name);
+ }
+
+ menu_width += 4;
+
+ if (menu_width < 30)
+ menu_width = 30;
+
+ menuwin = newwin(m_entries + 3, menu_width,
+ (SCREEN_Y - (m_entries + 3)) / 2,
+ (SCREEN_X - menu_width) / 2);
+}
+
+void draw_menu(void)
+{
+ struct payload *s;
+ int i;
+
+ wattrset(menuwin, COLOR_PAIR(3));
+ wclear(menuwin);
+ wborder(menuwin, '\263', '\263', '\304', '\304', '\332',
+ '\277', '\300', '\331');
+
+ wattrset(menuwin, COLOR_PAIR(4) | A_BOLD);
+ mvwprintw(menuwin, 0, (menu_width - 17) / 2, " Payload Chooser ");
+
+ wattrset(menuwin, COLOR_PAIR(3));
+
+ for (i = 0; i < m_entries; i++) {
+ char *name = payload_get_name(mpayloads[i]);
+ int col = (menu_width - (2 + strlen(name))) / 2;
+
+ if (i == selected)
+ wattrset(menuwin, COLOR_PAIR(5) | A_BOLD);
+ else
+ wattrset(menuwin, COLOR_PAIR(3));
+
+ mvwprintw(menuwin, 2 + i, col, name);
+ }
+
+ s = mpayloads[selected];
+
+ wclear(status);
+
+ if (s->params[BAYOU_PARAM_DESC] != NULL) {
+ char buf[66];
+ int len = strnlen(s->params[BAYOU_PARAM_DESC], 65);
+
+ snprintf(buf, 65, s->params[BAYOU_PARAM_DESC]);
+ buf[65] = 0;
+
+ mvwprintw(status, 0, (80 - len) / 2, buf);
+ }
+
+ wrefresh(menuwin);
+ wrefresh(status);
+}
+
+void loop(void)
+{
+ int key;
+
+ while (1) {
+ key = getch();
+
+ if (key == ERR)
+ continue;
+
+ if (key == KEY_DOWN)
+ selected = (selected + 1) % m_entries;
+ else if (key == KEY_UP)
+ selected = (selected - 1) % m_entries;
+ else if (key == KEY_ENTER) {
+ run_payload(mpayloads[selected]);
+ refresh();
+ } else
+ continue;
+
+ draw_menu();
+ }
+}
+
+void menu(void)
+{
+ initscr();
+
+ init_pair(1, COLOR_WHITE, COLOR_RED);
+ init_pair(2, COLOR_BLACK, COLOR_WHITE);
+ init_pair(3, COLOR_BLACK, COLOR_WHITE);
+ init_pair(4, COLOR_CYAN, COLOR_WHITE);
+ init_pair(5, COLOR_WHITE, COLOR_RED);
+
+ wattrset(stdscr, COLOR_PAIR(1));
+ wclear(stdscr);
+
+ status = newwin(1, 80, 24, 0);
+ wattrset(status, COLOR_PAIR(2));
+ wclear(status);
+
+ refresh();
+
+ create_menu();
+ draw_menu();
+
+ loop();
+}