mirror of
https://github.com/NevermindZZT/letter-shell.git
synced 2025-01-01 09:58:41 +08:00
新增 双击tab快速帮助
This commit is contained in:
parent
fe95543f6b
commit
6b79f9a4a1
@ -165,6 +165,7 @@
|
||||
| SHELL_PARAMETER_MAX_NUMBER | shell命令参数最大数量 |
|
||||
| SHELL_HISTORY_MAX_NUMBER | 历史命令记录数量 |
|
||||
| SHELL_DOUBLE_CLICK_TIME | 双击间隔(ms) |
|
||||
| SHELL_QUICK_HELP | 快速帮助 |
|
||||
| SHELL_MAX_NUMBER | 管理的最大shell数量 |
|
||||
| SHELL_GET_TICK() | 获取系统时间(ms) |
|
||||
| SHELL_USING_LOCK | 是否使用锁 |
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define __SHELL_CFG_H__
|
||||
|
||||
#include "stdlib.h"
|
||||
unsigned int userGetTick();
|
||||
|
||||
/**
|
||||
* @brief 是否使用默认shell任务while循环,使能宏`SHELL_USING_TASK`后此宏有意义
|
||||
@ -101,6 +102,12 @@
|
||||
*/
|
||||
#define SHELL_DOUBLE_CLICK_TIME 200
|
||||
|
||||
/**
|
||||
* @brief 快速帮助
|
||||
* 作用于双击tab的场景,当使能此宏时,双击tab不会对命令进行help补全,而是直接显示对应命令的帮助信息
|
||||
*/
|
||||
#define SHELL_QUICK_HELP 1
|
||||
|
||||
/**
|
||||
* @brief 管理的最大shell数量
|
||||
*/
|
||||
@ -124,7 +131,7 @@
|
||||
* 定义此宏为获取系统Tick,如`HAL_GetTick()`
|
||||
* @note 此宏不定义时无法使用双击tab补全命令help,无法使用shell超时锁定
|
||||
*/
|
||||
#define SHELL_GET_TICK() 0
|
||||
#define SHELL_GET_TICK() userGetTick()
|
||||
|
||||
/**
|
||||
* @brief 使用锁
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
Shell shell;
|
||||
char shellBuffer[512];
|
||||
@ -28,6 +29,18 @@ Log log = {
|
||||
.level = LOG_DEBUG
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 获取系统tick
|
||||
*
|
||||
* @return unsigned int 系统tick
|
||||
*/
|
||||
unsigned int userGetTick()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (tv.tv_sec * 1000 + tv.tv_usec / 1000) & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 日志写函数实现
|
||||
*
|
||||
|
50
src/shell.c
50
src/shell.c
@ -158,6 +158,7 @@ ShellCommand* shellSeekCommand(Shell *shell,
|
||||
const char *cmd,
|
||||
ShellCommand *base,
|
||||
unsigned short compareLength);
|
||||
static void shellWriteCommandHelp(Shell *shell, char *cmd);
|
||||
|
||||
/**
|
||||
* @brief shell 初始化
|
||||
@ -1543,6 +1544,12 @@ void shellTab(Shell *shell)
|
||||
&& shell->status.tabFlag
|
||||
&& SHELL_GET_TICK() - shell->info.activeTime < SHELL_DOUBLE_CLICK_TIME)
|
||||
{
|
||||
#if SHELL_QUICK_HELP == 1
|
||||
shellWriteString(shell, "\r\n");
|
||||
shellWriteCommandHelp(shell, shell->parser.buffer);
|
||||
shellWritePrompt(shell, 1);
|
||||
shellWriteString(shell, shell->parser.buffer);
|
||||
#else
|
||||
shellClearCommandLine(shell);
|
||||
for (short i = shell->parser.length; i >= 0; i--)
|
||||
{
|
||||
@ -1553,6 +1560,7 @@ void shellTab(Shell *shell)
|
||||
shell->parser.length += 5;
|
||||
shell->parser.cursor = shell->parser.length;
|
||||
shellWriteString(shell, shell->parser.buffer);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1614,6 +1622,31 @@ SHELL_EXPORT_KEY(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
|
||||
0x0D0A0000, shellEnter, enter);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief shell 写命令帮助信息
|
||||
*
|
||||
* @param shell shell对象
|
||||
* @param cmd 命令字符串
|
||||
*/
|
||||
static void shellWriteCommandHelp(Shell *shell, char *cmd)
|
||||
{
|
||||
ShellCommand *command = shellSeekCommand(shell,
|
||||
cmd,
|
||||
shell->commandList.base,
|
||||
0);
|
||||
if (command)
|
||||
{
|
||||
shellWriteString(shell, shellText[SHELL_TEXT_HELP_HEADER]);
|
||||
shellWriteString(shell, shellGetCommandName(command));
|
||||
shellWriteString(shell, "\r\n");
|
||||
shellWriteString(shell, shellGetCommandDesc(command));
|
||||
shellWriteString(shell, "\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
shellWriteString(shell, shellText[SHELL_TEXT_CMD_NOT_FOUND]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief shell help
|
||||
@ -1631,22 +1664,7 @@ void shellHelp(int argc, char *argv[])
|
||||
}
|
||||
else if (argc > 1)
|
||||
{
|
||||
ShellCommand *command = shellSeekCommand(shell,
|
||||
argv[1],
|
||||
shell->commandList.base,
|
||||
0);
|
||||
if (command)
|
||||
{
|
||||
shellWriteString(shell, shellText[SHELL_TEXT_HELP_HEADER]);
|
||||
shellWriteString(shell, shellGetCommandName(command));
|
||||
shellWriteString(shell, "\r\n");
|
||||
shellWriteString(shell, shellGetCommandDesc(command));
|
||||
shellWriteString(shell, "\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
shellWriteString(shell, shellText[SHELL_TEXT_CMD_NOT_FOUND]);
|
||||
}
|
||||
shellWriteCommandHelp(shell, argv[1]);
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(
|
||||
|
@ -100,6 +100,13 @@
|
||||
*/
|
||||
#define SHELL_DOUBLE_CLICK_TIME 200
|
||||
|
||||
/**
|
||||
* @brief 快速帮助
|
||||
* 作用于双击tab的场景,当使能此宏时,双击tab不会对命令进行help补全,而是直接显示对应命令的帮助信息
|
||||
*/
|
||||
#define SHELL_QUICK_HELP 1
|
||||
|
||||
|
||||
/**
|
||||
* @brief 管理的最大shell数量
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user