2 * $Id: tuidemo.c,v 1.22 2008/07/14 12:35:23 wmcbrine Exp $
4 * Author : P.J. Kunst <kunst@prl.philips.nl>
7 * Purpose: This program demonstrates the use of the 'curses' library
8 * for the creation of (simple) menu-operated programs.
9 * In the PDCurses version, use is made of colors for the
10 * highlighting of subwindows (title bar, status bar etc).
12 * Acknowledgement: some ideas were borrowed from Mark Hessling's
13 * version of the 'testcurs' program.
22 /* change this if source at other location */
25 # define FNAME "../demos/tui.c"
27 # define FNAME "..\\demos\\tui.c"
30 /**************************** strings entry box ***************************/
36 "Name", "Street", "City", "State", "Country", (char *)0
40 WINDOW *wbody = bodywin();
43 for (i = 0; i < 5; i++)
44 fieldbuf[i] = calloc(1, field + 1);
46 if (getstrings(fieldname, fieldbuf, field) != KEY_ESC)
48 for (i = 0; fieldname[i]; i++)
49 wprintw(wbody, "%10s : %s\n",
50 fieldname[i], fieldbuf[i]);
55 for (i = 0; i < 5; i++)
59 /**************************** string entry box ****************************/
61 char *getfname(char *desc, char *fname, int field)
70 return (getstrings(fieldname, fieldbuf, field) == KEY_ESC) ? NULL : fname;
73 /**************************** a very simple file browser ******************/
75 void showfile(char *fname)
77 int i, bh = bodylen();
82 statusmsg("FileBrowser: Hit key to continue, Q to quit");
84 if ((fp = fopen(fname, "r")) != NULL) /* file available? */
90 for (i = 0; i < bh - 1 && !ateof; i++)
93 fgets(buf, MAXSTRLEN, fp);
101 switch (waitforkey())
114 sprintf(buf, "ERROR: file '%s' not found", fname);
119 /***************************** forward declarations ***********************/
121 void sub0(void), sub1(void), sub2(void), sub3(void);
122 void func1(void), func2(void);
123 void subfunc1(void), subfunc2(void);
126 /***************************** menus initialization ***********************/
130 { "Asub", sub0, "Go inside first submenu" },
131 { "Bsub", sub1, "Go inside second submenu" },
132 { "Csub", sub2, "Go inside third submenu" },
133 { "Dsub", sub3, "Go inside fourth submenu" },
134 { "", (FUNC)0, "" } /* always add this as the last item! */
139 { "Exit", DoExit, "Terminate program" },
145 { "OneBeep", func1, "Sound one beep" },
146 { "TwoBeeps", func2, "Sound two beeps" },
152 { "Browse", subfunc1, "Source file lister" },
153 { "Input", subfunc2, "Interactive file lister" },
154 { "Address", address, "Get address data" },
160 { "SubSub", subsub, "Go inside sub-submenu" },
164 /***************************** main menu functions ************************/
186 /***************************** submenu1 functions *************************/
191 bodymsg("One beep! ");
197 bodymsg("Two beeps! ");
201 /***************************** submenu2 functions *************************/
210 char fname[MAXSTRLEN];
212 strcpy(fname, FNAME);
213 if (getfname ("File to browse:", fname, 50))
217 /***************************** submenu3 functions *************************/
224 /***************************** start main menu ***************************/
226 int main(int argc, char **argv)
228 setlocale(LC_ALL, "");
230 startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");