Merge pull request #870 from armink/fix_shell

[Finsh] Stop push new history when current cmd is same as last cmd.
This commit is contained in:
Bernard Xiong 2017-10-13 11:43:28 +08:00 committed by GitHub
commit c5e8d9d757
1 changed files with 23 additions and 14 deletions

View File

@ -372,26 +372,35 @@ static void shell_push_history(struct finsh_shell *shell)
/* push history */ /* push history */
if (shell->history_count >= FINSH_HISTORY_LINES) if (shell->history_count >= FINSH_HISTORY_LINES)
{ {
/* move history */ /* if current cmd is same as last cmd, don't push */
int index; if (memcmp(&shell->cmd_history[FINSH_HISTORY_LINES - 1], shell->line, shell->line_position))
for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
{ {
memcpy(&shell->cmd_history[index][0], /* move history */
&shell->cmd_history[index + 1][0], FINSH_CMD_SIZE); int index;
} for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE); {
memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position); memcpy(&shell->cmd_history[index][0],
&shell->cmd_history[index + 1][0], FINSH_CMD_SIZE);
}
memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE);
memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position);
/* it's the maximum history */ /* it's the maximum history */
shell->history_count = FINSH_HISTORY_LINES; shell->history_count = FINSH_HISTORY_LINES;
}
} }
else else
{ {
memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE); /* if current cmd is same as last cmd, don't push */
memcpy(&shell->cmd_history[shell->history_count][0], shell->line, shell->line_position); if (shell->history_count == 0 || memcmp(&shell->cmd_history[shell->history_count - 1], shell->line, shell->line_position))
{
shell->current_history = shell->history_count;
memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE);
memcpy(&shell->cmd_history[shell->history_count][0], shell->line, shell->line_position);
/* increase count and set current history position */ /* increase count and set current history position */
shell->history_count ++; shell->history_count ++;
}
} }
} }
shell->current_history = shell->history_count; shell->current_history = shell->history_count;