/
menuwithncurses.c
125 lines (110 loc) · 3.09 KB
/
menuwithncurses.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*****************************************************************************
* Copyright (C) Ansh Bordia ansh979@gmail.com
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*Menu Page*/
#include<ncurses.h>
#include<string.h>
#include<stdlib.h>
#define MENUMAX 8
void drawmenu(int item) {
int c;
start_color();
init_pair(1,COLOR_BLUE,COLOR_BLACK); /*Blue text with black background*/
char mainmenu[] = "Main Menu";
char menu[MENUMAX][21] = {"Log in","Register","Find train","Check availaibility","Cancel ticket","Check status ac", "Check status sleeper", "Exit/Logout"};
clear();
attrset(A_BOLD);
attron(COLOR_PAIR(1)); /*Initializing the colour pair and bold attribute*/
addstr("Welcome to rail booking services");
mvaddstr(1,0,"Main Menu");
attroff(A_BOLD);
attroff(COLOR_PAIR(1)); /*End of bold and colour*/
for(c = 0; c < MENUMAX; c++) {
if( c == item )
attron(A_REVERSE);
/* highlight selection */
mvaddstr(3 + (c * 2),20,menu[c]);
attroff(A_REVERSE);
/* remove highlight */
}
mvaddstr(17,25,"Use arrow keys to move; Right arrow key to select to select:");
refresh();
}
int main() {
int key, menuitem, ent, id;
menuitem = 0;
initscr();
drawmenu(menuitem);
keypad(stdscr,TRUE);
noecho();
do {
key = getch();
switch(key) {
case KEY_DOWN: menuitem++;
if(menuitem > MENUMAX-1)
menuitem = 0;
break;
case KEY_UP: menuitem--;
if(menuitem < 0)
menuitem = MENUMAX-1;
break;
default:
break;
}
drawmenu(menuitem);
ent = getch();
if(menuitem == 0 && ent == KEY_RIGHT) {
login();
refresh();
}
else if(menuitem == 1 && ent == KEY_RIGHT) {
register_id();
refresh();
}
else if(menuitem == 2 && ent == KEY_RIGHT) {
findtrain();
refresh();
}
else if(menuitem == 3 && ent == KEY_RIGHT) {
move(0,0);
clrtobot();
printw("Enter train id\n");
scanw("%d", &id);
CheckAvailibility(id);
refresh();
}
else if(menuitem == 4 && ent == KEY_RIGHT) {
cancelticket();
refresh();
}
else if(menuitem == 5 && ent == KEY_RIGHT) {
DisplayQueueac();
refresh();
}
else if(menuitem == 6 && ent == KEY_RIGHT) {
DisplayQueuesl();
refresh();
}
else if(menuitem == 7 && ent == KEY_RIGHT) {
exit(1);
}
}
while(key != '\n');
echo(); /*Shows the text*/
endwin();
return 0;
}