添加printf的颜色

Change-Id: I2faeb3009273b32f9391a2982cf529330d88fe8d
This commit is contained in:
weidonglin 2021-10-10 16:56:54 +08:00
parent 4512803541
commit 967d546131
3 changed files with 40 additions and 1 deletions

View File

@ -152,6 +152,27 @@ static int cmd_ctr_q(void* pv)
return 0;
}
static void cmd_print_color(int argc, char* argv[])
{
xcmd_print(TX_DEF "txt_color = DEF \r\n" TX_DEF);
xcmd_print(TX_RED "txt_color = RED \r\n" TX_DEF);
xcmd_print(TX_BLACK "txt_color = BLACK \r\n" TX_DEF);
xcmd_print(TX_GREEN "txt_color = GREEN \r\n" TX_DEF);
xcmd_print(TX_YELLOW "txt_color = YELLOW \r\n" TX_DEF);
xcmd_print(TX_BLUE "txt_color = BLUE \r\n" TX_DEF);
xcmd_print(TX_WHITE "txt_color = WHITE \r\n" TX_DEF);
xcmd_print(TX_WHITE "txt_color = WHITE \r\n" TX_DEF);
xcmd_print(BK_DEF "background_color = BK_DEF" BK_DEF "\r\n");
xcmd_print(BK_BLACK "background_color = BK_BLACK" BK_DEF "\r\n");
xcmd_print(BK_RED "background_color = BK_RED" BK_DEF "\r\n");
xcmd_print(BK_GREEN "background_color = BK_GREEN" BK_DEF "\r\n");
xcmd_print(BK_YELLOW "background_color = BK_YELLOW" BK_DEF "\r\n");
xcmd_print(BK_BLUE "background_color = BK_BLUE" BK_DEF "\r\n");
xcmd_print(BK_WHITE "background_color = BK_WHITE" BK_DEF "\r\n");
}
static xcmd_t cmds[] =
{
{"echo", cmd_echo, "echo [msg]", NULL},
@ -159,6 +180,7 @@ static xcmd_t cmds[] =
{"example", cmd_example, "example [-f|-i|-s] [val]", NULL},
{"delcmd", cmd_delete_cmd, "delete cmd [val]", NULL},
{"delkey", cmd_delete_key, "delete key [val]", NULL},
{"color", cmd_print_color, "printf color text", NULL},
};
static xcmd_key_t keys[] =

View File

@ -96,6 +96,24 @@ extern "C" {
#define IL(n) "\x1B[%dL",n /* 插入行 将 <n> 行插入光标位置的缓冲区。 光标所在的行及其下方的行将向下移动。*/
#define DL(n) "\x1B[%dM",n /* 删除行 从缓冲区中删除 <n> 行,从光标所在的行开始。*/
/* 打印字体颜色设置 */
#define TX_DEF "\x1b[0m"
#define TX_BLACK "\x1b[30m"
#define TX_RED "\x1b[31m"
#define TX_GREEN "\x1b[32m"
#define TX_YELLOW "\x1b[33m"
#define TX_BLUE "\x1b[34m"
#define TX_WHITE "\x1b[37m"
/* 打印背景颜色设置 */
#define BK_DEF "\x1b[0m"
#define BK_BLACK "\x1b[40m"
#define BK_RED "\x1b[41m"
#define BK_GREEN "\x1b[42m"
#define BK_YELLOW "\x1b[43m"
#define BK_BLUE "\x1b[44m"
#define BK_WHITE "\x1b[47m"
#ifdef __cplusplus
}
#endif

View File

@ -6,7 +6,6 @@
#include <stdio.h>
#include <string.h>
#define CMD_IS_ENDLINE(c) ((c == '\n') || (c == '\r'))
#define CMD_IS_END_KEY(c) ( ((c >= 'A') && (c <= 'D')) || ((c >= 'P') && (c <= 'S')) || \
(c == '~') || (c == 'H') || (c == 'F'))