mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 12:16:00 +00:00
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 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@139981 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
1
Makefile
1
Makefile
@@ -684,6 +684,7 @@ samples: adsi
|
||||
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]" ; \
|
||||
|
@@ -157,6 +157,10 @@ of your log files.
|
||||
\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
|
||||
|
@@ -82,6 +82,8 @@ enum ast_option_flags {
|
||||
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 @@ enum ast_option_flags {
|
||||
#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;
|
||||
|
||||
|
@@ -2113,7 +2113,7 @@ static char *cli_prompt(EditLine *editline)
|
||||
}
|
||||
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 @@ static int show_cli_help(void) {
|
||||
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 @@ static void ast_readconfig(void)
|
||||
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 @@ int main(int argc, char *argv[])
|
||||
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 @@ int main(int argc, char *argv[])
|
||||
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);
|
||||
}
|
||||
|
103
main/term.c
103
main/term.c
@@ -50,6 +50,20 @@ static const char *termpath[] = {
|
||||
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 @@ int ast_term_init(void)
|
||||
|
||||
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);
|
||||
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 @@ int ast_term_init(void)
|
||||
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)) {
|
||||
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 @@ char *term_prompt(char *outbuf, const char *inbuf, int maxout)
|
||||
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,
|
||||
if (ast_opt_light_background) {
|
||||
snprintf(outbuf, maxout, "%c[%d;0m%c%c[%d;0m%s",
|
||||
ESC, COLOR_BLUE,
|
||||
inbuf[0],
|
||||
ESC, 0, COLOR_WHITE, COLOR_BLACK + 10,
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user