mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-19 08:11:21 +00:00
Revamp of terminal color codes
The core module related to coloring terminal output was old and needed some love. The main thing here was an attempt to get rid of the obscene number of stack-local buffers that were allocated for no other reason than to colorize some output. Instead, this uses a simple trick to allocate several buffers within threadlocal storage, then automatically rotates between them, so that you can make multiple calls to the colorization routine within one function and not need to allocate multiple buffers. Review: https://reviewboard.asterisk.org/r/2241/ Patches: bug.patch uploaded by Tilghman Lesher git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@381448 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
16
main/data.c
16
main/data.c
@@ -2797,7 +2797,7 @@ static void data_result_print_cli_node(int fd, const struct ast_data *node, uint
|
||||
|
||||
ast_free(tabs);
|
||||
|
||||
ast_term_color_code(&output, COLOR_WHITE, 0);
|
||||
ast_term_color_code(&output, 0, 0);
|
||||
|
||||
ast_cli(fd, "%s", ast_str_buffer(output));
|
||||
|
||||
@@ -2840,19 +2840,7 @@ static void __data_result_print_cli(int fd, const struct ast_data *root, uint32_
|
||||
*/
|
||||
static void data_result_print_cli(int fd, const struct ast_data *root)
|
||||
{
|
||||
struct ast_str *output;
|
||||
|
||||
/* print the initial node. */
|
||||
output = ast_str_create(30);
|
||||
if (!output) {
|
||||
return;
|
||||
}
|
||||
|
||||
ast_term_color_code(&output, data_result_get_color(root->type), 0);
|
||||
ast_str_append(&output, 0, "%s\n", root->name);
|
||||
ast_term_color_code(&output, COLOR_WHITE, 0);
|
||||
ast_cli(fd, "%s", ast_str_buffer(output));
|
||||
ast_free(output);
|
||||
ast_cli(fd, COLORIZE_FMT "\n", COLORIZE(data_result_get_color(root->type), 0, root->name));
|
||||
|
||||
__data_result_print_cli(fd, root, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user