capt_get_packet(): check for key press only every 20ms
[iptraf-ng.git] / src / deskman.c
blobb625505261f4150972ffdec32a1ba326411838e8
1 /* For terms of usage/redistribution/modification see the LICENSE file */
2 /* For authors and contributors see the AUTHORS file */
4 /***
6 deskman.c - desktop management routines
8 ***/
10 #include "iptraf-ng-compat.h"
12 #include "tui/labels.h"
13 #include "tui/msgboxes.h"
14 #include "tui/winops.h"
16 #include "deskman.h"
17 #include "options.h"
19 /* Attribute variables */
21 int STDATTR;
22 int HIGHATTR;
23 int BOXATTR;
24 int ACTIVEATTR;
25 int BARSTDATTR;
26 int BARHIGHATTR;
27 int BARPTRATTR;
28 int DLGTEXTATTR;
29 int DLGBOXATTR;
30 int DLGHIGHATTR;
31 int DESCATTR;
32 int STATUSBARATTR;
33 int IPSTATLABELATTR;
34 int IPSTATATTR;
35 int DESKTEXTATTR;
36 int PTRATTR;
37 int FIELDATTR;
38 int ERRBOXATTR;
39 int ERRTXTATTR;
40 int OSPFATTR;
41 int UDPATTR;
42 int IGPATTR;
43 int IGMPATTR;
44 int IGRPATTR;
45 int GREATTR;
46 int ARPATTR;
47 int UNKNIPATTR;
48 int UNKNATTR;
49 int IPV6ATTR;
50 int ICMPV6ATTR;
52 /* draw the basic desktop common to my screen-oriented programs */
54 void draw_desktop(void)
56 int row; /* counter for desktop construction */
58 scrollok(stdscr, 0);
59 attrset(STATUSBARATTR);
60 move(0, 0);
61 printw("%*c", COLS, ' '); /* these two print the top n' bottom */
62 move(LINES - 1, 0);
63 printw("%*c", COLS, ' '); /* lines */
65 attrset(FIELDATTR);
67 for (row = 1; row <= LINES - 2; row++) { /* draw the background */
68 move(row, 0);
69 printw("%*c", COLS, ' ');
72 refresh();
75 void about(void)
77 WINDOW *win;
78 PANEL *panel;
79 int ch;
81 win = newwin(18, 62, (LINES - 17) / 2, (COLS - 62) / 2);
83 panel = new_panel(win);
85 tx_stdwinset(win);
86 wtimeout(win, -1);
87 wattrset(win, BOXATTR);
88 tx_colorwin(win);
89 tx_box(win, ACS_VLINE, ACS_HLINE);
90 wattrset(win, STDATTR);
91 mvwprintw(win, 1, 2, IPTRAF_NAME);
92 mvwprintw(win, 2, 2, "An IP Network Statistics Utility");
93 mvwprintw(win, 3, 2, "Version %s", IPTRAF_VERSION);
94 mvwprintw(win, 5, 2, "Written by Gerard Paul Java");
95 mvwprintw(win, 6, 2, "Copyright (c) Gerard Paul Java 1997-2004");
96 mvwprintw(win, 8, 2, "This program is open-source software released");
97 mvwprintw(win, 9, 2, "under the terms of the GNU General Public");
98 mvwprintw(win, 10, 2, "Public License Version 2 or any later version.");
99 mvwprintw(win, 11, 2, "See the included LICENSE file for details.");
100 mvwprintw(win, 13, 2,
101 "IPv6 support by Markus Ullmann <mail@markus-ullmann.de>");
102 mvwprintw(win, 14, 2,
103 "inspired by 2.7.0 diff by Guy Martin <gmsoft@tuxicoman.be>");
105 wattrset(win, HIGHATTR);
107 mvwprintw(win, 16, 2, ANYKEY_MSG);
109 update_panels();
110 doupdate();
112 do {
113 ch = wgetch(win);
114 if (ch == 12)
115 tx_refresh_screen();
116 } while (ch == 12);
118 del_panel(panel);
119 delwin(win);
120 update_panels();
121 doupdate();
124 void show_sort_statwin(WINDOW ** statwin, PANEL ** panel)
126 *statwin = newwin(5, 30, (LINES - 5) / 2, (COLS - 30) / 2);
127 *panel = new_panel(*statwin);
129 wattrset(*statwin, BOXATTR);
130 tx_colorwin(*statwin);
131 tx_box(*statwin, ACS_VLINE, ACS_HLINE);
133 wattrset(*statwin, STDATTR);
134 mvwprintw(*statwin, 2, 2, "Sorting, please wait...");
137 void printipcerr(void)
139 attrset(ERRTXTATTR);
140 mvprintw(0, 68, " IPC Error ");
143 void stdkeyhelp(WINDOW * win)
145 tx_printkeyhelp("Enter", "-accept ", win, DLGHIGHATTR, DLGTEXTATTR);
146 tx_printkeyhelp("Ctrl+X", "-cancel", win, DLGHIGHATTR, DLGTEXTATTR);
149 void sortkeyhelp(void)
151 tx_printkeyhelp("S", "-sort ", stdscr, HIGHATTR, STATUSBARATTR);
154 void stdexitkeyhelp(void)
156 tx_printkeyhelp("X", "-exit", stdscr, HIGHATTR, STATUSBARATTR);
157 tx_coloreol();
160 void scrollkeyhelp(void)
162 tx_printkeyhelp("Up/Down/PgUp/PgDn", "-scroll window ", stdscr,
163 HIGHATTR, STDATTR);
166 void tabkeyhelp(WINDOW * win)
168 tx_printkeyhelp("Tab", "-next field ", win, DLGHIGHATTR, DLGTEXTATTR);
171 void indicate(char *message)
173 attrset(STATUSBARATTR);
174 mvprintw(LINES - 1, 0, "%*c", COLS, ' ');
175 mvprintw(LINES - 1, 1, message);
176 refresh();
179 void printlargenum(unsigned long long i, WINDOW * win)
181 if (i < 100000000) /* less than 100 million */
182 wprintw(win, "%9llu", i);
183 else if (i < 1000000000) /* less than 1 billion */
184 wprintw(win, "%8lluk", i / 1000);
185 else if (i < 1000000000000ULL) /* less than 1 trillion */
186 wprintw(win, "%8lluM", i / 1000000);
187 else if (i < 1000000000000000ULL) /* less than 1000 trillion */
188 wprintw(win, "%8lluG", i / 1000000000ULL);
189 else
190 wprintw(win, "%8lluT", i / 1000000000000ULL);
193 void print_packet_drops(unsigned long count, WINDOW *win, int x)
195 wattrset(win, BOXATTR);
196 mvwprintw(win, getmaxy(win) - 1, x, " Drops: %9lu ", count);
199 int screen_update_needed(const struct timeval *now, const struct timeval *last)
201 unsigned long msecs = timeval_diff_msec(now, last);
202 if (options.updrate == 0) {
203 if (msecs >= DEFAULT_UPDATE_DELAY)
204 return 1;
205 else
206 return 0;
207 } else {
208 if (msecs >= (options.updrate * 1000UL))
209 return 1;
210 else
211 return 0;
215 void standardcolors(int color)
217 if ((color) && (has_colors())) {
218 init_pair(1, COLOR_BLUE, COLOR_WHITE);
219 init_pair(2, COLOR_BLACK, COLOR_CYAN);
220 init_pair(3, COLOR_CYAN, COLOR_BLUE);
221 init_pair(4, COLOR_YELLOW, COLOR_RED);
222 init_pair(5, COLOR_WHITE, COLOR_RED);
223 init_pair(6, COLOR_BLUE, COLOR_CYAN);
224 init_pair(7, COLOR_BLUE, COLOR_WHITE);
225 init_pair(9, COLOR_RED, COLOR_WHITE);
226 init_pair(10, COLOR_GREEN, COLOR_BLUE);
227 init_pair(11, COLOR_CYAN, COLOR_BLACK);
228 init_pair(12, COLOR_RED, COLOR_CYAN);
229 init_pair(14, COLOR_YELLOW, COLOR_BLUE);
230 init_pair(15, COLOR_YELLOW, COLOR_BLACK);
231 init_pair(16, COLOR_WHITE, COLOR_CYAN);
232 init_pair(17, COLOR_YELLOW, COLOR_CYAN);
233 init_pair(18, COLOR_GREEN, COLOR_BLACK);
234 init_pair(19, COLOR_WHITE, COLOR_BLUE);
236 STDATTR = COLOR_PAIR(14) | A_BOLD;
237 HIGHATTR = COLOR_PAIR(3) | A_BOLD;
238 BOXATTR = COLOR_PAIR(3);
239 ACTIVEATTR = COLOR_PAIR(10) | A_BOLD;
240 BARSTDATTR = COLOR_PAIR(15) | A_BOLD;
241 BARHIGHATTR = COLOR_PAIR(11) | A_BOLD;
242 BARPTRATTR = COLOR_PAIR(18) | A_BOLD;
243 DESCATTR = COLOR_PAIR(2);
244 DLGTEXTATTR = COLOR_PAIR(2);
245 DLGBOXATTR = COLOR_PAIR(6);
246 DLGHIGHATTR = COLOR_PAIR(12);
247 STATUSBARATTR = STDATTR;
248 IPSTATLABELATTR = COLOR_PAIR(2);
249 IPSTATATTR = COLOR_PAIR(12);
250 DESKTEXTATTR = COLOR_PAIR(7);
251 PTRATTR = COLOR_PAIR(10) | A_BOLD;
252 FIELDATTR = COLOR_PAIR(1);
253 ERRBOXATTR = COLOR_PAIR(5) | A_BOLD;
254 ERRTXTATTR = COLOR_PAIR(4) | A_BOLD;
255 OSPFATTR = COLOR_PAIR(2);
256 UDPATTR = COLOR_PAIR(9);
257 IGPATTR = COLOR_PAIR(12);
258 IGMPATTR = COLOR_PAIR(10) | A_BOLD;
259 IGRPATTR = COLOR_PAIR(16) | A_BOLD;
260 ARPATTR = COLOR_PAIR(5) | A_BOLD;
261 GREATTR = COLOR_PAIR(1);
262 UNKNIPATTR = COLOR_PAIR(19) | A_BOLD;
263 ICMPV6ATTR = COLOR_PAIR(19) | A_BOLD;
264 IPV6ATTR = COLOR_PAIR(19);
265 UNKNATTR = COLOR_PAIR(4) | A_BOLD;
266 } else {
267 STDATTR = A_REVERSE;
268 HIGHATTR = A_REVERSE;
269 BOXATTR = A_REVERSE;
270 ACTIVEATTR = A_BOLD;
271 BARSTDATTR = A_NORMAL;
272 BARHIGHATTR = A_BOLD;
273 BARPTRATTR = A_NORMAL;
274 DESCATTR = A_BOLD;
275 DLGBOXATTR = A_REVERSE;
276 DLGTEXTATTR = A_REVERSE;
277 DLGHIGHATTR = A_BOLD;
278 STATUSBARATTR = A_REVERSE;
279 IPSTATLABELATTR = A_REVERSE;
280 IPSTATATTR = A_STANDOUT;
281 DESKTEXTATTR = A_NORMAL;
282 PTRATTR = A_REVERSE;
283 FIELDATTR = A_BOLD;
284 ERRBOXATTR = A_BOLD;
285 ERRTXTATTR = A_NORMAL;
286 OSPFATTR = A_REVERSE;
287 UDPATTR = A_BOLD;
288 IGPATTR = A_REVERSE;
289 IGMPATTR = A_REVERSE;
290 IGRPATTR = A_REVERSE;
291 ARPATTR = A_BOLD;
292 GREATTR = A_BOLD;
293 UNKNIPATTR = A_BOLD;
294 ICMPV6ATTR = A_REVERSE;
295 UNKNATTR = A_BOLD;
298 tx_init_error_attrs(ERRBOXATTR, ERRTXTATTR, ERRBOXATTR);
299 tx_init_info_attrs(BOXATTR, STDATTR, HIGHATTR);