2 * This file is part of the bayou project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <libpayload.h>
27 static int menu_width = 0;
28 static struct payload *mpayloads[BAYOU_MAX_ENTRIES];
29 static int m_entries = 0;
30 static unsigned int selected = 0;
31 static WINDOW *menuwin, *status;
33 void create_menu(void)
37 for (i = 0; i < bayoucfg.n_entries; i++) {
38 struct payload *p = &(bayoucfg.entries[i]);
41 if ((p->pentry.parent != 0) ||
42 (p->pentry.flags & BPT_FLAG_NOSHOW))
45 mpayloads[m_entries++] = p;
47 name = payload_get_name(p);
49 if (strlen(name) > menu_width)
50 menu_width = strlen(name);
58 menuwin = newwin(m_entries + 3, menu_width,
59 (SCREEN_Y - (m_entries + 3)) / 2,
60 (SCREEN_X - menu_width) / 2);
68 wattrset(menuwin, COLOR_PAIR(3));
70 wborder(menuwin, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
71 ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER);
73 wattrset(menuwin, COLOR_PAIR(4) | A_BOLD);
74 mvwprintw(menuwin, 0, (menu_width - 17) / 2, " Payload Chooser ");
76 wattrset(menuwin, COLOR_PAIR(3));
78 for (i = 0; i < m_entries; i++) {
79 char *name = payload_get_name(mpayloads[i]);
80 int col = (menu_width - (2 + strlen(name))) / 2;
83 wattrset(menuwin, COLOR_PAIR(5) | A_BOLD);
85 wattrset(menuwin, COLOR_PAIR(3));
87 mvwprintw(menuwin, 2 + i, col, name);
90 s = mpayloads[selected];
94 if (s->params[BAYOU_PARAM_DESC] != NULL) {
96 int len = strnlen(s->params[BAYOU_PARAM_DESC], 65);
98 snprintf(buf, 65, s->params[BAYOU_PARAM_DESC]);
101 mvwprintw(status, 0, (80 - len) / 2, buf);
119 selected = (selected + 1) % m_entries;
120 else if (key == KEY_UP)
121 selected = (selected - 1) % m_entries;
122 else if (key == KEY_ENTER) {
123 run_payload(mpayloads[selected]);
137 init_pair(1, COLOR_WHITE, COLOR_RED);
138 init_pair(2, COLOR_BLACK, COLOR_WHITE);
139 init_pair(3, COLOR_BLACK, COLOR_WHITE);
140 init_pair(4, COLOR_CYAN, COLOR_WHITE);
141 init_pair(5, COLOR_WHITE, COLOR_RED);
143 wattrset(stdscr, COLOR_PAIR(1));
146 status = newwin(1, 80, 24, 0);
147 wattrset(status, COLOR_PAIR(2));