[svn-commits] tilghman: trunk r139981 - in /trunk: ./ doc/ include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 25 18:13:32 CDT 2008


Author: tilghman
Date: Mon Aug 25 18:13:32 2008
New Revision: 139981

URL: http://svn.digium.com/view/asterisk?view=rev&rev=139981
Log:
Optional light colored background, for those who use black on white terminals.
(closes issue #13306)
 Reported by: Corydon76
 Patches: 
       20080814__bug13306__3.diff.txt uploaded by Corydon76 (license 14)
 Tested by: Corydon76, pkempgen

Modified:
    trunk/Makefile
    trunk/doc/asterisk.8
    trunk/include/asterisk/options.h
    trunk/main/asterisk.c
    trunk/main/term.c

Modified: trunk/Makefile
URL: http://svn.digium.com/view/asterisk/trunk/Makefile?view=diff&rev=139981&r1=139980&r2=139981
==============================================================================
--- trunk/Makefile (original)
+++ trunk/Makefile Mon Aug 25 18:13:32 2008
@@ -684,6 +684,7 @@
 		echo ";transcode_via_sln = yes ; Build transcode paths via SLINEAR, instead of directly" ; \
 		echo ";runuser = asterisk ; The user to run as" ; \
 		echo ";rungroup = asterisk ; The group to run as" ; \
+		echo ";lightbackground = yes ; If your terminal is set for a light-colored background" ; \
 		echo "" ; \
 		echo "; Changing the following lines may compromise your security." ; \
 		echo ";[files]" ; \

Modified: trunk/doc/asterisk.8
URL: http://svn.digium.com/view/asterisk/trunk/doc/asterisk.8?view=diff&rev=139981&r1=139980&r2=139981
==============================================================================
--- trunk/doc/asterisk.8 (original)
+++ trunk/doc/asterisk.8 Mon Aug 25 18:13:32 2008
@@ -157,6 +157,10 @@
 \fB-V\fR
 Display version information and exit immediately.
 .TP
+\fB-W\fR
+Change the terminal colors to compensate for a light background,
+rather than a dark background, as is the default.
+.TP
 \fB-x \fIcommand\fB\fR
 Connect to a running Asterisk process and execute a command on
 a command line, passing any output through to standard out and

Modified: trunk/include/asterisk/options.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/options.h?view=diff&rev=139981&r1=139980&r2=139981
==============================================================================
--- trunk/include/asterisk/options.h (original)
+++ trunk/include/asterisk/options.h Mon Aug 25 18:13:32 2008
@@ -82,6 +82,8 @@
 	AST_OPT_FLAG_DEBUG_FILE = (1 << 23),
 	/*! There is a per-file verbose setting */
 	AST_OPT_FLAG_VERBOSE_FILE = (1 << 24),
+	/*! Terminal colors should be adjusted for a light-colored background */
+	AST_OPT_FLAG_LIGHT_BACKGROUND = (1 << 25),
 };
 
 /*! These are the options that set by default when Asterisk starts */
@@ -111,6 +113,7 @@
 #define ast_opt_mute			ast_test_flag(&ast_options, AST_OPT_FLAG_MUTE)
 #define ast_opt_dbg_file		ast_test_flag(&ast_options, AST_OPT_FLAG_DEBUG_FILE)
 #define ast_opt_verb_file		ast_test_flag(&ast_options, AST_OPT_FLAG_VERBOSE_FILE)
+#define ast_opt_light_background		ast_test_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND)
 
 extern struct ast_flags ast_options;
 

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=139981&r1=139980&r2=139981
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Mon Aug 25 18:13:32 2008
@@ -2113,7 +2113,7 @@
 		}
 		if (color_used) {
 			/* Force colors back to normal at end */
-			ast_str_append(&prompt, 0, "%s", term_color_code(term_code, COLOR_WHITE, COLOR_BLACK, sizeof(term_code)));
+			ast_str_append(&prompt, 0, "%s", term_color_code(term_code, 0, 0, sizeof(term_code)));
 		}
 	} else if (remotehostname) {
 		ast_str_set(&prompt, 0, ASTERISK_PROMPT2, remotehostname);
@@ -2570,13 +2570,14 @@
 	printf("   -q              Quiet mode (suppress output)\n");
 	printf("   -r              Connect to Asterisk on this machine\n");
 	printf("   -R              Same as -r, except attempt to reconnect if disconnected\n");
+	printf("   -s <socket>     Connect to Asterisk via socket <socket> (only valid with -r)\n");
 	printf("   -t              Record soundfiles in /var/tmp and move them where they\n");
 	printf("                   belong after they are done\n");
 	printf("   -T              Display the time in [Mmm dd hh:mm:ss] format for each line\n");
 	printf("                   of output to the CLI\n");
 	printf("   -v              Increase verbosity (multiple v's = more verbose)\n");
 	printf("   -x <cmd>        Execute command <cmd> (only valid with -r)\n");
-	printf("   -s <socket>     Connect to Asterisk via socket <socket> (only valid with -r)\n");
+	printf("   -W              Adjust terminal colors to compensate for a light background\n");
 	printf("\n");
 	return 0;
 }
@@ -2789,6 +2790,8 @@
 				g_eid = tmp_eid;
 			} else
 				ast_verbose("Invalid Entity ID '%s' provided\n", v->value);
+		} else if (!strcasecmp(v->name, "lightbackground")) {
+			ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_LIGHT_BACKGROUND);
 		}
 	}
 	for (v = ast_variable_browse(cfg, "compat"); v; v = v->next) {
@@ -2928,7 +2931,7 @@
 	if (getenv("HOME")) 
 		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
 	/* Check for options */
-	while ((c = getopt(argc, argv, "mtThfFdvVqprRgciInx:U:G:C:L:M:e:s:")) != -1) {
+	while ((c = getopt(argc, argv, "mtThfFdvVqprRgciInx:U:G:C:L:M:e:s:W")) != -1) {
 		switch (c) {
 #if defined(HAVE_SYSINFO)
 		case 'e':
@@ -3020,6 +3023,9 @@
 		case 's':
 			remotesock = ast_strdupa(optarg);
 			break;
+		case 'W': /* White background */
+			ast_set_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND);
+			break;
 		case '?':
 			exit(1);
 		}

Modified: trunk/main/term.c
URL: http://svn.digium.com/view/asterisk/trunk/main/term.c?view=diff&rev=139981&r1=139980&r2=139981
==============================================================================
--- trunk/main/term.c (original)
+++ trunk/main/term.c Mon Aug 25 18:13:32 2008
@@ -49,6 +49,20 @@
 	"/usr/lib/terminfo",
 	NULL
 	};
+
+static int opposite(int color)
+{
+	int lookup[] = {
+		/* BLACK */ COLOR_BLACK,
+		/* RED */ COLOR_MAGENTA,
+		/* GREEN */ COLOR_GREEN,
+		/* BROWN */ COLOR_BROWN,
+		/* BLUE */ COLOR_CYAN,
+		/* MAGENTA */ COLOR_RED,
+		/* CYAN */ COLOR_BLUE,
+		/* WHITE */ COLOR_BLACK };
+	return color ? lookup[color - 30] : 0;
+}
 
 /* Ripped off from Ross Ridge, but it's public domain code (libmytinfo) */
 static short convshort(char *s)
@@ -134,9 +148,15 @@
 
 	if (vt100compat) {
 		/* Make commands show up in nice colors */
-		snprintf(prepdata, sizeof(prepdata), "%c[%d;%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN, COLOR_BLACK + 10);
-		snprintf(enddata, sizeof(enddata), "%c[%d;%d;%dm", ESC, ATTR_RESET, COLOR_WHITE, COLOR_BLACK + 10);
-		snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
+		if (ast_opt_light_background) {
+			snprintf(prepdata, sizeof(prepdata), "%c[%dm", ESC, COLOR_BROWN);
+			snprintf(enddata, sizeof(enddata), "%c[%dm", ESC, COLOR_BLACK);
+			snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
+		} else {
+			snprintf(prepdata, sizeof(prepdata), "%c[%d;%dm", ESC, ATTR_BRIGHT, COLOR_BROWN);
+			snprintf(enddata, sizeof(enddata), "%c[%d;%dm", ESC, ATTR_RESET, COLOR_WHITE);
+			snprintf(quitdata, sizeof(quitdata), "%c[0m", ESC);
+		}
 	}
 	return 0;
 }
@@ -144,82 +164,47 @@
 char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
 {
 	int attr = 0;
-	char tmp[40];
+
 	if (!vt100compat) {
 		ast_copy_string(outbuf, inbuf, maxout);
 		return outbuf;
 	}
-	if (!fgcolor && !bgcolor) {
+	if (!fgcolor) {
 		ast_copy_string(outbuf, inbuf, maxout);
 		return outbuf;
 	}
-	if ((fgcolor & 128) && (bgcolor & 128)) {
-		/* Can't both be highlighted */
-		ast_copy_string(outbuf, inbuf, maxout);
-		return outbuf;
-	}
-	if (!bgcolor)
-		bgcolor = COLOR_BLACK;
-
-	if (bgcolor) {
-		bgcolor &= ~128;
-		bgcolor += 10;
-	}
+
 	if (fgcolor & 128) {
-		attr = ATTR_BRIGHT;
+		attr = ast_opt_light_background ? 0 : ATTR_BRIGHT;
 		fgcolor &= ~128;
 	}
-	if (fgcolor && bgcolor) {
-		snprintf(tmp, sizeof(tmp), "%d;%d", fgcolor, bgcolor);
-	} else if (bgcolor) {
-		snprintf(tmp, sizeof(tmp), "%d", bgcolor);
-	} else if (fgcolor) {
-		snprintf(tmp, sizeof(tmp), "%d", fgcolor);
-	}
-	if (attr) {
-		snprintf(outbuf, maxout, "%c[%d;%sm%s%c[0;%d;%dm", ESC, attr, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
-	} else {
-		snprintf(outbuf, maxout, "%c[%sm%s%c[0;%d;%dm", ESC, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
-	}
+
+	if (ast_opt_light_background) {
+		fgcolor = opposite(fgcolor);
+	}
+
+	snprintf(outbuf, maxout, "%c[%d;%dm%s%c[0m", ESC, attr, fgcolor, inbuf, ESC);
 	return outbuf;
 }
 
 char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
 {
-	int attr=0;
-	char tmp[40];
-	if ((!vt100compat) || (!fgcolor && !bgcolor)) {
+	int attr = 0;
+	if ((!vt100compat) || (!fgcolor)) {
 		*outbuf = '\0';
 		return outbuf;
 	}
-	if ((fgcolor & 128) && (bgcolor & 128)) {
-		/* Can't both be highlighted */
-		*outbuf = '\0';
-		return outbuf;
-	}
-	if (!bgcolor)
-		bgcolor = COLOR_BLACK;
-
-	if (bgcolor) {
-		bgcolor &= ~128;
-		bgcolor += 10;
-	}
+
 	if (fgcolor & 128) {
-		attr = ATTR_BRIGHT;
+		attr = ast_opt_light_background ? 0 : ATTR_BRIGHT;
 		fgcolor &= ~128;
 	}
-	if (fgcolor && bgcolor) {
-		snprintf(tmp, sizeof(tmp), "%d;%d", fgcolor, bgcolor);
-	} else if (bgcolor) {
-		snprintf(tmp, sizeof(tmp), "%d", bgcolor);
-	} else if (fgcolor) {
-		snprintf(tmp, sizeof(tmp), "%d", fgcolor);
-	}
-	if (attr) {
-		snprintf(outbuf, maxout, "%c[%d;%sm", ESC, attr, tmp);
-	} else {
-		snprintf(outbuf, maxout, "%c[%sm", ESC, tmp);
-	}
+
+	if (ast_opt_light_background) {
+		fgcolor = opposite(fgcolor);
+	}
+
+	snprintf(outbuf, maxout, "%c[%d;%dm", ESC, attr, fgcolor);
 	return outbuf;
 }
 
@@ -250,11 +235,19 @@
 		ast_copy_string(outbuf, inbuf, maxout);
 		return outbuf;
 	}
-	snprintf(outbuf, maxout, "%c[%d;%d;%dm%c%c[%d;%d;%dm%s",
-		ESC, ATTR_BRIGHT, COLOR_BLUE, COLOR_BLACK + 10,
-		inbuf[0],
-		ESC, 0, COLOR_WHITE, COLOR_BLACK + 10,
-		inbuf + 1);
+	if (ast_opt_light_background) {
+		snprintf(outbuf, maxout, "%c[%d;0m%c%c[%d;0m%s",
+			ESC, COLOR_BLUE,
+			inbuf[0],
+			ESC, COLOR_BLACK,
+			inbuf + 1);
+	} else {
+		snprintf(outbuf, maxout, "%c[%d;%d;0m%c%c[%d;%d;0m%s",
+			ESC, ATTR_BRIGHT, COLOR_BLUE,
+			inbuf[0],
+			ESC, 0, COLOR_WHITE,
+			inbuf + 1);
+	}
 	return outbuf;
 }
 




More information about the svn-commits mailing list