Browse code

Fix colors when terminal background color is not black. (bb #1438, reported by Dennis Peterson <dennispe*inetnw.com>)

git-svn: trunk@4877

Török Edvin authored on 2009/03/01 19:15:32
Showing 3 changed files
... ...
@@ -1,3 +1,9 @@
1
+Sun Mar  1 12:15:17 EET 2009 (edwin)
2
+------------------------------------
3
+ * clamdtop/clamdtop.c, shared/optparser.c: Fix colors when terminal
4
+ background color is not black.  (bb #1438, reported by Dennis
5
+ Peterson <dennispe*inetnw.com>)
6
+
1 7
 Sun Mar  1 11:29:32 EET 2009 (edwin)
2 8
 ------------------------------------
3 9
  * clamdtop/clamdtop.c: Use 'H' instead of 'F1', add support for
... ...
@@ -262,8 +262,10 @@ static void init_windows(int num_clamd)
262 262
 	}
263 263
 }
264 264
 
265
-static void init_ncurses(int num_clamd)
265
+static void init_ncurses(int num_clamd, int use_default)
266 266
 {
267
+	int default_bg = use_default ? DEFAULT_COLOR : COLOR_BLACK;
268
+	int default_fg = use_default ? DEFAULT_COLOR : COLOR_WHITE;
267 269
 	initscr();
268 270
 	curses_inited = 1;
269 271
 
... ...
@@ -273,18 +275,19 @@ static void init_ncurses(int num_clamd)
273 273
 	halfdelay(UPDATE_INTERVAL*10); /* timeout of 2s when waiting for input*/
274 274
 	noecho();		/* dont echo input */
275 275
 	curs_set(0);		/* turn off cursor */
276
-	use_default_colors();
276
+	if (use_default)
277
+	    use_default_colors();
277 278
 
278 279
 	init_pair(header_color, COLOR_BLACK, COLOR_WHITE);
279
-	init_pair(version_color, DEFAULT_COLOR, DEFAULT_COLOR);
280
+	init_pair(version_color, default_fg, default_bg);
280 281
 	init_pair(error_color, COLOR_WHITE, COLOR_RED);
281
-	init_pair(value_color, COLOR_GREEN, DEFAULT_COLOR);
282
-	init_pair(descr_color, COLOR_CYAN, DEFAULT_COLOR);
282
+	init_pair(value_color, COLOR_GREEN, default_bg);
283
+	init_pair(descr_color, COLOR_CYAN, default_bg);
283 284
 	init_pair(selected_color, COLOR_BLACK, COLOR_CYAN);
284 285
 	init_pair(queue_header_color, COLOR_BLACK, COLOR_GREEN);
285
-	init_pair(activ_color, COLOR_MAGENTA, DEFAULT_COLOR);
286
-	init_pair(dim_color, COLOR_GREEN, DEFAULT_COLOR);
287
-	init_pair(red_color, COLOR_RED, DEFAULT_COLOR);
286
+	init_pair(activ_color, COLOR_MAGENTA, default_bg);
287
+	init_pair(dim_color, COLOR_GREEN, default_bg);
288
+	init_pair(red_color, COLOR_RED, default_bg);
288 289
 
289 290
 	init_windows(num_clamd);
290 291
 }
... ...
@@ -1067,12 +1070,13 @@ static void help(void)
1067 1067
     printf("    --help                 -h         Show help\n");
1068 1068
     printf("    --version              -V         Show version\n");
1069 1069
     printf("    --config-file=FILE     -c FILE    Read clamd's configuration files from FILE\n");
1070
+    printf("    --defaultcolors	       -d	  Use default terminal colors\n");
1070 1071
     printf("	host[:port]			  Connect to clamd on host at port (default 3310)\n");
1071 1072
     printf("    /path/to/clamd.socket		  Connect to clamd over a local socket\n");
1072 1073
     printf("\n");
1073 1074
     return;
1074 1075
 }
1075
-
1076
+static int default_colors=0;
1076 1077
 /* -------------------------- Initialization ---------------- */
1077 1078
 static void setup_connections(int argc, char *argv[])
1078 1079
 {
... ...
@@ -1101,6 +1105,8 @@ static void setup_connections(int argc, char *argv[])
1101 1101
 	    exit(0);
1102 1102
 	}
1103 1103
 
1104
+	if(optget(opts, "defaultcolors")->enabled)
1105
+	    default_colors = 1;
1104 1106
 	memset(&global, 0, sizeof(global));
1105 1107
 	if (!opts->filename || !opts->filename[0]) {
1106 1108
 	    char *aargv[2];
... ...
@@ -1244,7 +1250,7 @@ int main(int argc, char *argv[])
1244 1244
 
1245 1245
 	atexit(cleanup);
1246 1246
 	setup_connections(argc, argv);
1247
-	init_ncurses(global.num_clamd);
1247
+	init_ncurses(global.num_clamd, default_colors);
1248 1248
 
1249 1249
 	memset(&tv_last, 0, sizeof(tv_last));
1250 1250
 	do {
... ...
@@ -108,6 +108,7 @@ const struct clam_option clam_options[] = {
108 108
     { NULL, "diff", 'd', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
109 109
     { NULL, "run-cdiff", 'r', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
110 110
     { NULL, "verify-cdiff", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
111
+    { NULL, "defaultcolors", 'd', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMDTOP, "", "" },
111 112
 
112 113
     { NULL, "config-dir", 'c', TYPE_STRING, NULL, 0, CONFDIR, FLAG_REQUIRED, OPT_CLAMCONF, "", "" },
113 114
     { NULL, "non-default", 'n', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMCONF, "", "" },