修改解释器关于显示部分的函数
This commit is contained in:
parent
a580b39d3e
commit
cb86bb245a
|
@ -1,20 +1,15 @@
|
|||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic"
|
||||
]
|
||||
"compilerPath": "/opt/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-gcc",
|
||||
"cStandard": "gnu17",
|
||||
"cppStandard": "gnu++14",
|
||||
"intelliSenseMode": "linux-gcc-arm"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
需要把根目录的inc和src拷贝到当前目录才能编译通过
|
|
@ -1,3 +1,11 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-09-17 23:03:06
|
||||
* @LastEditTime: 2021-09-17 23:07:03
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /xcmd/inc/xcmd_confg.h
|
||||
*/
|
||||
#ifndef XCMD_CONFG_H
|
||||
#define XCMD_CONFG_H
|
||||
|
||||
|
@ -7,7 +15,7 @@ extern "C" {
|
|||
|
||||
#define XCMD_LINE_MAX_LENGTH (32) /* 命令行支持的最大字符数 */
|
||||
#define XCMD_HISTORY_MAX_NUM (8) /* 支持的历史记录个数,0为不支持 */
|
||||
#define XCMD_PARAM_MAX_NUM (4) /* 支持输入的参数个数 */
|
||||
#define XCMD_PARAM_MAX_NUM (16) /* 支持输入的参数个数 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
93
src/xcmd.c
93
src/xcmd.c
|
@ -5,6 +5,31 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*光标操作符,其中0x1B是ESC,只适用于xcmd_print函数*/
|
||||
#define CUU(n) "\x1B[%dA",n /* 光标向上 光标向上 <n> 行 */
|
||||
#define CUD(n) "\x1B[%dB",n /* 光标向下 光标向下 <n> 行 */
|
||||
#define CUF(n) "\x1B[%dC",n /* 光标向前 光标向前(右)<n> 行 */
|
||||
#define CUB(n) "\x1B[%dD",n /* 光标向后 光标向后(左)<n> 行 */
|
||||
#define CNL(n) "\x1B[%dE",n /* 光标下一行 光标从当前位置向下 <n> 行 */
|
||||
#define CPL(n) "\x1B[%dF",n /* 光标当前行 光标从当前位置向上 <n> 行 */
|
||||
#define CHA(n) "\x1B[%dG",n /* 绝对光标水平 光标在当前行中水平移动到第 <n> 个位置 */
|
||||
#define VPA(n) "\x1B[%dd",n /* 绝对垂直行位置 光标在当前列中垂直移动到第 <n> 个位置 */
|
||||
#define CUP(y,x) "\x1B[%d;%dH",y,x /* 光标位置 *光标移动到视区中的 <x>; <y> 坐标,其中 <x> 是 <y> 行的列 */
|
||||
#define HVP(y,x) "\x1B[%d;%df",y,x /* 水平垂直位置 *光标移动到视区中的 <x>; <y> 坐标,其中 <x> 是 <y> 行的列 */
|
||||
|
||||
/*光标可见性*/
|
||||
#define CU_START_BL "\x1B[?12h" /* ATT160 文本光标启用闪烁 开始光标闪烁 */
|
||||
#define CU_STOP_BL "\x1B[?12l" /* ATT160 文本光标禁用闪烁 停止闪烁光标 */
|
||||
#define CU_SHOW "\x1B[?25h" /* DECTCEM 文本光标启用模式显示 显示光标 */
|
||||
#define CU_HIDE "\x1B[?25l" /* DECTCEM 文本光标启用模式隐藏 隐藏光标 */
|
||||
|
||||
/* 字符操作 */
|
||||
#define ICH(n) "\x1B[%d@",n /* 插入字符 在当前光标位置插入 <n> 个空格,这会将所有现有文本移到右侧。 向右溢出屏幕的文本会被删除。*/
|
||||
#define DCH(n) "\x1B[%dP",n /* 删除字符 删除当前光标位置的 <n> 个字符,这会从屏幕右边缘以空格字符移动。*/
|
||||
#define ECH(n) "\x1B[%dX",n /* 擦除字符 擦除当前光标位置的 <n> 个字符,方法是使用空格字符覆盖它们。*/
|
||||
#define IL(n) "\x1B[%dL",n /* 插入行 将 <n> 行插入光标位置的缓冲区。 光标所在的行及其下方的行将向下移动。*/
|
||||
#define DL(n) "\x1B[%dM",n /* 删除行 从缓冲区中删除 <n> 行,从光标所在的行开始。*/
|
||||
|
||||
#define CMD_IS_ENDLINE(c) ((c == '\n') || (c == '\r'))
|
||||
#define CMD_IS_PRINT(c) ((c >= 32) && (c <= 126))
|
||||
|
||||
|
@ -54,7 +79,7 @@ struct
|
|||
#endif
|
||||
|
||||
char display_line[XCMD_LINE_MAX_LENGTH]; /* 显示区的缓存 */
|
||||
|
||||
char *prompt; /* 显示区的提示 */
|
||||
uint16_t byte_num; /* 当前行的字符个数 */
|
||||
uint16_t cursor; /* 光标所在位置 */
|
||||
uint8_t encode_case_stu;
|
||||
|
@ -125,6 +150,12 @@ static void xcmd_key_match(XCMD_KEY_T key)
|
|||
}
|
||||
}
|
||||
|
||||
static void xcmd_key_exec(XCMD_KEY_T key)
|
||||
{
|
||||
xcmd_key_match(key);
|
||||
}
|
||||
|
||||
|
||||
static uint32_t xcmd_bytes_encode(uint8_t byte)
|
||||
{
|
||||
uint32_t ret = byte;
|
||||
|
@ -184,19 +215,6 @@ static uint32_t xcmd_bytes_encode(uint8_t byte)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void xcmd_display_update(void)
|
||||
{
|
||||
char *line = xcmd_display_get();
|
||||
xcmd_print("\r->");
|
||||
xcmd_print(line);
|
||||
xcmd_print("\r->");
|
||||
/* move cursor */
|
||||
for(uint16_t i = 0; i<g_xcmder.parser.cursor; i++)
|
||||
{
|
||||
xcmd_print("\x1B\x5B\x43");
|
||||
}
|
||||
}
|
||||
|
||||
static char* xcmd_line_end(void)
|
||||
{
|
||||
char* ret = g_xcmder.parser.display_line;
|
||||
|
@ -218,19 +236,13 @@ static char* xcmd_line_end(void)
|
|||
#endif
|
||||
g_xcmder.parser.byte_num = 0;
|
||||
g_xcmder.parser.cursor = 0;
|
||||
xcmd_print("\r\n");
|
||||
xcmd_history_reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
xcmd_print("\r\n->");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char* xcmd_parser(uint8_t byte)
|
||||
static void xcmd_parser(uint8_t byte)
|
||||
{
|
||||
char* ret = NULL;
|
||||
uint32_t c = 0;
|
||||
|
||||
c = xcmd_bytes_encode(byte);
|
||||
|
@ -241,14 +253,20 @@ static char* xcmd_parser(uint8_t byte)
|
|||
}
|
||||
else if(CMD_IS_ENDLINE(c))
|
||||
{
|
||||
ret = xcmd_line_end();
|
||||
char *cmd = xcmd_line_end();
|
||||
xcmd_print("\n\r");
|
||||
if(cmd[0])
|
||||
{
|
||||
xcmd_exec(cmd);
|
||||
cmd[0] = '\0';
|
||||
}
|
||||
xcmd_print("%s", g_xcmder.parser.prompt);
|
||||
}
|
||||
else
|
||||
{
|
||||
xcmd_key_match(c);
|
||||
xcmd_key_exec(c);
|
||||
}
|
||||
fflush(stdout);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void xcmd_print(const char *fmt, ...)
|
||||
|
@ -288,12 +306,8 @@ void xcmd_display_clear(void)
|
|||
uint16_t len = strlen(line);
|
||||
if(len)
|
||||
{
|
||||
xcmd_print("\r->");
|
||||
for(uint16_t i=0; i<len; i++)
|
||||
{
|
||||
g_xcmder.io.put_c(' ');
|
||||
}
|
||||
xcmd_print("\r->");
|
||||
xcmd_print(DL(0));
|
||||
xcmd_print("\r%s", g_xcmder.parser.prompt);
|
||||
g_xcmder.parser.byte_num = 0;
|
||||
g_xcmder.parser.cursor = 0;
|
||||
line[0] = '\0';
|
||||
|
@ -312,7 +326,8 @@ void xcmd_display_insert_char(char c)
|
|||
g_xcmder.parser.byte_num++;
|
||||
line[g_xcmder.parser.byte_num] = '\0';
|
||||
line[g_xcmder.parser.cursor++] = c;
|
||||
xcmd_display_update();
|
||||
xcmd_print(ICH(1));
|
||||
xcmd_print("%c", c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,17 +343,18 @@ void xcmd_display_delete_char(void)
|
|||
g_xcmder.parser.byte_num--;
|
||||
g_xcmder.parser.cursor--;
|
||||
line[g_xcmder.parser.byte_num] = ' ';
|
||||
xcmd_display_update();
|
||||
line[g_xcmder.parser.byte_num] = '\0';
|
||||
xcmd_print(CUB(1));
|
||||
xcmd_print(DCH(1));
|
||||
}
|
||||
}
|
||||
|
||||
void xcmd_display_cursor_set(uint16_t pos)
|
||||
{
|
||||
if(pos < g_xcmder.parser.byte_num)
|
||||
if(pos <= g_xcmder.parser.byte_num)
|
||||
{
|
||||
g_xcmder.parser.cursor = pos;
|
||||
xcmd_display_update();
|
||||
xcmd_print(CHA(g_xcmder.parser.cursor+3));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,6 +536,7 @@ void xcmd_init( int (*get_c)(uint8_t*), int (*put_c)(uint8_t))
|
|||
g_xcmder.io.get_c = get_c;
|
||||
g_xcmder.io.put_c = put_c;
|
||||
|
||||
g_xcmder.parser.prompt = "->";
|
||||
g_xcmder.parser.byte_num = 0;
|
||||
g_xcmder.parser.cursor = 0;
|
||||
g_xcmder.parser.encode_case_stu = 0;
|
||||
|
@ -539,17 +556,11 @@ void xcmd_init( int (*get_c)(uint8_t*), int (*put_c)(uint8_t))
|
|||
void xcmd_task(void)
|
||||
{
|
||||
uint8_t c;
|
||||
char *str = NULL;
|
||||
if(g_xcmder._initOK)
|
||||
{
|
||||
if(g_xcmder.io.get_c(&c))
|
||||
{
|
||||
str = xcmd_parser(c);
|
||||
if(str)
|
||||
{
|
||||
xcmd_exec(str);
|
||||
str[0] = '\0';
|
||||
}
|
||||
xcmd_parser(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-09-15 00:11:50
|
||||
* @LastEditTime: 2021-09-16 22:58:41
|
||||
* @LastEditTime: 2021-09-17 23:06:51
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /xcmd/src/xcmd_default_cmds.c
|
||||
|
@ -33,10 +33,10 @@ static void cmd_exit(int argc, char* argv[])
|
|||
static void cmd_logo(int argc, char* argv[])
|
||||
{
|
||||
char *log = "\
|
||||
_ _ ___ __ __ ____ \n\
|
||||
( \\/ )/ __)( \\/ )( _ \\ \n\
|
||||
) (( (__ ) ( )(_) )\n\
|
||||
(_/\\_)\\___)(_/\\/\\_)(____/\n ";
|
||||
_ _ ___ __ __ ____ \r\n\
|
||||
( \\/ )/ __)( \\/ )( _ \\ \r\n\
|
||||
) (( (__ ) ( )(_) )\r\n\
|
||||
(_/\\_)\\___)(_/\\/\\_)(____/\r\n ";
|
||||
xcmd_print("%s", log);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-09-15 00:11:50
|
||||
* @LastEditTime: 2021-09-16 23:00:17
|
||||
* @LastEditTime: 2021-09-17 23:18:12
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: /xcmd/src/xcmd_default_keys.c
|
||||
|
@ -10,17 +10,6 @@
|
|||
#include "../inc/xcmd_confg.h"
|
||||
#include "../inc/xcmd.h"
|
||||
|
||||
#define STR_UP "\x1B\x5B\x41"
|
||||
#define STR_DW "\x1B\x5B\x42"
|
||||
#define STR_RIGHT "\x1B\x5B\x43"
|
||||
#define STR_LEFT "\x1B\x5B\x44"
|
||||
#define STR_END "\x1B\x5B\x46"
|
||||
#define STR_HOME "\x1B\x5B\x48"
|
||||
#define STR_INSERT "\x1B\x5B\x32\x7E"
|
||||
#define STR_DELETE "\x1B\x5B\x33\x7E"
|
||||
#define STR_PGUP "\x1B\x5B\x35\x7E"
|
||||
#define STR_PGDW "\x1B\x5B\x36\x7E"
|
||||
|
||||
static int xcmd_del_char(void *pv)
|
||||
{
|
||||
xcmd_display_delete_char();
|
||||
|
|
Loading…
Reference in New Issue