How to write a C Program Free Smit Menu Test in C Programming Language ?
Solution:
#include <ncurses.h>
#define MENUMAX 7
#define PROGNAME "Free SMIT"
void drawmenu(int item)
{
int c;
char mainmenutitle[] = "Systems Administration"; // Title
char subtitle[] = "Please move the cursor to the desired item and press Enter";
char menu [MENUMAX] [34] = { /* 6 Items for MENUMAX */
"Process Viewer",
"Filesystem Management",
"Users & Groups",
"Init Manager",
"About Free SMIT",
"Test",
"Shutdown"
};
clear();
/* Print Title and Subtitle */
attron(A_BOLD);
mvaddstr(1, 26, mainmenutitle);
mvaddstr(3,1, subtitle);
attroff(A_BOLD);
/* Menu Items print and highlight */
for (c=0;c<MENUMAX;c++)
{
if (c==item)
attron(A_REVERSE); // Highlight
mvaddstr(5+(c*1),5,menu[c]);
attroff(A_REVERSE);
}
/* Bottom Part of the Menu */
attron(A_BOLD);
mvaddstr(19,2, "F1=Help F2=Refresh F9=Shell Enter=Do");
attroff(A_BOLD);
refresh();
}
int main(void)
{
int key,menuitem;
menuitem = 0;
initscr();
refresh();
drawmenu(menuitem);
mvprintw(20,2, "Menuitem Item %d", menuitem);
keypad(stdscr,TRUE);
noecho(); /* Disable Echo */
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);
mvprintw(20,2, "Menuitem Item %d", menuitem);
refresh();
} while(key != '\n');
echo(); /* Turn on Echo */
/* At this point, the value of selected menu is kept in the menuitem
* varible. The program can branch off to whatever subroutine
* is required to carry out that function */
endwin();
return 0;
}
#define MENUMAX 7
#define PROGNAME "Free SMIT"
void drawmenu(int item)
{
int c;
char mainmenutitle[] = "Systems Administration"; // Title
char subtitle[] = "Please move the cursor to the desired item and press Enter";
char menu [MENUMAX] [34] = { /* 6 Items for MENUMAX */
"Process Viewer",
"Filesystem Management",
"Users & Groups",
"Init Manager",
"About Free SMIT",
"Test",
"Shutdown"
};
clear();
/* Print Title and Subtitle */
attron(A_BOLD);
mvaddstr(1, 26, mainmenutitle);
mvaddstr(3,1, subtitle);
attroff(A_BOLD);
/* Menu Items print and highlight */
for (c=0;c<MENUMAX;c++)
{
if (c==item)
attron(A_REVERSE); // Highlight
mvaddstr(5+(c*1),5,menu[c]);
attroff(A_REVERSE);
}
/* Bottom Part of the Menu */
attron(A_BOLD);
mvaddstr(19,2, "F1=Help F2=Refresh F9=Shell Enter=Do");
attroff(A_BOLD);
refresh();
}
int main(void)
{
int key,menuitem;
menuitem = 0;
initscr();
refresh();
drawmenu(menuitem);
mvprintw(20,2, "Menuitem Item %d", menuitem);
keypad(stdscr,TRUE);
noecho(); /* Disable Echo */
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);
mvprintw(20,2, "Menuitem Item %d", menuitem);
refresh();
} while(key != '\n');
echo(); /* Turn on Echo */
/* At this point, the value of selected menu is kept in the menuitem
* varible. The program can branch off to whatever subroutine
* is required to carry out that function */
endwin();
return 0;
}