1
/* $Id: main_console.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
static pj_bool_t console_quit;
26
enum gui_key gui_msgbox(const char *title, const char *message, enum gui_flag flag)
34
if (flag == WITH_YESNO)
35
printf("%c:Yes %c:No ", KEY_YES, KEY_NO);
36
else if (flag == WITH_OK)
37
printf("%c:OK ", KEY_OK);
38
else if (flag == WITH_OKCANCEL)
39
printf("%c:OK %c:Cancel ", KEY_OK, KEY_CANCEL);
42
ret = fgets(input, sizeof(input), stdin);
46
if (input[0]==KEY_NO || input[0]==KEY_YES || input[0]==KEY_CANCEL)
47
return (enum gui_key)input[0];
51
pj_status_t gui_init(gui_menu *menu)
57
static void print_menu(const char *indent, char *menu_id, gui_menu *menu)
59
char child_indent[16];
62
pj_ansi_snprintf(child_indent, sizeof(child_indent), "%s ", indent);
64
printf("%s%s: %s\n", indent, menu_id, menu->title);
66
for (i=0; i<menu->submenu_cnt; ++i) {
69
pj_ansi_sprintf(child_id, "%s%u", menu_id, i);
71
if (!menu->submenus[i])
74
print_menu(child_indent, child_id, menu->submenus[i]);
78
pj_status_t gui_start(gui_menu *menu)
80
while (!console_quit) {
87
for (i=0; i<menu->submenu_cnt; ++i) {
89
pj_ansi_sprintf(menu_id, "%u", i);
90
print_menu("", menu_id, menu->submenus[i]);
93
printf("Enter the menu number: ");
95
if (!fgets(input, sizeof(input), stdin))
100
while (*p && *p!='\r' && *p!='\n') {
101
unsigned d = (*p - '0');
102
if (d < 0 || d >= choice->submenu_cnt) {
103
puts("Invalid selection");
108
choice = choice->submenus[d];
112
if (choice && *p!='\r' && *p!='\n') {
113
puts("Invalid characters entered");
117
if (choice && choice->handler)
118
(*choice->handler)();
124
void gui_destroy(void)
126
console_quit = PJ_TRUE;
129
void gui_sleep(unsigned sec)
131
pj_thread_sleep(sec * 1000);
136
if (systest_init() != PJ_SUCCESS)