mirror of
https://github.com/NevermindZZT/letter-shell.git
synced 2025-01-21 10:02:54 +08:00
新增双击tab长帮助补全
This commit is contained in:
parent
596cf049f8
commit
24b1cc282f
34
README.md
34
README.md
@ -1,20 +1,43 @@
|
||||
# letter shell
|
||||
|
||||
![version](https://img.shields.io/badge/version-2.0.0-brightgreen.svg)
|
||||
![build](https://img.shields.io/badge/build-2019.2.12-brightgreen.svg)
|
||||
|
||||
一个体积极小的嵌入式shell
|
||||
|
||||
## 功能
|
||||
|
||||
- 命令自动补全,使用tab键补全命令
|
||||
- 命令长帮助,使用help [command]显示命令长帮助
|
||||
- 长帮助补全,输入命令后双击tab键补全命令长帮助指令
|
||||
|
||||
## 移植说明
|
||||
|
||||
1. 定义shell对象
|
||||
|
||||
```C
|
||||
SHELL_TypeDef shell
|
||||
SHELL_TypeDef shell;
|
||||
```
|
||||
|
||||
2. 定义shell读,写函数,函数原型如下
|
||||
|
||||
```C
|
||||
typedef signed char (*shellRead)(char *); /**< shell读取数据函数原型 */
|
||||
typedef void (*shellWrite)(const char); /**< shell写数据函数原型 */
|
||||
/**
|
||||
* @brief shell读取数据函数原型
|
||||
*
|
||||
* @param char shell读取的字符
|
||||
*
|
||||
* @return char 0 读取数据成功
|
||||
* @return char -1 读取数据失败
|
||||
*/
|
||||
typedef signed char (*shellRead)(char *);
|
||||
|
||||
/**
|
||||
* @brief shell写数据函数原型
|
||||
*
|
||||
* @param const char 需写的字符
|
||||
*/
|
||||
typedef void (*shellWrite)(const char);
|
||||
```
|
||||
|
||||
3. 调用shellInit进行初始化
|
||||
@ -31,6 +54,10 @@ shellInit(&shell);
|
||||
- 对于在无操作系统环境下,可以使用查询的方式,使能```SHELL_UISNG_TASK```,然后在循环中不断调用shellTask
|
||||
- 对于使用操作系统的情况,使能```SHELL_USING_TASK```和```SHEHLL_TASK_WHILE```宏,然后创建shellTask任务
|
||||
|
||||
5. 其他配置
|
||||
|
||||
- 定义宏```SHELL_GET_TICK()```为获取系统tick函数,使能tab双击操作,用户长帮助补全
|
||||
|
||||
## 使用方式
|
||||
|
||||
### 命令定义
|
||||
@ -52,6 +79,7 @@ const SHELL_CommandTypeDef shellDefaultCommandList[] =
|
||||
|
||||
- 对于基于串口移植,letter shell建议使用secureCRT软件,letter shell中的相关按键映射都是按照secureCRT进行设计的,使用其他串口软件可能会出现某些功能无法使用的情况
|
||||
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 2018/4/20 v1.0
|
||||
|
22
shell.c
22
shell.c
@ -477,6 +477,28 @@ static void shellTab(SHELL_TypeDef *shell)
|
||||
shellHelp(shell, 1, (void *)0);
|
||||
shellDisplay(shell, SHELL_COMMAND);
|
||||
}
|
||||
|
||||
#if SHELL_LONG_HELP == 1
|
||||
static int time = 0;
|
||||
|
||||
if (SHELL_GET_TICK())
|
||||
{
|
||||
if (matchNum == 1 && SHELL_GET_TICK() - time < SHELL_DOUBLE_CLICK_TIME)
|
||||
{
|
||||
shellClearLine(shell);
|
||||
for (short i = shell->length; i >= 0; i--)
|
||||
{
|
||||
shell->buffer[i + 5] = shell->buffer[i];
|
||||
}
|
||||
shellStringCopy(shell->buffer, "help");
|
||||
shell->buffer[4] = ' ';
|
||||
shell->length += 5;
|
||||
shell->cursor = shell->length;
|
||||
shellDisplay(shell, shell->buffer);
|
||||
}
|
||||
time = SHELL_GET_TICK();
|
||||
}
|
||||
#endif /** SHELL_LONG_HELP == 1 */
|
||||
}
|
||||
|
||||
|
||||
|
3
shell.h
3
shell.h
@ -22,6 +22,9 @@
|
||||
#define SHELL_COMMAND_MAX_LENGTH 50 /**< shell命令最大长度 */
|
||||
#define SHELL_PARAMETER_MAX_NUMBER 5 /**< shell命令参数最大数量 */
|
||||
#define SHELL_HISTORY_MAX_NUMBER 5 /**< 历史命令记录数量 */
|
||||
#define SHELL_DOUBLE_CLICK_TIME 200 /**< 双击间隔(ms) */
|
||||
|
||||
#define SHELL_GET_TICK() 0 /**< 获取系统时间(ms) */
|
||||
|
||||
#define SHELL_COMMAND "\r\nletter>>" /**< shell提示符 */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user