修改xcmd_display_print函数,添加xcmd_put_str函数
This commit is contained in:
parent
1bf105f844
commit
492c9eee10
|
@ -14,8 +14,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int(*cmd_func_t)(int argv, char* argc[]);
|
||||
typedef int(*cmd_key_func_t)(void *data);
|
||||
typedef int(*cmd_func_t)(int, char**);
|
||||
typedef int(*cmd_key_func_t)(void *);
|
||||
|
||||
typedef struct __cmd
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ int xcmd_exec(char *str);
|
|||
* @return 无
|
||||
*/
|
||||
void xcmd_print(const char *fmt, ...);
|
||||
|
||||
void xcmd_put_str(const char *str);
|
||||
|
||||
/**
|
||||
* @description: 向显示器插入一个字符
|
||||
|
@ -150,7 +150,7 @@ char* xcmd_display_get(void);
|
|||
* @param {char*} 要现实的内容
|
||||
* @return 无
|
||||
*/
|
||||
void xcmd_display_print(const char *msg);
|
||||
void xcmd_display_print(const char *fmt, ...);
|
||||
void xcmd_display_write(const char* buf, uint16_t len);
|
||||
|
||||
/**
|
||||
|
|
42
src/xcmd.c
42
src/xcmd.c
|
@ -206,8 +206,10 @@ static void xcmd_key_match(char* key)
|
|||
{
|
||||
if(strcmp(key, p->key) == 0)
|
||||
{
|
||||
p->func(&g_xcmder);
|
||||
break;
|
||||
if(p->func(&g_xcmder) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
|
@ -313,6 +315,14 @@ static void xcmd_parser(uint8_t byte)
|
|||
}
|
||||
}
|
||||
|
||||
void xcmd_put_str(const char *str)
|
||||
{
|
||||
for(uint16_t i=0; str[i]; i++)
|
||||
{
|
||||
g_xcmder.io.put_c(str[i]);
|
||||
};
|
||||
}
|
||||
|
||||
void xcmd_print(const char *fmt, ...)
|
||||
{
|
||||
char ucstring[XCMD_PRINT_BUF_MAX_LENGTH] = {0};
|
||||
|
@ -320,12 +330,7 @@ void xcmd_print(const char *fmt, ...)
|
|||
va_start(arg, fmt);
|
||||
vsnprintf(ucstring, XCMD_PRINT_BUF_MAX_LENGTH, fmt, arg);
|
||||
va_end(arg);
|
||||
|
||||
for(uint16_t i=0; ucstring[i]; i++)
|
||||
{
|
||||
g_xcmder.io.put_c(ucstring[i]);
|
||||
};
|
||||
return;
|
||||
xcmd_put_str(ucstring);
|
||||
}
|
||||
|
||||
void xcmd_display_write(const char* buf, uint16_t len)
|
||||
|
@ -337,18 +342,21 @@ void xcmd_display_write(const char* buf, uint16_t len)
|
|||
}
|
||||
memcpy(g_xcmder.parser.display_line, buf, len);
|
||||
g_xcmder.parser.display_line[len] = '\0';
|
||||
xcmd_print(g_xcmder.parser.display_line);
|
||||
xcmd_put_str(g_xcmder.parser.display_line);
|
||||
g_xcmder.parser.byte_num = len;
|
||||
g_xcmder.parser.cursor = len;
|
||||
}
|
||||
|
||||
void xcmd_display_print(const char *msg)
|
||||
void xcmd_display_print(const char *fmt, ...)
|
||||
{
|
||||
xcmd_display_write(msg, strlen(msg));
|
||||
char ucstring[XCMD_PRINT_BUF_MAX_LENGTH] = {0};
|
||||
va_list arg;
|
||||
va_start(arg, fmt);
|
||||
vsnprintf(ucstring, XCMD_PRINT_BUF_MAX_LENGTH, fmt, arg);
|
||||
va_end(arg);
|
||||
xcmd_display_write(ucstring, strlen(ucstring));
|
||||
}
|
||||
|
||||
|
||||
|
||||
char* xcmd_display_get(void)
|
||||
{
|
||||
char *line = g_xcmder.parser.display_line;
|
||||
|
@ -358,11 +366,13 @@ char* xcmd_display_get(void)
|
|||
void xcmd_display_clear(void)
|
||||
{
|
||||
char *line = xcmd_display_get();
|
||||
xcmd_print(DL(0));
|
||||
xcmd_put_str("\x1B[0M");
|
||||
#ifndef XCMD_DEFAULT_PROMPT_CLOLR
|
||||
xcmd_print("%s", xcmd_get_prompt());
|
||||
xcmd_put_str(xcmd_get_prompt());
|
||||
#else
|
||||
xcmd_print(XCMD_DEFAULT_PROMPT_CLOLR "%s" TX_DEF, xcmd_get_prompt());
|
||||
xcmd_put_str(XCMD_DEFAULT_PROMPT_CLOLR);
|
||||
xcmd_put_str(xcmd_get_prompt());
|
||||
xcmd_put_str(TX_DEF);
|
||||
#endif
|
||||
g_xcmder.parser.byte_num = 0;
|
||||
g_xcmder.parser.cursor = 0;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-09-15 00:11:50
|
||||
* @LastEditTime: 2021-10-11 21:38:26
|
||||
* @LastEditTime: 2021-10-12 14:58:23
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /xcmd/src/xcmd_default_keys.c
|
||||
|
@ -133,7 +133,7 @@ static int xcmd_auto_completion(void *pv)
|
|||
|
||||
if(match_num == 1)
|
||||
{
|
||||
xcmd_display_print(match_cmd_first->name);
|
||||
xcmd_display_print("%s ", match_cmd_first->name);
|
||||
}
|
||||
else if(match_num > 1)
|
||||
{
|
||||
|
@ -146,6 +146,7 @@ static int xcmd_auto_completion(void *pv)
|
|||
static xcmd_key_t default_keys[] =
|
||||
{
|
||||
{KEY_CTR_M, xcmd_enter, "enter", NULL},
|
||||
{KEY_CTR_J, xcmd_enter, "enter", NULL},
|
||||
{KEY_CTR_H, xcmd_del_char, "backspace", NULL},
|
||||
{KEY_BACKSPACE, xcmd_del_char, "delete", NULL},
|
||||
{KEY_LEFT, xcmd_cursor_left, "left", NULL},
|
||||
|
|
Loading…
Reference in New Issue