aboutsummaryrefslogtreecommitdiff
path: root/payloads/libpayload/curses/PDCurses-3.4/demos/tuidemo.c
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@secunet.com>2011-07-07 15:41:53 +0200
committerStefan Reinauer <stefan.reinauer@coreboot.org>2011-08-04 08:10:41 +0200
commit3b77b723ca209199c8a224702812441e2196d452 (patch)
treecbf3be2c724139ec80a33dbf8e002b7871ef9307 /payloads/libpayload/curses/PDCurses-3.4/demos/tuidemo.c
parent1ac19e28eed4f6c53a4f295eb55500c65fc80f8d (diff)
libpayload: Add PDCurses and ncurses' libform/libmenu
PDCurses provides an alternative implementation of the curses library standard in addition to tinycurses. Where tinycurses is really tiny, PDCurses is more complete and provides virtually unlimited windows and the full API. The PDCurses code is brought in "vanilla", with all local changes residing in curses/pdcurses-backend/ In addition to a curses library, this change also provides libpanel (as part of the PDCurses code), and libform and libmenu which were derived from ncurses-5.9. As they rely on ncurses internals (and PDCurses is not ncurses), more changes were required for these libraries to work. The build system is extended to install the right set of header files depending on the selected curses implementation. Change-Id: I9e5b920f94b6510da01da2f656196a993170d1c5 Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com> Reviewed-on: http://review.coreboot.org/106 Tested-by: build bot (Jenkins) Reviewed-by: Marc Jones <marcj303@gmail.com>
Diffstat (limited to 'payloads/libpayload/curses/PDCurses-3.4/demos/tuidemo.c')
-rw-r--r--payloads/libpayload/curses/PDCurses-3.4/demos/tuidemo.c233
1 files changed, 233 insertions, 0 deletions
diff --git a/payloads/libpayload/curses/PDCurses-3.4/demos/tuidemo.c b/payloads/libpayload/curses/PDCurses-3.4/demos/tuidemo.c
new file mode 100644
index 0000000000..a22d2a4181
--- /dev/null
+++ b/payloads/libpayload/curses/PDCurses-3.4/demos/tuidemo.c
@@ -0,0 +1,233 @@
+/*
+ * $Id: tuidemo.c,v 1.22 2008/07/14 12:35:23 wmcbrine Exp $
+ *
+ * Author : P.J. Kunst <kunst@prl.philips.nl>
+ * Date : 25-02-93
+ *
+ * Purpose: This program demonstrates the use of the 'curses' library
+ * for the creation of (simple) menu-operated programs.
+ * In the PDCurses version, use is made of colors for the
+ * highlighting of subwindows (title bar, status bar etc).
+ *
+ * Acknowledgement: some ideas were borrowed from Mark Hessling's
+ * version of the 'testcurs' program.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+#include "tui.h"
+
+/* change this if source at other location */
+
+#ifdef XCURSES
+# define FNAME "../demos/tui.c"
+#else
+# define FNAME "..\\demos\\tui.c"
+#endif
+
+/**************************** strings entry box ***************************/
+
+void address(void)
+{
+ char *fieldname[6] =
+ {
+ "Name", "Street", "City", "State", "Country", (char *)0
+ };
+
+ char *fieldbuf[5];
+ WINDOW *wbody = bodywin();
+ int i, field = 50;
+
+ for (i = 0; i < 5; i++)
+ fieldbuf[i] = calloc(1, field + 1);
+
+ if (getstrings(fieldname, fieldbuf, field) != KEY_ESC)
+ {
+ for (i = 0; fieldname[i]; i++)
+ wprintw(wbody, "%10s : %s\n",
+ fieldname[i], fieldbuf[i]);
+
+ wrefresh(wbody);
+ }
+
+ for (i = 0; i < 5; i++)
+ free(fieldbuf[i]);
+}
+
+/**************************** string entry box ****************************/
+
+char *getfname(char *desc, char *fname, int field)
+{
+ char *fieldname[2];
+ char *fieldbuf[1];
+
+ fieldname[0] = desc;
+ fieldname[1] = 0;
+ fieldbuf[0] = fname;
+
+ return (getstrings(fieldname, fieldbuf, field) == KEY_ESC) ? NULL : fname;
+}
+
+/**************************** a very simple file browser ******************/
+
+void showfile(char *fname)
+{
+ int i, bh = bodylen();
+ FILE *fp;
+ char buf[MAXSTRLEN];
+ bool ateof = FALSE;
+
+ statusmsg("FileBrowser: Hit key to continue, Q to quit");
+
+ if ((fp = fopen(fname, "r")) != NULL) /* file available? */
+ {
+ while (!ateof)
+ {
+ clsbody();
+
+ for (i = 0; i < bh - 1 && !ateof; i++)
+ {
+ buf[0] = '\0';
+ fgets(buf, MAXSTRLEN, fp);
+
+ if (strlen(buf))
+ bodymsg(buf);
+ else
+ ateof = TRUE;
+ }
+
+ switch (waitforkey())
+ {
+ case 'Q':
+ case 'q':
+ case 0x1b:
+ ateof = TRUE;
+ }
+ }
+
+ fclose(fp);
+ }
+ else
+ {
+ sprintf(buf, "ERROR: file '%s' not found", fname);
+ errormsg(buf);
+ }
+}
+
+/***************************** forward declarations ***********************/
+
+void sub0(void), sub1(void), sub2(void), sub3(void);
+void func1(void), func2(void);
+void subfunc1(void), subfunc2(void);
+void subsub(void);
+
+/***************************** menus initialization ***********************/
+
+menu MainMenu[] =
+{
+ { "Asub", sub0, "Go inside first submenu" },
+ { "Bsub", sub1, "Go inside second submenu" },
+ { "Csub", sub2, "Go inside third submenu" },
+ { "Dsub", sub3, "Go inside fourth submenu" },
+ { "", (FUNC)0, "" } /* always add this as the last item! */
+};
+
+menu SubMenu0[] =
+{
+ { "Exit", DoExit, "Terminate program" },
+ { "", (FUNC)0, "" }
+};
+
+menu SubMenu1[] =
+{
+ { "OneBeep", func1, "Sound one beep" },
+ { "TwoBeeps", func2, "Sound two beeps" },
+ { "", (FUNC)0, "" }
+};
+
+menu SubMenu2[] =
+{
+ { "Browse", subfunc1, "Source file lister" },
+ { "Input", subfunc2, "Interactive file lister" },
+ { "Address", address, "Get address data" },
+ { "", (FUNC)0, "" }
+};
+
+menu SubMenu3[] =
+{
+ { "SubSub", subsub, "Go inside sub-submenu" },
+ { "", (FUNC)0, "" }
+};
+
+/***************************** main menu functions ************************/
+
+void sub0(void)
+{
+ domenu(SubMenu0);
+}
+
+void sub1(void)
+{
+ domenu(SubMenu1);
+}
+
+void sub2(void)
+{
+ domenu(SubMenu2);
+}
+
+void sub3(void)
+{
+ domenu(SubMenu3);
+}
+
+/***************************** submenu1 functions *************************/
+
+void func1(void)
+{
+ beep();
+ bodymsg("One beep! ");
+}
+
+void func2(void)
+{
+ beep();
+ bodymsg("Two beeps! ");
+ beep();
+}
+
+/***************************** submenu2 functions *************************/
+
+void subfunc1(void)
+{
+ showfile(FNAME);
+}
+
+void subfunc2(void)
+{
+ char fname[MAXSTRLEN];
+
+ strcpy(fname, FNAME);
+ if (getfname ("File to browse:", fname, 50))
+ showfile(fname);
+}
+
+/***************************** submenu3 functions *************************/
+
+void subsub(void)
+{
+ domenu(SubMenu2);
+}
+
+/***************************** start main menu ***************************/
+
+int main(int argc, char **argv)
+{
+ setlocale(LC_ALL, "");
+
+ startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");
+
+ return 0;
+}