inital draft for history previus handeling

This commit is contained in:
Laila van Reenen 2024-04-13 20:52:05 +02:00
parent d4edc2cd8f
commit 8f8000d9ca
3 changed files with 64 additions and 2 deletions

View File

@ -107,6 +107,39 @@ void CLI_PrintHistory()
} }
free(historyList); free(historyList);
} }
void historyPrevius()
{
char* line;
if (
(History_getCurrPos(History) == History_getSize(History))
&& (FIFOBuffChar_getSize(FIFO) > 0)
)
{
// add current text to end of history
line = fifoToString(FIFO);
History_put(History, line);
}
// empty current line
while (FIFOBuffChar_getSize(FIFO) > 0)
{
CLI_stringOut((char*)"\x1b[D \x1b[D");
FIFOBuffChar_pop(FIFO);
}
// get previus command
int ret = History_getPrev(History, &line);
// write line
if ((ret >= 0) && (line != NULL))
{
for (int i=0; *(line + i) != '\0'; i++)
{
CLI_charIn(*(line + i));
}
}
}
#endif #endif
int tryExecute(FIFOBuffChar_t* fifo) int tryExecute(FIFOBuffChar_t* fifo)
@ -234,8 +267,8 @@ bool CLI_charIn(char c)
{ {
#ifdef HISTORY #ifdef HISTORY
case 'A': // arrow up case 'A': // arrow up
// history previus historyPrevius();
CLI_stringOut((char*)"(key: arrow up)"); // CLI_stringOut((char*)"(key: arrow up)");
CLI_State = CLI_State_Default; CLI_State = CLI_State_Default;
break; break;
case 'B': // arrow down case 'B': // arrow down

View File

@ -167,6 +167,33 @@ int History_getFullHistory(History_t* history, char*** list)
return retCode; return retCode;
} }
int History_getCurrPos(History_t* history)
{
int retCode = 0;
if (history->CurrEl_p != NULL)
{
History_element_t* el = history->FirstEl_p;
for (int i = 0; (el != history->CurrEl_p) && (retCode >= 0); i++)
{
if (el->nextEl_p == NULL)
{
retCode = 2;
}
else
{
el = (History_element_t*)el->nextEl_p;
}
}
}
else
{
retCode = History_getSize(history);
}
return retCode;
}
unsigned int History_getSize(History_t *history) unsigned int History_getSize(History_t *history)
{ {
return history->size; return history->size;

View File

@ -31,6 +31,8 @@ extern int History_put(History_t *history, char* line);
extern int History_getPrev(History_t* history, char** line); extern int History_getPrev(History_t* history, char** line);
extern int History_getNext(History_t* history, char** line); extern int History_getNext(History_t* history, char** line);
extern int History_getCurrPos(History_t* history);
extern int History_getFullHistory(History_t* history, char*** list); extern int History_getFullHistory(History_t* history, char*** list);
extern unsigned int History_getSize(History_t *history); extern unsigned int History_getSize(History_t *history);