summaryrefslogtreecommitdiff
path: root/main/asterisk.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2013-02-14 18:47:56 +0000
committerKinsey Moore <kmoore@digium.com>2013-02-14 18:47:56 +0000
commit2e1e0735fe84ddb5536687f2bf5948ff94640423 (patch)
treecbfaeb33a9451bb9af5721f7e098786cc7f0cc17 /main/asterisk.c
parent86a537c2712f99842d1076dc093ce654a76ed55c (diff)
Revamp of terminal color codes
The core module related to coloring terminal output was old and needed some love. The main thing here was an attempt to get rid of the obscene number of stack-local buffers that were allocated for no other reason than to colorize some output. Instead, this uses a simple trick to allocate several buffers within threadlocal storage, then automatically rotates between them, so that you can make multiple calls to the colorization routine within one function and not need to allocate multiple buffers. Review: https://reviewboard.asterisk.org/r/2241/ Patches: bug.patch uploaded by Tilghman Lesher git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@381448 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index f7b62613a..243321dda 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2571,7 +2571,6 @@ static char *cli_prompt(EditLine *editline)
char *pfmt;
int color_used = 0;
static int cli_prompt_changes = 0;
- char term_code[20];
struct passwd *pw;
struct group *gr;
@@ -2598,10 +2597,10 @@ static char *cli_prompt(EditLine *editline)
case 'C': /* color */
t++;
if (sscanf(t, "%30d;%30d%n", &fgcolor, &bgcolor, &i) == 2) {
- ast_str_append(&prompt, 0, "%s", term_color_code(term_code, fgcolor, bgcolor, sizeof(term_code)));
+ ast_term_color_code(&prompt, fgcolor, bgcolor);
t += i - 1;
} else if (sscanf(t, "%30d%n", &fgcolor, &i) == 1) {
- ast_str_append(&prompt, 0, "%s", term_color_code(term_code, fgcolor, 0, sizeof(term_code)));
+ ast_term_color_code(&prompt, fgcolor, 0);
t += i - 1;
}
@@ -2681,7 +2680,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, 0, 0, sizeof(term_code)));
+ ast_term_color_code(&prompt, 0, 0);
}
} else if (remotehostname) {
ast_str_set(&prompt, 0, ASTERISK_PROMPT2, remotehostname);
@@ -3586,7 +3585,6 @@ int main(int argc, char *argv[])
int c;
char filename[80] = "";
char hostname[MAXHOSTNAMELEN] = "";
- char tmp[80];
char * xarg = NULL;
int x;
FILE *f;
@@ -4284,7 +4282,7 @@ int main(int argc, char *argv[])
/* We might have the option of showing a console, but for now just
do nothing... */
- ast_verb(0, "%s\n", term_color(tmp, "Asterisk Ready.", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp)));
+ ast_verb(0, COLORIZE_FMT "\n", COLORIZE(COLOR_BRWHITE, COLOR_BLACK, "Asterisk Ready."));
if (ast_opt_no_fork) {
consolethread = pthread_self();
}