Asterisk - The Open Source Telephony Project  18.5.0
term.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief Handy terminal functions for vt* terms
21  */
22 
23 #ifndef _ASTERISK_TERM_H
24 #define _ASTERISK_TERM_H
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 #define ESC 0x1b
31 
32 /*! \name Terminal Attributes
33 */
34 /*@{ */
35 #define ATTR_RESET 0
36 #define ATTR_BRIGHT 1
37 #define ATTR_DIM 2
38 #define ATTR_UNDER 4
39 #define ATTR_BLINK 5
40 #define ATTR_REVER 7
41 #define ATTR_HIDDEN 8
42 /*@} */
43 
44 /*! \name Terminal Colors
45 */
46 /*@{ */
47 #define COLOR_BLACK 30
48 #define COLOR_GRAY (30 | 128)
49 #define COLOR_RED 31
50 #define COLOR_BRRED (31 | 128)
51 #define COLOR_GREEN 32
52 #define COLOR_BRGREEN (32 | 128)
53 #define COLOR_BROWN 33
54 #define COLOR_YELLOW (33 | 128)
55 #define COLOR_BLUE 34
56 #define COLOR_BRBLUE (34 | 128)
57 #define COLOR_MAGENTA 35
58 #define COLOR_BRMAGENTA (35 | 128)
59 #define COLOR_CYAN 36
60 #define COLOR_BRCYAN (36 | 128)
61 #define COLOR_WHITE 37
62 #define COLOR_BRWHITE (37 | 128)
63 /*@} */
64 
65 /*! \brief Shortcut macros for coloring a set of text
66  */
67 #define COLORIZE_FMT "%s%s%s"
68 #define COLORIZE(fg, bg, str) ast_term_color(fg,bg),str,ast_term_reset()
69 /*! \brief Maximum number of characters needed for a color escape sequence,
70  * and another one for a trailing reset, plus a null char */
71 #define AST_TERM_MAX_ESCAPE_CHARS 23
72 #define AST_TERM_MAX_ROTATING_BUFFERS 15
73 
74 /*! \brief Colorize a specified string by adding terminal color codes
75  *
76  * \param outbuf Result buffer
77  * \param inbuf Starting string
78  * \param fgcolor Foreground color, specified as one of the constants in include/asterisk/term.h. Use '0' if the want the normal terminal foreground color.
79  * \param bgcolor Background color, specified as one of the constants in include/asterisk/term.h. Use '0' if you want the normal terminal background color.
80  * \param maxout Maximum size of outbuf
81  *
82  * \return outbuf
83  *
84  * \deprecated Due to the necessity of pre-sizing a result buffer, new code should avoid using this function in preference to ast_term_color_code() or ast_term_color().
85  */
86 char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout);
87 
88 /*!
89  * \brief Append a color sequence to an ast_str
90  *
91  * \param str The string to append to
92  * \param fgcolor foreground color
93  * \param bgcolor background color
94  *
95  * \retval 0 success
96  * \retval -1 failure
97  */
98 int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor);
99 
100 /*!
101  * \brief Return a color sequence string
102  * \param fgcolor foreground color
103  * \param bgcolor background color
104  * \note This function may be called up to 15 times within the arguments to a single function without the danger of overwriting a common buffer.
105  *
106  * \return A color sequence string, or the empty string, on error
107  */
108 const char *ast_term_color(int fgcolor, int bgcolor);
109 
110 /*!
111  * \brief Returns the terminal reset code
112  * \return String which, when sent to the screen, resets the terminal colors
113  */
114 const char *ast_term_reset(void);
115 
116 /*!
117  * \brief Write a color sequence to a string
118  *
119  * \param outbuf the location to write to
120  * \param fgcolor foreground color
121  * \param bgcolor background color
122  * \param maxout maximum number of characters to write
123  * \deprecated You should use ast_term_color_code or ast_term_color, instead.
124  *
125  * \return outbuf
126  */
127 char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout);
128 
129 /*!
130  * \brief Remove colorings from a specified string
131  * \param outbuf the location to write to
132  * \param inbuf the original string
133  * \param maxout the available size of outbuf
134  * \return outbuf
135  */
136 char *term_strip(char *outbuf, const char *inbuf, int maxout);
137 
138 void term_filter_escapes(char *line);
139 
140 const char *term_end(void);
141 
142 const char *term_quit(void);
143 
144 #if defined(__cplusplus) || defined(c_plusplus)
145 }
146 #endif
147 
148 #endif /* _ASTERISK_TERM_H */
const char * term_quit(void)
Definition: term.c:361
int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor)
Append a color sequence to an ast_str.
Definition: term.c:245
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
Definition: term.c:311
const char * str
Definition: app_jack.c:147
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
const char * term_end(void)
Definition: term.c:356
char * term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
Write a color sequence to a string.
Definition: term.c:267
void term_filter_escapes(char *line)
Definition: term.c:334
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Colorize a specified string by adding terminal color codes.
Definition: term.c:184
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
const char * ast_term_reset(void)
Returns the terminal reset code.
Definition: term.c:306
const char * ast_term_color(int fgcolor, int bgcolor)
Return a color sequence string.
Definition: term.c:290