Sync usage with man page.
[netbsd-mini2440.git] / usr.sbin / isdn / isdntel / display.c
blob46a07006083381a9c96a2280001ba87191a78e7d
1 /*
2 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
25 *---------------------------------------------------------------------------
27 * isdntel - isdn4bsd telephone answering machine support
28 * ======================================================
30 * $Id: display.c,v 1.4 2009/04/16 05:56:33 lukem Exp $
32 * $FreeBSD$
34 * last edit-date: [Wed Jul 19 10:08:06 2000]
36 *----------------------------------------------------------------------------*/
38 #include "defs.h"
40 static const char *helpstr = "Enter Control-D to exit program or RETURN for command window";
42 /*---------------------------------------------------------------------------*
43 * init curses fullscreen display
44 *---------------------------------------------------------------------------*/
45 void
46 init_screen(void)
48 char buffer[512];
50 initscr(); /* curses init */
52 curses_ready = 1;
54 if ((COLS < 80) || (LINES < 24))
55 fatal("ERROR, minimal screensize must be 80x24, is %dx%d, terminating!", COLS, LINES);
58 if ((main_w = newwin(LINES-START_O-2, COLS, START_O, 0)) == NULL)
59 fatal("ERROR, curses init main window, terminating!");
61 raw(); /* raw input */
62 noecho(); /* do not echo input */
63 keypad(stdscr, TRUE); /* use special keys */
64 keypad(main_w, TRUE); /* use special keys */
65 scrollok(main_w, TRUE);
67 snprintf(buffer, sizeof(buffer), " isdntel %d.%d.%d ", VERSION, REL, STEP);
69 move(0, 0);
70 standout();
71 hline(ACS_HLINE, 5);
72 move(0, 5);
73 addstr(buffer);
74 move(0, 5 + strlen(buffer));
75 hline(ACS_HLINE, 256);
76 standend();
78 move(1, 0);
79 addstr("Date Time Called Party Calling Party Alias Length");
80 /* 31.12.96 16:45:12 1234567890123456 1234567890123456 12345678901234567890 123456 */
82 move(2, 0);
83 hline(ACS_HLINE, 256);
85 move(LINES-2, 0);
86 hline(ACS_HLINE, 256);
88 mvaddstr(LINES-1, (COLS / 2) - (strlen(helpstr) / 2), helpstr);
90 refresh();
92 wrefresh(main_w);
95 /*---------------------------------------------------------------------------*
96 * curses menu for fullscreen command mode
97 *---------------------------------------------------------------------------*/
98 void
99 do_menu(void)
101 static const char *menu[WMITEMS] =
103 "Play File",
104 #define PLAY 0
105 "Delete File",
106 #define DELETE 1
107 "Re-Read Spool",
108 #define REREAD 2
109 "Refresh Screen",
110 #define REFRESH 3
111 "Exit Program",
112 #define EXIT 4
115 WINDOW *menu_w;
116 int c;
117 int mpos;
119 /* create a new window in the lower screen area */
121 if ((menu_w = newwin(WMENU_HGT, WMENU_LEN, WMENU_POSLN, WMENU_POSCO )) == NULL)
122 return;
124 keypad(menu_w, TRUE); /* use special keys */
126 /* draw border around the window */
128 box(menu_w, 0, 0);
130 /* add a title */
132 wstandout(menu_w);
133 mvwaddstr(menu_w, 0, (WMENU_LEN / 2) - (strlen(WMENU_TITLE) / 2), WMENU_TITLE);
134 wstandend(menu_w);
136 /* fill the window with the menu options */
138 for (mpos=0; mpos <= (WMITEMS-1); mpos++)
139 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
141 /* highlight the first menu option */
143 mpos = 0;
144 wstandout(menu_w);
145 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
146 wstandend(menu_w);
148 /* input loop */
150 for (;;)
152 wrefresh(menu_w);
154 c = wgetch(menu_w);
156 switch (c)
158 case TAB:
159 case KEY_DOWN: /* down-move cursor */
160 case ' ':
161 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
162 mpos++;
163 if (mpos >= WMITEMS)
164 mpos = 0;
165 wstandout(menu_w);
166 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
167 wstandend(menu_w);
168 break;
170 case KEY_UP: /* up-move cursor */
171 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
172 if (mpos)
173 mpos--;
174 else
175 mpos = WMITEMS-1;
176 wstandout(menu_w);
177 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
178 wstandend(menu_w);
179 break;
181 case 'R':
182 case 'r':
183 wrefresh(curscr);
184 goto mexit;
186 case 'E':
187 case 'e':
188 case 'Q':
189 case 'q':
190 case 'X':
191 case 'x':
192 do_quit(0);
193 goto mexit;
194 break;
196 case 'P':
197 case 'p':
198 play(cur_file);
199 goto mexit;
200 break;
202 case 'D':
203 case 'd':
204 delete(cur_file);
205 goto mexit;
206 break;
208 case CR:
209 case LF: /* exec highlighted option */
210 #ifdef KEY_ENTER
211 case KEY_ENTER:
212 #endif
213 switch (mpos)
215 case PLAY:
216 play(cur_file);
217 goto mexit;
218 break;
219 case DELETE:
220 delete(cur_file);
221 goto mexit;
222 break;
223 case REREAD:
224 reread();
225 goto mexit;
226 break;
227 case REFRESH:
228 wrefresh(curscr);
229 break;
230 case EXIT:
231 do_quit(0);
232 break;
234 goto mexit;
235 break;
237 default:
238 goto mexit;
239 break;
243 mexit:
244 /* delete the menu window */
246 delwin(menu_w);
248 /* re-display the original lower window contents */
250 touchwin(main_w);
251 wrefresh(main_w);
254 /* EOF */