Sat Aug 6 00:40:06 2011

Asterisk developer's documentation


term.h File Reference

Handy terminal functions for vt* terms. More...

Go to the source code of this file.

Defines

#define ATTR_BLINK   5
#define ATTR_BRIGHT   1
#define ATTR_DIM   2
#define ATTR_HIDDEN   8
#define ATTR_RESET   0
#define ATTR_REVER   7
#define ATTR_UNDER   4
#define COLOR_BLACK   30
#define COLOR_BLUE   34
#define COLOR_BRBLUE   (34 | 128)
#define COLOR_BRCYAN   (36 | 128)
#define COLOR_BRGREEN   (32 | 128)
#define COLOR_BRMAGENTA   (35 | 128)
#define COLOR_BROWN   33
#define COLOR_BRRED   (31 | 128)
#define COLOR_BRWHITE   (37 | 128)
#define COLOR_CYAN   36
#define COLOR_GRAY   (30 | 128)
#define COLOR_GREEN   32
#define COLOR_MAGENTA   35
#define COLOR_RED   31
#define COLOR_WHITE   37
#define COLOR_YELLOW   (33 | 128)
#define ESC   0x1b

Functions

char * term_color (char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
char * term_color_code (char *outbuf, int fgcolor, int bgcolor, int maxout)
char * term_end (void)
void term_filter_escapes (char *line)
char * term_prep (void)
char * term_prompt (char *outbuf, const char *inbuf, int maxout)
char * term_quit (void)
char * term_strip (char *outbuf, char *inbuf, int maxout)


Detailed Description

Handy terminal functions for vt* terms.

Definition in file term.h.


Define Documentation

#define ATTR_BLINK   5

Definition at line 35 of file term.h.

#define ATTR_BRIGHT   1

Definition at line 32 of file term.h.

Referenced by ast_term_init(), term_color(), term_color_code(), and term_prompt().

#define ATTR_DIM   2

Definition at line 33 of file term.h.

#define ATTR_HIDDEN   8

Definition at line 37 of file term.h.

#define ATTR_RESET   0

Definition at line 31 of file term.h.

Referenced by ast_term_init().

#define ATTR_REVER   7

Definition at line 36 of file term.h.

#define ATTR_UNDER   4

Definition at line 34 of file term.h.

#define COLOR_BLACK   30

Definition at line 39 of file term.h.

Referenced by __ast_register_translator(), ast_frame_dump(), ast_term_init(), ast_unregister_translator(), cli_prompt(), handle_dahdi_show_cadences(), load_resource(), main(), term_color(), term_color_code(), and term_prompt().

#define COLOR_BLUE   34

Definition at line 47 of file term.h.

Referenced by term_prompt().

#define COLOR_BRBLUE   (34 | 128)

Definition at line 48 of file term.h.

#define COLOR_BRCYAN   (36 | 128)

Definition at line 52 of file term.h.

Referenced by ast_frame_dump(), ast_register_application(), pbx_extension_helper(), and realtime_exec().

#define COLOR_BRGREEN   (32 | 128)

Definition at line 44 of file term.h.

Referenced by ast_frame_dump().

#define COLOR_BRMAGENTA   (35 | 128)

Definition at line 50 of file term.h.

Referenced by ast_frame_dump(), pbx_extension_helper(), and realtime_exec().

#define COLOR_BROWN   33

Definition at line 45 of file term.h.

Referenced by ast_term_init(), and load_resource().

#define COLOR_BRRED   (31 | 128)

Definition at line 42 of file term.h.

Referenced by ast_frame_dump().

#define COLOR_BRWHITE   (37 | 128)

Definition at line 54 of file term.h.

Referenced by ast_log(), main(), and show_config_description().

#define COLOR_CYAN   36

Definition at line 51 of file term.h.

Referenced by handle_show_application(), handle_show_application_deprecated(), handle_show_function(), and handle_show_function_deprecated().

#define COLOR_GRAY   (30 | 128)

Definition at line 40 of file term.h.

Referenced by fix_header().

#define COLOR_GREEN   32

Definition at line 43 of file term.h.

Referenced by handle_dahdi_show_cadences().

#define COLOR_MAGENTA   35

Definition at line 49 of file term.h.

Referenced by __ast_register_translator(), ast_unregister_translator(), handle_dahdi_show_cadences(), handle_show_application(), handle_show_application_deprecated(), handle_show_function(), and handle_show_function_deprecated().

#define COLOR_RED   31

Definition at line 41 of file term.h.

#define COLOR_WHITE   37

Definition at line 53 of file term.h.

Referenced by ast_term_init(), cli_prompt(), term_color(), and term_prompt().

#define COLOR_YELLOW   (33 | 128)

Definition at line 46 of file term.h.

Referenced by ast_frame_dump(), and show_config_description().

#define ESC   0x1b

Definition at line 30 of file term.h.

Referenced by ast_term_init(), term_color(), term_color_code(), term_filter_escapes(), term_prompt(), and term_strip().


Function Documentation

char* term_color ( char *  outbuf,
const char *  inbuf,
int  fgcolor,
int  bgcolor,
int  maxout 
)

Definition at line 160 of file term.c.

References ast_copy_string(), ATTR_BRIGHT, COLOR_BLACK, COLOR_WHITE, and ESC.

Referenced by __ast_register_translator(), ast_frame_dump(), ast_log(), ast_register_application(), ast_unregister_translator(), fix_header(), handle_dahdi_show_cadences(), handle_show_application(), handle_show_application_deprecated(), handle_show_function(), handle_show_function_deprecated(), load_resource(), main(), pbx_extension_helper(), realtime_exec(), and show_config_description().

00161 {
00162    int attr=0;
00163    char tmp[40];
00164    if (!vt100compat) {
00165       ast_copy_string(outbuf, inbuf, maxout);
00166       return outbuf;
00167    }
00168    if (!fgcolor && !bgcolor) {
00169       ast_copy_string(outbuf, inbuf, maxout);
00170       return outbuf;
00171    }
00172    if ((fgcolor & 128) && (bgcolor & 128)) {
00173       /* Can't both be highlighted */
00174       ast_copy_string(outbuf, inbuf, maxout);
00175       return outbuf;
00176    }
00177    if (!bgcolor)
00178       bgcolor = COLOR_BLACK;
00179 
00180    if (bgcolor) {
00181       bgcolor &= ~128;
00182       bgcolor += 10;
00183    }
00184    if (fgcolor & 128) {
00185       attr = ATTR_BRIGHT;
00186       fgcolor &= ~128;
00187    }
00188    if (fgcolor && bgcolor) {
00189       snprintf(tmp, sizeof(tmp), "%d;%d", fgcolor, bgcolor);
00190    } else if (bgcolor) {
00191       snprintf(tmp, sizeof(tmp), "%d", bgcolor);
00192    } else if (fgcolor) {
00193       snprintf(tmp, sizeof(tmp), "%d", fgcolor);
00194    }
00195    if (attr) {
00196       snprintf(outbuf, maxout, "%c[%d;%sm%s%c[0;%d;%dm", ESC, attr, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
00197    } else {
00198       snprintf(outbuf, maxout, "%c[%sm%s%c[0;%d;%dm", ESC, tmp, inbuf, ESC, COLOR_WHITE, COLOR_BLACK + 10);
00199    }
00200    return outbuf;
00201 }

char* term_color_code ( char *  outbuf,
int  fgcolor,
int  bgcolor,
int  maxout 
)

Definition at line 203 of file term.c.

References ATTR_BRIGHT, COLOR_BLACK, and ESC.

Referenced by cli_prompt().

00204 {
00205    int attr=0;
00206    char tmp[40];
00207    if ((!vt100compat) || (!fgcolor && !bgcolor)) {
00208       *outbuf = '\0';
00209       return outbuf;
00210    }
00211    if ((fgcolor & 128) && (bgcolor & 128)) {
00212       /* Can't both be highlighted */
00213       *outbuf = '\0';
00214       return outbuf;
00215    }
00216    if (!bgcolor)
00217       bgcolor = COLOR_BLACK;
00218 
00219    if (bgcolor) {
00220       bgcolor &= ~128;
00221       bgcolor += 10;
00222    }
00223    if (fgcolor & 128) {
00224       attr = ATTR_BRIGHT;
00225       fgcolor &= ~128;
00226    }
00227    if (fgcolor && bgcolor) {
00228       snprintf(tmp, sizeof(tmp), "%d;%d", fgcolor, bgcolor);
00229    } else if (bgcolor) {
00230       snprintf(tmp, sizeof(tmp), "%d", bgcolor);
00231    } else if (fgcolor) {
00232       snprintf(tmp, sizeof(tmp), "%d", fgcolor);
00233    }
00234    if (attr) {
00235       snprintf(outbuf, maxout, "%c[%d;%sm", ESC, attr, tmp);
00236    } else {
00237       snprintf(outbuf, maxout, "%c[%sm", ESC, tmp);
00238    }
00239    return outbuf;
00240 }

char* term_end ( void   ) 

Definition at line 305 of file term.c.

Referenced by consolehandler(), and main().

00306 {
00307    return enddata;
00308 }

void term_filter_escapes ( char *  line  ) 

Definition at line 278 of file term.c.

References ESC, and len().

Referenced by ast_log(), and ast_verbose().

00279 {
00280    int i;
00281    int len = strlen(line);
00282 
00283    for (i = 0; i < len; i++) {
00284       if (line[i] != ESC)
00285          continue;
00286       if ((i < (len - 2)) &&
00287           (line[i + 1] == 0x5B)) {
00288          switch (line[i + 2]) {
00289          case 0x30:
00290          case 0x31:
00291          case 0x33:
00292             continue;
00293          }
00294       }
00295       /* replace ESC with a space */
00296       line[i] = ' ';
00297    }
00298 }

char* term_prep ( void   ) 

Definition at line 300 of file term.c.

00301 {
00302    return prepdata;
00303 }

char* term_prompt ( char *  outbuf,
const char *  inbuf,
int  maxout 
)

Definition at line 263 of file term.c.

References ast_copy_string(), ATTR_BRIGHT, COLOR_BLACK, COLOR_BLUE, COLOR_WHITE, and ESC.

00264 {
00265    if (!vt100compat) {
00266       ast_copy_string(outbuf, inbuf, maxout);
00267       return outbuf;
00268    }
00269    snprintf(outbuf, maxout, "%c[%d;%d;%dm%c%c[%d;%d;%dm%s",
00270       ESC, ATTR_BRIGHT, COLOR_BLUE, COLOR_BLACK + 10,
00271       inbuf[0],
00272       ESC, 0, COLOR_WHITE, COLOR_BLACK + 10,
00273       inbuf + 1);
00274    return outbuf;
00275 }

char* term_quit ( void   ) 

Definition at line 310 of file term.c.

Referenced by ast_el_read_char(), main(), and quit_handler().

00311 {
00312    return quitdata;
00313 }

char* term_strip ( char *  outbuf,
char *  inbuf,
int  maxout 
)

Definition at line 242 of file term.c.

References ESC.

Referenced by __verboser(), action_command(), ast_log(), and ast_log_vsyslog().

00243 {
00244    char *outbuf_ptr = outbuf, *inbuf_ptr = inbuf;
00245 
00246    while (outbuf_ptr < outbuf + maxout) {
00247       switch (*inbuf_ptr) {
00248          case ESC:
00249             while (*inbuf_ptr && (*inbuf_ptr != 'm'))
00250                inbuf_ptr++;
00251             break;
00252          default:
00253             *outbuf_ptr = *inbuf_ptr;
00254             outbuf_ptr++;
00255       }
00256       if (! *inbuf_ptr)
00257          break;
00258       inbuf_ptr++;
00259    }
00260    return outbuf;
00261 }


Generated on Sat Aug 6 00:40:06 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7