修改了xcmd部分源码,修复了一些问题

This commit is contained in:
hqm 2021-11-23 10:44:37 +08:00
parent 492c9eee10
commit bfc400fc89
3 changed files with 28 additions and 31 deletions

View File

@ -35,7 +35,7 @@ typedef struct __key
/** /**
* @description: * @description:
* @param {func*} get_c * @param {func*} get_c
* @param {func*} put_c * @param {func*} put_c
* @return {*} * @return {*}
@ -67,17 +67,17 @@ int xcmd_key_register(xcmd_key_t* keys, uint16_t number);
/** /**
* @description: next指针可以遍历所有指令 * @description: next指针可以遍历所有指令
* @param {xcmd_key_t*} keys * @param {*}
* @param {uint16_t} number * @param {}
* @return {int} * @return {xcmd_t *}
*/ */
xcmd_t *xcmd_cmdlist_get(void); xcmd_t *xcmd_cmdlist_get(void);
/** /**
* @description: next指针可以遍历所有案件 * @description: next指针可以遍历所有按键
* @param {xcmd_key_t*} keys * @param {*}
* @param {uint16_t} number * @param {}
* @return {int} * @return {xcmd_key_t *}
*/ */
xcmd_key_t *xcmd_keylist_get(void); xcmd_key_t *xcmd_keylist_get(void);
@ -104,8 +104,6 @@ int xcmd_exec(char *str);
/** /**
* @description: * @description:
* @param {char*} str
* @return
*/ */
void xcmd_print(const char *fmt, ...); void xcmd_print(const char *fmt, ...);
void xcmd_put_str(const char *str); void xcmd_put_str(const char *str);
@ -153,13 +151,6 @@ char* xcmd_display_get(void);
void xcmd_display_print(const char *fmt, ...); void xcmd_display_print(const char *fmt, ...);
void xcmd_display_write(const char* buf, uint16_t len); void xcmd_display_write(const char* buf, uint16_t len);
/**
* @description:
* @param {*}
* @return {*}
*/
char* xcmd_display_line_end(void);
/** /**
* @description: * @description:
* @param {*} * @param {*}
@ -225,6 +216,13 @@ char *xcmd_history_current(void);
*/ */
void xcmd_history_slider_reset(void); void xcmd_history_slider_reset(void);
/**
* @description:
* @param {*}
* @return {*}
*/
char* xcmd_end_of_input(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -266,7 +266,7 @@ static uint8_t xcmd_rcv_encode(uint8_t byte)
return ret; return ret;
} }
char* xcmd_display_line_end(void) char* xcmd_end_of_input(void)
{ {
char* ret = g_xcmder.parser.display_line; char* ret = g_xcmder.parser.display_line;
if(g_xcmder.parser.byte_num) if(g_xcmder.parser.byte_num)
@ -335,16 +335,14 @@ void xcmd_print(const char *fmt, ...)
void xcmd_display_write(const char* buf, uint16_t len) void xcmd_display_write(const char* buf, uint16_t len)
{ {
xcmd_display_clear();
if(len > XCMD_LINE_MAX_LENGTH) if(len > XCMD_LINE_MAX_LENGTH)
{ {
len = XCMD_LINE_MAX_LENGTH; len = XCMD_LINE_MAX_LENGTH;
} }
memcpy(g_xcmder.parser.display_line, buf, len); for(uint16_t i=0; i<len; i++)
g_xcmder.parser.display_line[len] = '\0'; {
xcmd_put_str(g_xcmder.parser.display_line); xcmd_display_insert_char(buf[i]);
g_xcmder.parser.byte_num = len; }
g_xcmder.parser.cursor = len;
} }
void xcmd_display_print(const char *fmt, ...) void xcmd_display_print(const char *fmt, ...)

View File

@ -1,7 +1,7 @@
/* /*
* @Author: your name * @Author: your name
* @Date: 2021-09-15 00:11:50 * @Date: 2021-09-15 00:11:50
* @LastEditTime: 2021-10-12 14:58:23 * @LastEditTime: 2021-10-27 09:16:27
* @LastEditors: Please set LastEditors * @LastEditors: Please set LastEditors
* @Description: In User Settings Edit * @Description: In User Settings Edit
* @FilePath: /xcmd/src/xcmd_default_keys.c * @FilePath: /xcmd/src/xcmd_default_keys.c
@ -31,7 +31,7 @@ static int xcmd_del_char(void *pv)
static int xcmd_enter(void *pv) static int xcmd_enter(void *pv)
{ {
char *cmd = xcmd_display_line_end(); char *cmd = xcmd_end_of_input();
xcmd_print("\n\r"); xcmd_print("\n\r");
if(cmd[0]) if(cmd[0])
{ {
@ -70,14 +70,12 @@ static int xcmd_cursor_right(void *pv)
static int xcmd_history_dw(void *pv) static int xcmd_history_dw(void *pv)
{ {
char *line = xcmd_history_prev(); char *line = xcmd_history_prev();
xcmd_display_clear();
if(line) if(line)
{ {
xcmd_display_print(line); xcmd_display_print(line);
} }
else
{
xcmd_display_clear();
}
return 0; return 0;
} }
@ -86,6 +84,7 @@ static int xcmd_history_up(void *pv)
char *line = xcmd_history_next(); char *line = xcmd_history_next();
if(line) if(line)
{ {
xcmd_display_clear();
xcmd_display_print(line); xcmd_display_print(line);
} }
return 0; return 0;
@ -133,11 +132,13 @@ static int xcmd_auto_completion(void *pv)
if(match_num == 1) if(match_num == 1)
{ {
xcmd_display_print("%s ", match_cmd_first->name); xcmd_display_clear();
xcmd_display_print("%s", match_cmd_first->name);
} }
else if(match_num > 1) else if(match_num > 1)
{ {
xcmd_print("\r\n"); xcmd_print("\r\n");
xcmd_display_clear();
xcmd_display_write(match_cmd_first->name, match_subscript_min); xcmd_display_write(match_cmd_first->name, match_subscript_min);
} }
return 0; return 0;