Asterisk - The Open Source Telephony Project GIT-master-5782b03
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 <markster@digium.com>
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)
27extern "C" {
28#endif
29
30#define ESC 0x1b
31
32/*! \name Terminal Attributes
33 *
34 * @{
35 */
36#define ATTR_RESET 0
37#define ATTR_BRIGHT 1
38#define ATTR_DIM 2
39#define ATTR_UNDER 4
40#define ATTR_BLINK 5
41#define ATTR_REVER 7
42#define ATTR_HIDDEN 8
43
44/*! @} */
45
46/*! \name Terminal Colors
47 *
48 * @{
49 */
50#define COLOR_BLACK 30
51#define COLOR_GRAY (30 | 128)
52#define COLOR_RED 31
53#define COLOR_BRRED (31 | 128)
54#define COLOR_GREEN 32
55#define COLOR_BRGREEN (32 | 128)
56#define COLOR_BROWN 33
57#define COLOR_YELLOW (33 | 128)
58#define COLOR_BLUE 34
59#define COLOR_BRBLUE (34 | 128)
60#define COLOR_MAGENTA 35
61#define COLOR_BRMAGENTA (35 | 128)
62#define COLOR_CYAN 36
63#define COLOR_BRCYAN (36 | 128)
64#define COLOR_WHITE 37
65#define COLOR_BRWHITE (37 | 128)
66
67/*! @} */
68
69/*! \brief Shortcut macros for coloring a set of text
70 */
71#define COLORIZE_FMT "%s%s%s"
72#define COLORIZE(fg, bg, str) ast_term_color(fg,bg),str,ast_term_reset()
73/*! \brief Maximum number of characters needed for a color escape sequence,
74 * and another one for a trailing reset, plus a null char */
75#define AST_TERM_MAX_ESCAPE_CHARS 23
76#define AST_TERM_MAX_ROTATING_BUFFERS 15
77
78/*! \brief Colorize a specified string by adding terminal color codes
79 *
80 * \param outbuf Result buffer
81 * \param inbuf Starting string
82 * \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.
83 * \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.
84 * \param maxout Maximum size of outbuf
85 *
86 * \return outbuf
87 *
88 * \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().
89 */
90char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout);
91
92/*!
93 * \brief Append a color sequence to an ast_str
94 *
95 * \param str The string to append to
96 * \param fgcolor foreground color
97 * \param bgcolor background color
98 *
99 * \retval 0 success
100 * \retval -1 failure
101 */
102int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor);
103
104/*!
105 * \brief Return a color sequence string
106 * \param fgcolor foreground color
107 * \param bgcolor background color
108 * \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.
109 *
110 * \return A color sequence string, or the empty string, on error
111 */
112const char *ast_term_color(int fgcolor, int bgcolor);
113
114/*!
115 * \brief Returns the terminal reset code
116 * \return String which, when sent to the screen, resets the terminal colors
117 */
118const char *ast_term_reset(void);
119
120/*!
121 * \brief Write a color sequence to a string
122 *
123 * \param outbuf the location to write to
124 * \param fgcolor foreground color
125 * \param bgcolor background color
126 * \param maxout maximum number of characters to write
127 * \deprecated You should use ast_term_color_code or ast_term_color, instead.
128 *
129 * \return outbuf
130 */
131char *term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout);
132
133/*!
134 * \brief Remove colorings from a specified string
135 * \param outbuf the location to write to
136 * \param inbuf the original string
137 * \param maxout the available size of outbuf
138 * \return outbuf
139 */
140char *term_strip(char *outbuf, const char *inbuf, int maxout);
141
142void term_filter_escapes(char *line);
143
144const char *term_end(void);
145
146const char *term_quit(void);
147
148#if defined(__cplusplus) || defined(c_plusplus)
149}
150#endif
151
152#endif /* _ASTERISK_TERM_H */
const char * str
Definition: app_jack.c:147
Support for dynamic strings.
Definition: strings.h:623
const char * term_quit(void)
Definition: term.c:412
int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor)
Append a color sequence to an ast_str.
Definition: term.c:296
const char * ast_term_reset(void)
Returns the terminal reset code.
Definition: term.c:357
const char * ast_term_color(int fgcolor, int bgcolor)
Return a color sequence string.
Definition: term.c:341
const char * term_end(void)
Definition: term.c:407
char * term_color_code(char *outbuf, int fgcolor, int bgcolor, int maxout)
Write a color sequence to a string.
Definition: term.c:318
void term_filter_escapes(char *line)
Definition: term.c:385
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:235
char * term_strip(char *outbuf, const char *inbuf, int maxout)
Remove colorings from a specified string.
Definition: term.c:362
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
Definition: utils.c:590