Merge branch 'dev' of https://gitee.com/two_salted_eggs/xcmd into HEAD
Change-Id: Icb18d8fec97ea9268e460188183a36612f51a88e
This commit is contained in:
commit
5f9b9ff1af
40
inc/xcmd.h
40
inc/xcmd.h
|
@ -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
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ typedef struct __key
|
|||
|
||||
|
||||
/**
|
||||
* @description: 接时期初始化
|
||||
* @description: 解释器初始化
|
||||
* @param {func*} get_c:获取一个字符的函数
|
||||
* @param {func*} put_c:发送一个字符的函数
|
||||
* @return {*}
|
||||
|
@ -67,17 +67,17 @@ int xcmd_key_register(xcmd_key_t* keys, uint16_t number);
|
|||
|
||||
/**
|
||||
* @description: 获取命令列表,可以通过next指针可以遍历所有指令
|
||||
* @param {xcmd_key_t*} keys:快捷键集
|
||||
* @param {uint16_t} number:快捷键的个数
|
||||
* @return {int}:已经注册的快捷键的个数
|
||||
* @param {*}
|
||||
* @param {}
|
||||
* @return {xcmd_t *}:指令链表表头
|
||||
*/
|
||||
xcmd_t *xcmd_cmdlist_get(void);
|
||||
|
||||
/**
|
||||
* @description: 获取案件列表,可以通过next指针可以遍历所有案件
|
||||
* @param {xcmd_key_t*} keys:快捷键集
|
||||
* @param {uint16_t} number:快捷键的个数
|
||||
* @return {int}:已经注册的快捷键的个数
|
||||
* @description: 获取按键列表,可以通过next指针可以遍历所有按键
|
||||
* @param {*}
|
||||
* @param {}
|
||||
* @return {xcmd_key_t *}:快捷键链表表头
|
||||
*/
|
||||
xcmd_key_t *xcmd_keylist_get(void);
|
||||
|
||||
|
@ -104,11 +104,9 @@ int xcmd_exec(char *str);
|
|||
|
||||
/**
|
||||
* @description: 打印字符串
|
||||
* @param {char*} str
|
||||
* @return 无
|
||||
*/
|
||||
void xcmd_print(const char *fmt, ...);
|
||||
|
||||
void xcmd_put_str(const char *str);
|
||||
|
||||
/**
|
||||
* @description: 向显示器插入一个字符
|
||||
|
@ -150,16 +148,9 @@ 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);
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
char* xcmd_display_line_end(void);
|
||||
|
||||
/**
|
||||
* @description: 光标操作函数
|
||||
* @param {*}
|
||||
|
@ -225,6 +216,13 @@ char *xcmd_history_current(void);
|
|||
*/
|
||||
void xcmd_history_slider_reset(void);
|
||||
|
||||
/**
|
||||
* @description: 结束输入
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
char* xcmd_end_of_input(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
52
src/xcmd.c
52
src/xcmd.c
|
@ -206,9 +206,11 @@ static void xcmd_key_match(char* key)
|
|||
{
|
||||
if(strcmp(key, p->key) == 0)
|
||||
{
|
||||
p->func(&g_xcmder);
|
||||
if(p->func(&g_xcmder) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +266,7 @@ static uint8_t xcmd_rcv_encode(uint8_t byte)
|
|||
return ret;
|
||||
}
|
||||
|
||||
char* xcmd_display_line_end(void)
|
||||
char* xcmd_end_of_input(void)
|
||||
{
|
||||
char* ret = g_xcmder.parser.display_line;
|
||||
if(g_xcmder.parser.byte_num)
|
||||
|
@ -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,34 +330,30 @@ 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)
|
||||
{
|
||||
xcmd_display_clear();
|
||||
if(len > XCMD_LINE_MAX_LENGTH)
|
||||
{
|
||||
len = XCMD_LINE_MAX_LENGTH;
|
||||
}
|
||||
memcpy(g_xcmder.parser.display_line, buf, len);
|
||||
g_xcmder.parser.display_line[len] = '\0';
|
||||
xcmd_print(g_xcmder.parser.display_line);
|
||||
g_xcmder.parser.byte_num = len;
|
||||
g_xcmder.parser.cursor = len;
|
||||
}
|
||||
|
||||
void xcmd_display_print(const char *msg)
|
||||
for(uint16_t i=0; i<len; i++)
|
||||
{
|
||||
xcmd_display_write(msg, strlen(msg));
|
||||
xcmd_display_insert_char(buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xcmd_display_print(const char *fmt, ...)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -358,11 +364,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-27 09:16:27
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /xcmd/src/xcmd_default_keys.c
|
||||
|
@ -31,7 +31,7 @@ static int xcmd_del_char(void *pv)
|
|||
|
||||
static int xcmd_enter(void *pv)
|
||||
{
|
||||
char *cmd = xcmd_display_line_end();
|
||||
char *cmd = xcmd_end_of_input();
|
||||
xcmd_print("\n\r");
|
||||
if(cmd[0])
|
||||
{
|
||||
|
@ -70,14 +70,12 @@ static int xcmd_cursor_right(void *pv)
|
|||
static int xcmd_history_dw(void *pv)
|
||||
{
|
||||
char *line = xcmd_history_prev();
|
||||
xcmd_display_clear();
|
||||
if(line)
|
||||
{
|
||||
|
||||
xcmd_display_print(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
xcmd_display_clear();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -86,6 +84,7 @@ static int xcmd_history_up(void *pv)
|
|||
char *line = xcmd_history_next();
|
||||
if(line)
|
||||
{
|
||||
xcmd_display_clear();
|
||||
xcmd_display_print(line);
|
||||
}
|
||||
return 0;
|
||||
|
@ -133,11 +132,13 @@ static int xcmd_auto_completion(void *pv)
|
|||
|
||||
if(match_num == 1)
|
||||
{
|
||||
xcmd_display_print(match_cmd_first->name);
|
||||
xcmd_display_clear();
|
||||
xcmd_display_print("%s", match_cmd_first->name);
|
||||
}
|
||||
else if(match_num > 1)
|
||||
{
|
||||
xcmd_print("\r\n");
|
||||
xcmd_display_clear();
|
||||
xcmd_display_write(match_cmd_first->name, match_subscript_min);
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue