49 "/usr/share/terminfo",
50 "/usr/local/share/misc/terminfo",
73 return color ? lookup[color - 30] : 0;
81 a = (int) s[0] & 0377;
82 b = (int) s[1] & 0377;
84 if (a == 0377 && b == 0377)
86 if (a == 0376 && b == 0377)
94 char *term = getenv(
"TERM");
95 char termfile[256] =
"";
97 int termfd = -1, parseokay = 0, i;
117 snprintf(termfile,
sizeof(termfile),
"%s/%c/%s",
termpath[i], *term, term);
118 termfd = open(termfile, O_RDONLY);
124 int actsize = read(termfd, buffer,
sizeof(buffer) - 1);
132 if (sz_names + sz_bools + n_nums < actsize) {
135 short max_colors =
convshort(buffer + 12 + sz_names + sz_bools + 13 * 2);
136 if (max_colors > 0) {
150 if (!strcmp(term,
"linux")) {
152 }
else if (!strcmp(term,
"xterm")) {
154 }
else if (!strcmp(term,
"xterm-color")) {
156 }
else if (!strcmp(term,
"xterm-256color")) {
158 }
else if (!strncmp(term,
"Eterm", 5)) {
161 }
else if (!strcmp(term,
"vt100")) {
163 }
else if (!strncmp(term,
"crt", 3)) {
184 char *
term_color(
char *outbuf,
const char *
inbuf,
int fgcolor,
int bgcolor,
int maxout)
214 snprintf(outbuf, maxout,
"%c[%d;%d;%dm%s%s",
ESC, attr, fgcolor, bgcolor + 10, inbuf,
term_end());
216 snprintf(outbuf, maxout,
"%c[%d;%dm%s%s",
ESC, attr, fgcolor, inbuf,
term_end());
224 if (*fgcolor & 128) {
258 }
else if (bgcolor) {
280 snprintf(outbuf, maxout,
"%c[%d;%d;%dm",
ESC, attr, fgcolor,
COLOR_BLACK + 10);
281 }
else if (bgcolor) {
282 snprintf(outbuf, maxout,
"%c[%d;%d;%dm",
ESC, attr, fgcolor, bgcolor + 10);
284 snprintf(outbuf, maxout,
"%c[%d;%dm",
ESC, attr, fgcolor);
313 char *outbuf_ptr = outbuf;
314 const char *inbuf_ptr =
inbuf;
316 while (outbuf_ptr < outbuf + maxout) {
317 switch (*inbuf_ptr) {
319 while (*inbuf_ptr && (*inbuf_ptr !=
'm'))
323 *outbuf_ptr = *inbuf_ptr;
337 int len = strlen(line);
339 for (i = 0; i <
len; i++) {
342 if ((i < (len - 2)) &&
343 (line[i + 1] == 0x5B)) {
344 switch (line[i + 2]) {
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
static void check_fgcolor(int *fgcolor, int *attr)
#define AST_TERM_MAX_ROTATING_BUFFERS
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define ast_opt_force_black_background
static short convshort(char *s)
void term_filter_escapes(char *line)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
Definitions to aid in the use of thread local storage.
#define AST_TERM_MAX_ESCAPE_CHARS
Maximum number of characters needed for a color escape sequence, and another one for a trailing reset...
char * term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
Write a color sequence to a string.
static int check_colors_allowed(void)
const char * ast_term_color(int fgcolor, int bgcolor)
Return a color sequence string.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const char * ast_term_reset(void)
Returns the terminal reset code.
char buffer[AST_TERM_MAX_ROTATING_BUFFERS][AST_TERM_MAX_ESCAPE_CHARS]
const char * term_end(void)
Prototypes for public functions only of internal interest,.
#define ast_opt_light_background
int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor)
Append a color sequence to an ast_str.
static void check_bgcolor(int *bgcolor)
static const char *const termpath[]
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Handy terminal functions for vt* terms.
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
static int opposite(int color)
const char * term_quit(void)