From e56c10c7b60d4e0fac936de1ce473bb9dbd4d9c8 Mon Sep 17 00:00:00 2001 From: DaJiYuQia <88259094+DaJiYuQia@users.noreply.github.com> Date: Sun, 23 Oct 2022 17:35:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=A1=8C=E5=88=87=E6=8D=A2=E9=97=AE=E9=A2=98=20(#66)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user/apps/shell/shell.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/user/apps/shell/shell.c b/user/apps/shell/shell.c index ab9a8fba..687760df 100644 --- a/user/apps/shell/shell.c +++ b/user/apps/shell/shell.c @@ -117,7 +117,7 @@ void clear_command(int count, char *buf) * @brief 切换命令(写入到缓冲区) * * @param buf 缓冲区 - * @param type 如果为1,就向下,如果为-1,就向上 + * @param type 如果为1,就向上,如果为-1,就向下 */ void change_command(char *buf, int type) { @@ -126,7 +126,18 @@ void change_command(char *buf, int type) if (current_command_index < 0) current_command_index++; if (current_command_index >= count_history - 1) - current_command_index = count_history - 2; + { + //初始只含一条空历史记录,需单独考虑 + if(count_history == 1) + { + //防止出现多条空历史记录 + if(current_command_index > 1) + current_command_index = 1; + } + else + current_command_index = count_history - 2; + } + strcpy(buf, history_commands[current_command_index]); printf("%s", buf); put_string(" ", COLOR_BLACK, COLOR_WHITE);