1 04/15/88  "WINDOW" EXAMPLE
 2 
 3 /*        WINDOW.  Displays inputed commands,
 4  */       using multiple windows.
 5 
 6 #include <curses.h>
 7 
 8 WINDOW *cmdwin;
 9 
10 main()
11 {
12           int i, c;
13           char buf[120];
14 
15           initscr();
16           nonl();
17           noecho();
18           cbreak();
19 
20 
21           cmdwin = newwin(3, COLS, 0,0); /* top 3 lines */
22           for (i=0; i<LINES; i ++)
23                     mvprintw(i,0, "This is line %d of stdscr", i);
24 
25 
26           for (;;) {
27                     refresh();
28                     c = getch();
29                     switch (c) {
30                     case  'c' : /* Enter command from keyboard */
31                               werase(cmdwin);
32                               wprintw(cmdwin, "Enter command:");
33                               wmove(cmdwin, 2,0);
34                               for (i=0; i<COLS; i++)
35                                         waddch(cmdwin,  '-' );
36 
37 
38                               wmove(cmdwin, 1,0);
39                               touchwin(cmdwin);
40                               echo();
41                               wrefresh(cmdwin);
42                               wgetstr(cmdwin, buf);
43                               noecho();
44                               touchwin(stdscr);
45 
46                               /*
47                                * The command is now in buf.
48                                * It should be processed here.
49                                */
50 
51                               system(buf);
52                               sleep(5);
53                               clearok(curscr);
54                               refresh();
55 
56                               break;
57                     case  'q' :
58                               erase();
59                               refresh();
60                               endwin();
61                               exit(0);
62                     default :
63 
64                          flash();
65                          mvaddstr(23,0,"Sorry, no such command. Only (c,q) are
66                          valid");
67 
68                     }
69           }
70 }