summaryrefslogtreecommitdiff
path: root/main/term.c
diff options
context:
space:
mode:
authorWalter Doekes <walter+asterisk@wjd.nu>2015-11-25 20:29:42 +0100
committerWalter Doekes <walter+asterisk@wjd.nu>2015-11-25 20:29:42 +0100
commitb2787876d67cb7d47ce1c7a87db515adcacc151f (patch)
tree40076b7427cc0222c23ea73e98bfe69a85b0c6f6 /main/term.c
parentb75f587d159cb68ed24b6ee1007ed062f669d79f (diff)
main: Slight refactor of main. Improve color situation.
Several issues are addressed here: - main() is large, and half of it is only used if we're not rasterisk; fixed by spliting up the daemon part into a separate function. - Call ast_term_init from rasterisk as well. - Remove duplicate code reading/writing asterisk history file. - Attempt to tackle background color issues and color changes that occur. Tested by starting asterisk -c until the colors stopped changing at odd locations. ASTERISK-25585 #close Change-Id: Ib641a0964c59ef9fe6f59efa8ccb481a9580c52f
Diffstat (limited to 'main/term.c')
-rw-r--r--main/term.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/main/term.c b/main/term.c
index 871a7cb3c..6a1a64533 100644
--- a/main/term.c
+++ b/main/term.c
@@ -175,16 +175,14 @@ end:
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 if (ast_opt_force_black_background) {
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);
} 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);
+ snprintf(enddata, sizeof(enddata), "%c[%dm", ESC, ATTR_RESET);
}
+ snprintf(quitdata, sizeof(quitdata), "%c[%dm", ESC, ATTR_RESET);
}
return 0;
}
@@ -216,9 +214,12 @@ char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int
}
if (ast_opt_force_black_background) {
- snprintf(outbuf, maxout, "%c[%d;%d;%dm%s%c[%d;%dm", ESC, attr, fgcolor, bgcolor + 10, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
+ if (!bgcolor) {
+ bgcolor = COLOR_BLACK;
+ }
+ snprintf(outbuf, maxout, "%c[%d;%d;%dm%s%s", ESC, attr, fgcolor, bgcolor + 10, inbuf, term_end());
} else {
- snprintf(outbuf, maxout, "%c[%d;%dm%s%c[0m", ESC, attr, fgcolor, inbuf, ESC);
+ snprintf(outbuf, maxout, "%c[%d;%dm%s%s", ESC, attr, fgcolor, inbuf, term_end());
}
return outbuf;
}
@@ -242,16 +243,16 @@ static void check_bgcolor(int *bgcolor)
}
}
-static int check_colors_allowed(int fgcolor)
+static int check_colors_allowed(void)
{
- return (!vt100compat || !fgcolor) ? 0 : 1;
+ return vt100compat;
}
int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor)
{
int attr = 0;
- if (!check_colors_allowed(fgcolor)) {
+ if (!check_colors_allowed()) {
return -1;
}
@@ -273,7 +274,7 @@ char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
{
int attr = 0;
- if (!check_colors_allowed(fgcolor)) {
+ if (!check_colors_allowed()) {
*outbuf = '\0';
return outbuf;
}
@@ -310,11 +311,7 @@ const char *ast_term_color(int fgcolor, int bgcolor)
const char *ast_term_reset(void)
{
- if (ast_opt_force_black_background) {
- return enddata;
- } else {
- return quitdata;
- }
+ return term_end();
}
char *term_strip(char *outbuf, const char *inbuf, int maxout)