From eae2e282472b4c2d73e90d946ab858f1b7494b77 Mon Sep 17 00:00:00 2001 From: markster Date: Sun, 2 May 2004 19:13:16 +0000 Subject: Merge Tilghman's color patches for the asterisk prompt (bug #1535) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2862 f38db490-d61c-443f-a65b-d21fe96a405b --- asterisk.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'asterisk.c') diff --git a/asterisk.c b/asterisk.c index e21f149dc..f7abea070 100755 --- a/asterisk.c +++ b/asterisk.c @@ -884,18 +884,41 @@ static char *cli_prompt(EditLine *el) { static char prompt[200]; char *pfmt; + int color_used=0; + char term_code[20]; if ((pfmt = getenv("ASTERISK_PROMPT"))) { char *t = pfmt, *p = prompt; memset(prompt, 0, sizeof(prompt)); while (*t != '\0' && *p < sizeof(prompt)) { if (*t == '%') { + char hostname[256]; + int i; + struct timeval tv; + struct tm tm; + time_t curtime; + FILE *LOADAVG; + int fgcolor = COLOR_WHITE, bgcolor = COLOR_BLACK; + t++; switch (*t) { - char hostname[256]; - struct timeval tv; - struct tm tm; - FILE *LOADAVG; + case 'C': /* color */ + t++; + if (sscanf(t, "%d;%d%n", &fgcolor, &bgcolor, &i) == 2) { + strncat(p, term_color_code(term_code, fgcolor, bgcolor, sizeof(term_code)),sizeof(prompt) - strlen(prompt)); + t += i - 1; + } else if (sscanf(t, "%d%n", &fgcolor, &i) == 1) { + strncat(p, term_color_code(term_code, fgcolor, 0, sizeof(term_code)),sizeof(prompt) - strlen(prompt)); + t += i - 1; + } + + /* If the color has been reset correctly, then there's no need to reset it later */ + if ((fgcolor == COLOR_WHITE) && (bgcolor == COLOR_BLACK)) { + color_used = 0; + } else { + color_used = 1; + } + break; case 'd': /* date */ memset(&tm, 0, sizeof(struct tm)); gettimeofday(&tv, NULL); @@ -910,6 +933,19 @@ static char *cli_prompt(EditLine *el) strncat(p, "localhost", sizeof(prompt) - strlen(prompt)); } break; + case 'H': /* short hostname */ + if (!gethostname(hostname, sizeof(hostname) - 1)) { + for (i=0;i sizeof(prompt) - strlen(prompt)) { + strncat(prompt + sizeof(prompt) - strlen(term_code) - 1, term_code, strlen(term_code)); + } else { + strncat(p, term_code, sizeof(term_code)); + } + } } else if (remotehostname) snprintf(prompt, sizeof(prompt), ASTERISK_PROMPT2, remotehostname); else -- cgit v1.2.3