34 #include "asterisk/_private.h"
51 "/usr/share/terminfo",
52 "/usr/local/share/misc/terminfo",
68 return color ? lookup[color - 30] : 0;
76 a = (int) s[0] & 0377;
77 b = (int) s[1] & 0377;
79 if (a == 0377 && b == 0377)
81 if (a == 0376 && b == 0377)
89 char *term = getenv(
"TERM");
90 char termfile[256] =
"";
91 char buffer[512] =
"";
92 int termfd = -1, parseokay = 0, i;
109 if (termpath[i] == NULL) {
112 snprintf(termfile,
sizeof(termfile),
"%s/%c/%s", termpath[i], *term, term);
113 termfd = open(termfile, O_RDONLY);
119 int actsize = read(termfd, buffer,
sizeof(buffer) - 1);
127 if (sz_names + sz_bools + n_nums < actsize) {
130 short max_colors =
convshort(buffer + 12 + sz_names + sz_bools + 13 * 2);
131 if (max_colors > 0) {
145 if (!strcmp(term,
"linux")) {
147 }
else if (!strcmp(term,
"xterm")) {
149 }
else if (!strcmp(term,
"xterm-color")) {
151 }
else if (!strcmp(term,
"xterm-256color")) {
153 }
else if (!strncmp(term,
"Eterm", 5)) {
156 }
else if (!strcmp(term,
"vt100")) {
158 }
else if (!strncmp(term,
"crt", 3)) {
170 snprintf(quitdata,
sizeof(quitdata),
"%c[0m",
ESC);
174 snprintf(quitdata,
sizeof(quitdata),
"%c[0m",
ESC);
178 snprintf(quitdata,
sizeof(quitdata),
"%c[0m",
ESC);
184 char *
term_color(
char *outbuf,
const char *
inbuf,
int fgcolor,
int bgcolor,
int maxout)
211 snprintf(outbuf, maxout,
"%c[%d;%d;%dm%s%c[%d;%dm",
ESC, attr, fgcolor, bgcolor + 10, inbuf,
ESC,
COLOR_WHITE,
COLOR_BLACK + 10);
213 snprintf(outbuf, maxout,
"%c[%d;%dm%s%c[0m",
ESC, attr, fgcolor, inbuf,
ESC);
220 if (*fgcolor & 128) {
239 return (!vt100compat || !fgcolor) ? 0 : 1;
255 }
else if (bgcolor) {
277 snprintf(outbuf, maxout,
"%c[%d;%d;%dm",
ESC, attr, fgcolor,
COLOR_BLACK + 10);
278 }
else if (bgcolor) {
279 snprintf(outbuf, maxout,
"%c[%d;%d;%dm",
ESC, attr, fgcolor, bgcolor + 10);
281 snprintf(outbuf, maxout,
"%c[%d;%dm",
ESC, attr, fgcolor);
289 char *outbuf_ptr = outbuf;
290 const char *inbuf_ptr =
inbuf;
292 while (outbuf_ptr < outbuf + maxout) {
293 switch (*inbuf_ptr) {
295 while (*inbuf_ptr && (*inbuf_ptr !=
'm'))
299 *outbuf_ptr = *inbuf_ptr;
316 snprintf(outbuf, maxout,
"%c[%d;%dm%c%c[%d;%dm%s",
322 snprintf(outbuf, maxout,
"%c[%d;0m%c%c[%d;0m%s",
328 snprintf(outbuf, maxout,
"%c[%d;%d;0m%c%c[%d;%d;0m%s",
341 int len = strlen(line);
343 for (i = 0; i <
len; i++) {
346 if ((i < (len - 2)) &&
347 (line[i + 1] == 0x5B)) {
348 switch (line[i + 2]) {
static void check_fgcolor(int *fgcolor, int *attr)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define ast_opt_force_black_background
static short convshort(char *s)
int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor)
Append a color sequence to an ast_str.
char * term_strip(char *outbuf, const char *inbuf, int maxout)
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()
char * term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
Write a color sequence to a string.
void term_filter_escapes(char *line)
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_opt_light_background
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.
char * term_prompt(char *outbuf, const char *inbuf, int maxout)
Handy terminal functions for vt* terms.
static int opposite(int color)
static int check_colors_allowed(int fgcolor)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.