1
0
mirror of https://github.com/NevermindZZT/letter-shell.git synced 2025-01-21 10:02:54 +08:00

新增 双击tab快速帮助

This commit is contained in:
Letter 2021-06-12 16:39:12 +08:00
parent fe95543f6b
commit 6b79f9a4a1
5 changed files with 63 additions and 17 deletions

View File

@ -165,6 +165,7 @@
| SHELL_PARAMETER_MAX_NUMBER | shell命令参数最大数量 | | SHELL_PARAMETER_MAX_NUMBER | shell命令参数最大数量 |
| SHELL_HISTORY_MAX_NUMBER | 历史命令记录数量 | | SHELL_HISTORY_MAX_NUMBER | 历史命令记录数量 |
| SHELL_DOUBLE_CLICK_TIME | 双击间隔(ms) | | SHELL_DOUBLE_CLICK_TIME | 双击间隔(ms) |
| SHELL_QUICK_HELP | 快速帮助 |
| SHELL_MAX_NUMBER | 管理的最大shell数量 | | SHELL_MAX_NUMBER | 管理的最大shell数量 |
| SHELL_GET_TICK() | 获取系统时间(ms) | | SHELL_GET_TICK() | 获取系统时间(ms) |
| SHELL_USING_LOCK | 是否使用锁 | | SHELL_USING_LOCK | 是否使用锁 |

View File

@ -13,6 +13,7 @@
#define __SHELL_CFG_H__ #define __SHELL_CFG_H__
#include "stdlib.h" #include "stdlib.h"
unsigned int userGetTick();
/** /**
* @brief 使shell任务while循环使`SHELL_USING_TASK` * @brief 使shell任务while循环使`SHELL_USING_TASK`
@ -101,6 +102,12 @@
*/ */
#define SHELL_DOUBLE_CLICK_TIME 200 #define SHELL_DOUBLE_CLICK_TIME 200
/**
* @brief
* tab的场景使tab不会对命令进行help补全
*/
#define SHELL_QUICK_HELP 1
/** /**
* @brief shell数量 * @brief shell数量
*/ */
@ -124,7 +131,7 @@
* Tick`HAL_GetTick()` * Tick`HAL_GetTick()`
* @note 使tab补全命令help使shell超时锁定 * @note 使tab补全命令help使shell超时锁定
*/ */
#define SHELL_GET_TICK() 0 #define SHELL_GET_TICK() userGetTick()
/** /**
* @brief 使 * @brief 使

View File

@ -18,6 +18,7 @@
#include <unistd.h> #include <unistd.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <sys/time.h>
Shell shell; Shell shell;
char shellBuffer[512]; char shellBuffer[512];
@ -28,6 +29,18 @@ Log log = {
.level = LOG_DEBUG .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 * @brief
* *

View File

@ -158,6 +158,7 @@ ShellCommand* shellSeekCommand(Shell *shell,
const char *cmd, const char *cmd,
ShellCommand *base, ShellCommand *base,
unsigned short compareLength); unsigned short compareLength);
static void shellWriteCommandHelp(Shell *shell, char *cmd);
/** /**
* @brief shell * @brief shell
@ -1543,6 +1544,12 @@ void shellTab(Shell *shell)
&& shell->status.tabFlag && shell->status.tabFlag
&& SHELL_GET_TICK() - shell->info.activeTime < SHELL_DOUBLE_CLICK_TIME) && 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); shellClearCommandLine(shell);
for (short i = shell->parser.length; i >= 0; i--) for (short i = shell->parser.length; i >= 0; i--)
{ {
@ -1553,6 +1560,7 @@ void shellTab(Shell *shell)
shell->parser.length += 5; shell->parser.length += 5;
shell->parser.cursor = shell->parser.length; shell->parser.cursor = shell->parser.length;
shellWriteString(shell, shell->parser.buffer); shellWriteString(shell, shell->parser.buffer);
#endif
} }
else else
{ {
@ -1614,6 +1622,31 @@ SHELL_EXPORT_KEY(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
0x0D0A0000, shellEnter, enter); 0x0D0A0000, shellEnter, enter);
#endif #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 * @brief shell help
@ -1631,22 +1664,7 @@ void shellHelp(int argc, char *argv[])
} }
else if (argc > 1) else if (argc > 1)
{ {
ShellCommand *command = shellSeekCommand(shell, shellWriteCommandHelp(shell, argv[1]);
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]);
}
} }
} }
SHELL_EXPORT_CMD( SHELL_EXPORT_CMD(

View File

@ -100,6 +100,13 @@
*/ */
#define SHELL_DOUBLE_CLICK_TIME 200 #define SHELL_DOUBLE_CLICK_TIME 200
/**
* @brief
* tab的场景使tab不会对命令进行help补全
*/
#define SHELL_QUICK_HELP 1
/** /**
* @brief shell数量 * @brief shell数量
*/ */