added check if the current entered command matches the last command in the history buffer - if the command is already stored it will not be stored again
This commit is contained in:
parent
ac6ffb9602
commit
88c33895f6
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Stefan Strobel <stefan.strobel@shimatta.net>
|
||||
* Copyright (c) 2019 - 2021 Stefan Strobel <stefan.strobel@shimatta.net>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@ -38,7 +38,7 @@ static void appendHistoryByte(shellmatta_instance_t *inst, char byte)
|
||||
/** -# append the byte */
|
||||
inst->historyBuffer[inst->historyEnd] = byte;
|
||||
|
||||
/** -# check if the we overwrite an existing stored command */
|
||||
/** -# check if we overwrite an existing stored command */
|
||||
if(inst->historyEnd == inst->historyStart)
|
||||
{
|
||||
/** -# move the start pointer to the next termination (0) */
|
||||
@ -84,6 +84,56 @@ static bool getHistoryByte(shellmatta_instance_t *inst, char *byte)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief compares the current buffer to the last command in the history buffer
|
||||
* @param[in] inst pointer to a shellmatta instance
|
||||
* @return true: current command is identical to the last one in the history buffer
|
||||
*/
|
||||
static bool compareLastCommand(shellmatta_instance_t *inst)
|
||||
{
|
||||
bool ret = false;
|
||||
uint32_t i;
|
||||
uint32_t cnt;
|
||||
|
||||
/** -# check if there is anything in the buffer */
|
||||
if(inst->historyStart != inst->historyEnd)
|
||||
{
|
||||
i = inst->historyEnd;
|
||||
cnt = 0u;
|
||||
|
||||
ret = true;
|
||||
|
||||
while((true == ret) && (cnt < inst->inputCount))
|
||||
{
|
||||
/** -# terminate compare on first mismatch */
|
||||
if((inst->historyBuffer[i] != inst->buffer[cnt]) || (0u == inst->historyBuffer[i]))
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if(0u == i)
|
||||
{
|
||||
i = inst->historyBufferSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
i --;
|
||||
}
|
||||
|
||||
if(cnt < inst->inputCount)
|
||||
{
|
||||
cnt ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief navigates in the history buffer by the given number of commands
|
||||
* @param[in, out] inst pointer to a shellmatta instance
|
||||
@ -175,7 +225,8 @@ void history_storeCmd(shellmatta_instance_t *inst)
|
||||
* and there is a new command to be stored */
|
||||
if( (inst->historyBufferSize > inst->inputCount)
|
||||
&& (0u != inst->inputCount)
|
||||
&& (true == inst->dirty))
|
||||
&& (true == inst->dirty)
|
||||
&& (true != compareLastCommand(inst)))
|
||||
{
|
||||
/** -# append the command termination */
|
||||
appendHistoryByte(inst, 0u);
|
||||
@ -186,9 +237,6 @@ void history_storeCmd(shellmatta_instance_t *inst)
|
||||
appendHistoryByte(inst, inst->buffer[i - 1u]);
|
||||
}
|
||||
}
|
||||
|
||||
/** -# remove the dirty flag - everything is nice and saved */
|
||||
inst->dirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +269,6 @@ void history_restoreCmd(shellmatta_instance_t *inst)
|
||||
if(true == anythingToRestore)
|
||||
{
|
||||
utils_writeEcho(inst, inst->buffer, inst->inputCount);
|
||||
inst->dirty = false;
|
||||
}
|
||||
(void)history_navigate(inst, 1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user