Index: doc/asterisk.8 =================================================================== --- doc/asterisk.8 (revision 137850) +++ doc/asterisk.8 (working copy) @@ -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 Index: Makefile =================================================================== --- Makefile (revision 137850) +++ Makefile (working copy) @@ -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 "dahdichanname = yes ; Set channel name as DAHDI" ; \ echo "" ; \ echo "; Changing the following lines may compromise your security." ; \ Index: include/asterisk/options.h =================================================================== --- include/asterisk/options.h (revision 137850) +++ include/asterisk/options.h (working copy) @@ -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; Index: main/term.c =================================================================== --- main/term.c (revision 137850) +++ main/term.c (working copy) @@ -50,6 +50,20 @@ 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 ? ATTR_DIM : 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 (ast_opt_light_background) { + fgcolor = opposite(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); - } + + 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 ? ATTR_DIM : 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 (ast_opt_light_background) { + fgcolor = opposite(fgcolor); } - if (attr) { - snprintf(outbuf, maxout, "%c[%d;%sm", ESC, attr, tmp); - } else { - snprintf(outbuf, maxout, "%c[%sm", ESC, tmp); - } + + 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; } Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 137850) +++ main/asterisk.c (working copy) @@ -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 Connect to Asterisk via 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 Execute command (only valid with -r)\n"); - printf(" -s Connect to Asterisk via 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); }