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

Go to the source code of this file.
Defines | |
| #define | AST_TERM_MAX_ESCAPE_CHARS 23 |
| Maximum number of characters needed for a color escape sequence, plus a null char. | |
| #define | ESC 0x1b |
Terminal Attributes | |
| #define | ATTR_RESET 0 |
| #define | ATTR_BRIGHT 1 |
| #define | ATTR_DIM 2 |
| #define | ATTR_UNDER 4 |
| #define | ATTR_BLINK 5 |
| #define | ATTR_REVER 7 |
| #define | ATTR_HIDDEN 8 |
Terminal Colors | |
| #define | COLOR_BLACK 30 |
| #define | COLOR_GRAY (30 | 128) |
| #define | COLOR_RED 31 |
| #define | COLOR_BRRED (31 | 128) |
| #define | COLOR_GREEN 32 |
| #define | COLOR_BRGREEN (32 | 128) |
| #define | COLOR_BROWN 33 |
| #define | COLOR_YELLOW (33 | 128) |
| #define | COLOR_BLUE 34 |
| #define | COLOR_BRBLUE (34 | 128) |
| #define | COLOR_MAGENTA 35 |
| #define | COLOR_BRMAGENTA (35 | 128) |
| #define | COLOR_CYAN 36 |
| #define | COLOR_BRCYAN (36 | 128) |
| #define | COLOR_WHITE 37 |
| #define | COLOR_BRWHITE (37 | 128) |
Functions | |
| int | ast_term_color_code (struct ast_str **str, int fgcolor, int bgcolor) |
| Append a color sequence to an ast_str. | |
| 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) |
| Write a color sequence to a string. | |
| 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, const char *inbuf, int maxout) |
Handy terminal functions for vt* terms.
Definition in file term.h.
| #define AST_TERM_MAX_ESCAPE_CHARS 23 |
Maximum number of characters needed for a color escape sequence, plus a null char.
Definition at line 67 of file term.h.
Referenced by handle_show_function(), print_app_docs(), and handle_cli_agi_show().
| #define ATTR_BRIGHT 1 |
Definition at line 36 of file term.h.
Referenced by ast_term_init(), term_color(), check_fgcolor(), and term_prompt().
| #define ATTR_RESET 0 |
Definition at line 35 of file term.h.
Referenced by ast_term_init().
| #define COLOR_BLACK 30 |
Definition at line 47 of file term.h.
Referenced by cli_prompt(), main(), handle_dahdi_show_cadences(), ast_frame_dump(), start_resource(), opposite(), ast_term_init(), term_color(), ast_term_color_code(), term_color_code(), term_prompt(), __ast_register_translator(), and ast_unregister_translator().
| #define COLOR_BLUE 34 |
Definition at line 55 of file term.h.
Referenced by data_result_get_color(), opposite(), and term_prompt().
| #define COLOR_BRCYAN (36 | 128) |
Definition at line 60 of file term.h.
Referenced by ast_frame_dump(), __ast_custom_function_register(), pbx_extension_helper(), ast_register_application2(), lua_pbx_exec(), and realtime_exec().
| #define COLOR_BRGREEN (32 | 128) |
Definition at line 52 of file term.h.
Referenced by ast_frame_dump().
| #define COLOR_BRMAGENTA (35 | 128) |
Definition at line 58 of file term.h.
Referenced by ast_frame_dump(), pbx_extension_helper(), lua_pbx_exec(), and realtime_exec().
| #define COLOR_BROWN 33 |
Definition at line 53 of file term.h.
Referenced by start_resource(), opposite(), and ast_term_init().
| #define COLOR_BRRED (31 | 128) |
Definition at line 50 of file term.h.
Referenced by ast_frame_dump().
| #define COLOR_BRWHITE (37 | 128) |
Definition at line 62 of file term.h.
Referenced by main(), show_config_description(), and logger_print_normal().
| #define COLOR_CYAN 36 |
Definition at line 59 of file term.h.
Referenced by handle_show_function(), print_app_docs(), handle_cli_agi_show(), opposite(), and ast_xmldoc_printable().
| #define COLOR_GRAY (30 | 128) |
Definition at line 48 of file term.h.
Referenced by fix_header().
| #define COLOR_GREEN 32 |
Definition at line 51 of file term.h.
Referenced by handle_dahdi_show_cadences(), and opposite().
| #define COLOR_MAGENTA 35 |
Definition at line 57 of file term.h.
Referenced by handle_dahdi_show_cadences(), handle_showmancmd(), handle_show_function(), print_app_docs(), handle_cli_agi_show(), opposite(), __ast_register_translator(), and ast_unregister_translator().
| #define COLOR_RED 31 |
Definition at line 49 of file term.h.
Referenced by opposite().
| #define COLOR_WHITE 37 |
Definition at line 61 of file term.h.
Referenced by cli_prompt(), data_result_print_cli_node(), data_result_print_cli(), ast_term_init(), term_color(), and term_prompt().
| #define COLOR_YELLOW (33 | 128) |
Definition at line 54 of file term.h.
Referenced by show_config_description(), and ast_frame_dump().
| #define ESC 0x1b |
Definition at line 30 of file term.h.
Referenced by ast_term_init(), term_color(), ast_term_color_code(), term_color_code(), term_strip(), term_prompt(), term_filter_escapes(), xmldoc_wait_nextspace(), and xmldoc_string_wrap().
| int ast_term_color_code | ( | struct ast_str ** | str, |
| int | fgcolor, | ||
| int | bgcolor | ||
| ) |
Append a color sequence to an ast_str.
| str | The string to append to |
| fgcolor | foreground color |
| bgcolor | background color |
| 0 | success |
| -1 | failure |
Definition at line 238 of file term.c.
References check_colors_allowed(), check_fgcolor(), check_bgcolor(), ast_opt_force_black_background, ast_str_append(), ESC, and COLOR_BLACK.
Referenced by data_result_print_cli_node(), data_result_print_cli(), and ast_xmldoc_printable().
{
int attr = 0;
if (!check_colors_allowed(fgcolor)) {
return -1;
}
check_fgcolor(&fgcolor, &attr);
check_bgcolor(&bgcolor);
if (ast_opt_force_black_background) {
ast_str_append(str, 0, "%c[%d;%d;%dm", ESC, attr, fgcolor, COLOR_BLACK + 10);
} else if (bgcolor) {
ast_str_append(str, 0, "%c[%d;%d;%dm", ESC, attr, fgcolor, bgcolor + 10);
} else {
ast_str_append(str, 0, "%c[%d;%dm", ESC, attr, fgcolor);
}
return 0;
}
| char* term_color | ( | char * | outbuf, |
| const char * | inbuf, | ||
| int | fgcolor, | ||
| int | bgcolor, | ||
| int | maxout | ||
| ) |
Definition at line 180 of file term.c.
References ast_copy_string(), ast_opt_light_background, ATTR_BRIGHT, opposite(), ast_opt_force_black_background, ESC, COLOR_WHITE, and COLOR_BLACK.
Referenced by fix_header(), main(), handle_dahdi_show_cadences(), show_config_description(), ast_frame_dump(), start_resource(), logger_print_normal(), handle_showmancmd(), handle_show_function(), __ast_custom_function_register(), pbx_extension_helper(), ast_register_application2(), print_app_docs(), lua_pbx_exec(), realtime_exec(), handle_cli_agi_show(), __ast_register_translator(), and ast_unregister_translator().
{
int attr = 0;
if (!vt100compat) {
ast_copy_string(outbuf, inbuf, maxout);
return outbuf;
}
if (!fgcolor) {
ast_copy_string(outbuf, inbuf, maxout);
return outbuf;
}
if (fgcolor & 128) {
attr = ast_opt_light_background ? 0 : ATTR_BRIGHT;
fgcolor &= ~128;
}
if (bgcolor) {
bgcolor &= ~128;
}
if (ast_opt_light_background) {
fgcolor = opposite(fgcolor);
}
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);
} else {
snprintf(outbuf, maxout, "%c[%d;%dm%s%c[0m", ESC, attr, fgcolor, inbuf, ESC);
}
return outbuf;
}
| char* term_color_code | ( | char * | outbuf, |
| int | fgcolor, | ||
| int | bgcolor, | ||
| int | maxout | ||
| ) |
Write a color sequence to a string.
| outbuf | the location to write to |
| fgcolor | foreground color |
| bgcolor | background color |
| maxout | maximum number of characters to write |
Definition at line 260 of file term.c.
References check_colors_allowed(), check_fgcolor(), check_bgcolor(), ast_opt_force_black_background, ESC, and COLOR_BLACK.
Referenced by cli_prompt().
{
int attr = 0;
if (!check_colors_allowed(fgcolor)) {
*outbuf = '\0';
return outbuf;
}
check_fgcolor(&fgcolor, &attr);
check_bgcolor(&bgcolor);
if (ast_opt_force_black_background) {
snprintf(outbuf, maxout, "%c[%d;%d;%dm", ESC, attr, fgcolor, COLOR_BLACK + 10);
} else if (bgcolor) {
snprintf(outbuf, maxout, "%c[%d;%d;%dm", ESC, attr, fgcolor, bgcolor + 10);
} else {
snprintf(outbuf, maxout, "%c[%d;%dm", ESC, attr, fgcolor);
}
return outbuf;
}
| char* term_end | ( | void | ) |
Definition at line 361 of file term.c.
References enddata.
Referenced by consolehandler(), main(), and ast_xmldoc_printable().
{
return enddata;
}
| void term_filter_escapes | ( | char * | line | ) |
| char* term_prep | ( | void | ) |
| char* term_prompt | ( | char * | outbuf, |
| const char * | inbuf, | ||
| int | maxout | ||
| ) |
Definition at line 305 of file term.c.
References ast_copy_string(), ast_opt_force_black_background, ESC, COLOR_BLUE, COLOR_BLACK, COLOR_WHITE, ast_opt_light_background, and ATTR_BRIGHT.
{
if (!vt100compat) {
ast_copy_string(outbuf, inbuf, maxout);
return outbuf;
}
if (ast_opt_force_black_background) {
snprintf(outbuf, maxout, "%c[%d;%dm%c%c[%d;%dm%s",
ESC, 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[%d;0m%s",
ESC, COLOR_BLUE,
inbuf[0],
ESC, COLOR_BLACK,
inbuf + 1);
} else {
snprintf(outbuf, maxout, "%c[%d;%d;0m%c%c[%d;%d;0m%s",
ESC, ATTR_BRIGHT, COLOR_BLUE,
inbuf[0],
ESC, 0, COLOR_WHITE,
inbuf + 1);
}
return outbuf;
}
| char* term_quit | ( | void | ) |
Definition at line 366 of file term.c.
References quitdata.
Referenced by quit_handler(), ast_el_read_char(), and main().
{
return quitdata;
}
| char* term_strip | ( | char * | outbuf, |
| const char * | inbuf, | ||
| int | maxout | ||
| ) |
Definition at line 283 of file term.c.
Referenced by ast_log_vsyslog(), logger_print_normal(), and action_command().
{
char *outbuf_ptr = outbuf;
const char *inbuf_ptr = inbuf;
while (outbuf_ptr < outbuf + maxout) {
switch (*inbuf_ptr) {
case ESC:
while (*inbuf_ptr && (*inbuf_ptr != 'm'))
inbuf_ptr++;
break;
default:
*outbuf_ptr = *inbuf_ptr;
outbuf_ptr++;
}
if (! *inbuf_ptr)
break;
inbuf_ptr++;
}
return outbuf;
}