summaryrefslogtreecommitdiff
path: root/main/term.c
diff options
context:
space:
mode:
authorWalter Doekes <walter+asterisk@wjd.nu>2015-11-25 20:29:55 +0100
committerWalter Doekes <walter+asterisk@wjd.nu>2015-11-25 20:29:55 +0100
commit03759c5587229b95204288e0969f928c20764a6e (patch)
tree723f2e202365b2626b307e6fe25ab22bad7ea075 /main/term.c
parentfb45130476bf2530a189eda5119dd0e817202ac1 (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. - Remove unused term_prep() and term_prompt() functions. ASTERISK-25585 #close Change-Id: Ib641a0964c59ef9fe6f59efa8ccb481a9580c52f
Diffstat (limited to 'main/term.c')
-rw-r--r--main/term.c64
1 files changed, 12 insertions, 52 deletions
diff --git a/main/term.c b/main/term.c
index cf21719ae..11fbe2da9 100644
--- a/main/term.c
+++ b/main/term.c
@@ -44,7 +44,6 @@ ASTERISK_REGISTER_FILE()
static int vt100compat;
-static char prepdata[80] = "";
static char enddata[80] = "";
static char quitdata[80] = "";
@@ -173,18 +172,13 @@ end:
if (vt100compat) {
/* Make commands show up in nice colors */
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 +210,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 +239,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 +270,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 +307,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)
@@ -339,34 +332,6 @@ char *term_strip(char *outbuf, const char *inbuf, int maxout)
return outbuf;
}
-char *term_prompt(char *outbuf, const char *inbuf, int maxout)
-{
- if (!vt100compat) {
- ast_copy_string(outbuf, inbuf, maxout);
- return outbuf;
- }
- if (ast_opt_force_black_background) {
- snprintf(outbuf, maxout, "%c[%d;%d;%dm%c%c[%d;%dm%s",
- ESC, ATTR_BRIGHT, COLOR_BLUE, COLOR_BLACK + 10,
- inbuf[0],
- ESC, COLOR_WHITE, COLOR_BLACK + 10,
- inbuf + 1);
- } else if (ast_opt_light_background) {
- snprintf(outbuf, maxout, "%c[%d;0m%c%c[0m%s",
- ESC, COLOR_BLUE,
- inbuf[0],
- ESC,
- inbuf + 1);
- } else {
- snprintf(outbuf, maxout, "%c[%d;%d;0m%c%c[0m%s",
- ESC, ATTR_BRIGHT, COLOR_BLUE,
- inbuf[0],
- ESC,
- inbuf + 1);
- }
- return outbuf;
-}
-
/* filter escape sequences */
void term_filter_escapes(char *line)
{
@@ -390,11 +355,6 @@ void term_filter_escapes(char *line)
}
}
-const char *term_prep(void)
-{
- return prepdata;
-}
-
const char *term_end(void)
{
return enddata;