fix #15 added an api to control mode and echo + fixed the implementation and added tests

This commit is contained in:
prozessorkern
2020-03-08 19:56:04 +01:00
parent e970b6c941
commit 2921f9791b
7 changed files with 164 additions and 30 deletions

View File

@@ -162,6 +162,7 @@ void utils_forwardCursor(shellmatta_instance_t *inst, uint32_t length)
* @param[in] inst pointer to shellmatta instance
* @param[in] data pointer to the data to be inserted
* @param[in] length length of the data to be inserted
* @todo this function shall check buffer overflows
*/
void utils_insertChars( shellmatta_instance_t *inst,
char *data,
@@ -192,16 +193,20 @@ void utils_insertChars( shellmatta_instance_t *inst,
&(inst->buffer[inst->cursor + length]),
inst->inputCount - inst->cursor);
utils_restoreCursorPos(inst);
inst->cursor += length;
inst->inputCount += length;
}
/** -# just overwrite/append the chars */
/** -# overwrite - if the cursor reaches the end of the input it is pushed further */
else
{
memcpy(&(inst->buffer[inst->cursor]), data, length);
utils_writeEcho(inst, data, length);
inst->cursor += length;
if(inst->cursor > inst->inputCount)
{
inst->inputCount = inst->cursor;
}
}
inst->inputCount += length;
inst->cursor += length;
}
}