@@ -158,6 +158,7 @@ ShellCommand* shellSeekCommand(Shell *shell,
158158 const char * cmd ,
159159 ShellCommand * base ,
160160 unsigned short compareLength );
161+ static void shellWriteCommandHelp (Shell * shell , char * cmd );
161162
162163/**
163164 * @brief shell 初始化
@@ -168,18 +169,21 @@ void shellInit(Shell *shell, char *buffer, unsigned short size)
168169{
169170 shell -> parser .length = 0 ;
170171 shell -> parser .cursor = 0 ;
171- shell -> history .offset = 0 ;
172- shell -> history .number = 0 ;
173- shell -> history .record = 0 ;
174172 shell -> info .user = NULL ;
175173 shell -> status .isChecked = 1 ;
176174
177175 shell -> parser .buffer = buffer ;
178176 shell -> parser .bufferSize = size / (SHELL_HISTORY_MAX_NUMBER + 1 );
177+
178+ #if SHELL_HISTORY_MAX_NUMBER > 0
179+ shell -> history .offset = 0 ;
180+ shell -> history .number = 0 ;
181+ shell -> history .record = 0 ;
179182 for (short i = 0 ; i < SHELL_HISTORY_MAX_NUMBER ; i ++ )
180183 {
181184 shell -> history .item [i ] = buffer + shell -> parser .bufferSize * (i + 1 );
182185 }
186+ #endif /** SHELL_HISTORY_MAX_NUMBER > 0 */
183187
184188#if SHELL_USING_CMD_EXPORT == 1
185189 #if defined(__CC_ARM ) || (defined(__ARMCC_VERSION ) && __ARMCC_VERSION >= 6000000 )
@@ -1271,6 +1275,7 @@ static void shellWriteReturnValue(Shell *shell, int value)
12711275}
12721276
12731277
1278+ #if SHELL_HISTORY_MAX_NUMBER > 0
12741279/**
12751280 * @brief shell历史记录添加
12761281 *
@@ -1350,6 +1355,7 @@ static void shellHistory(Shell *shell, signed char dir)
13501355 }
13511356
13521357}
1358+ #endif /** SHELL_HISTORY_MAX_NUMBER > 0 */
13531359
13541360
13551361/**
@@ -1382,7 +1388,9 @@ void shellExec(Shell *shell)
13821388
13831389 if (shell -> status .isChecked )
13841390 {
1391+ #if SHELL_HISTORY_MAX_NUMBER > 0
13851392 shellHistoryAdd (shell );
1393+ #endif /** SHELL_HISTORY_MAX_NUMBER > 0 */
13861394 shellParserParam (shell );
13871395 shell -> parser .length = shell -> parser .cursor = 0 ;
13881396 if (shell -> parser .paramCount == 0 )
@@ -1411,6 +1419,7 @@ void shellExec(Shell *shell)
14111419}
14121420
14131421
1422+ #if SHELL_HISTORY_MAX_NUMBER > 0
14141423/**
14151424 * @brief shell上方向键输入
14161425 *
@@ -1433,6 +1442,7 @@ void shellDown(Shell *shell)
14331442 shellHistory (shell , -1 );
14341443}
14351444SHELL_EXPORT_KEY (SHELL_CMD_PERMISSION (0 ), 0x1B5B4200 , shellDown , down );
1445+ #endif /** SHELL_HISTORY_MAX_NUMBER > 0 */
14361446
14371447
14381448/**
@@ -1543,6 +1553,12 @@ void shellTab(Shell *shell)
15431553 && shell -> status .tabFlag
15441554 && SHELL_GET_TICK () - shell -> info .activeTime < SHELL_DOUBLE_CLICK_TIME )
15451555 {
1556+ #if SHELL_QUICK_HELP == 1
1557+ shellWriteString (shell , "\r\n" );
1558+ shellWriteCommandHelp (shell , shell -> parser .buffer );
1559+ shellWritePrompt (shell , 1 );
1560+ shellWriteString (shell , shell -> parser .buffer );
1561+ #else
15461562 shellClearCommandLine (shell );
15471563 for (short i = shell -> parser .length ; i >= 0 ; i -- )
15481564 {
@@ -1553,6 +1569,7 @@ void shellTab(Shell *shell)
15531569 shell -> parser .length += 5 ;
15541570 shell -> parser .cursor = shell -> parser .length ;
15551571 shellWriteString (shell , shell -> parser .buffer );
1572+ #endif
15561573 }
15571574 else
15581575 {
@@ -1614,6 +1631,31 @@ SHELL_EXPORT_KEY(SHELL_CMD_PERMISSION(0)|SHELL_CMD_ENABLE_UNCHECKED,
161416310x0D0A0000 , shellEnter , enter );
16151632#endif
16161633
1634+ /**
1635+ * @brief shell 写命令帮助信息
1636+ *
1637+ * @param shell shell对象
1638+ * @param cmd 命令字符串
1639+ */
1640+ static void shellWriteCommandHelp (Shell * shell , char * cmd )
1641+ {
1642+ ShellCommand * command = shellSeekCommand (shell ,
1643+ cmd ,
1644+ shell -> commandList .base ,
1645+ 0 );
1646+ if (command )
1647+ {
1648+ shellWriteString (shell , shellText [SHELL_TEXT_HELP_HEADER ]);
1649+ shellWriteString (shell , shellGetCommandName (command ));
1650+ shellWriteString (shell , "\r\n" );
1651+ shellWriteString (shell , shellGetCommandDesc (command ));
1652+ shellWriteString (shell , "\r\n" );
1653+ }
1654+ else
1655+ {
1656+ shellWriteString (shell , shellText [SHELL_TEXT_CMD_NOT_FOUND ]);
1657+ }
1658+ }
16171659
16181660/**
16191661 * @brief shell help
@@ -1631,22 +1673,7 @@ void shellHelp(int argc, char *argv[])
16311673 }
16321674 else if (argc > 1 )
16331675 {
1634- ShellCommand * command = shellSeekCommand (shell ,
1635- argv [1 ],
1636- shell -> commandList .base ,
1637- 0 );
1638- if (command )
1639- {
1640- shellWriteString (shell , shellText [SHELL_TEXT_HELP_HEADER ]);
1641- shellWriteString (shell , shellGetCommandName (command ));
1642- shellWriteString (shell , "\r\n" );
1643- shellWriteString (shell , shellGetCommandDesc (command ));
1644- shellWriteString (shell , "\r\n" );
1645- }
1646- else
1647- {
1648- shellWriteString (shell , shellText [SHELL_TEXT_CMD_NOT_FOUND ]);
1649- }
1676+ shellWriteCommandHelp (shell , argv [1 ]);
16501677 }
16511678}
16521679SHELL_EXPORT_CMD (
0 commit comments