inital draft for history previus handeling
This commit is contained in:
parent
d4edc2cd8f
commit
8f8000d9ca
37
CLI/CLI.c
37
CLI/CLI.c
@ -107,6 +107,39 @@ void CLI_PrintHistory()
|
||||
}
|
||||
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
|
||||
|
||||
int tryExecute(FIFOBuffChar_t* fifo)
|
||||
@ -234,8 +267,8 @@ bool CLI_charIn(char c)
|
||||
{
|
||||
#ifdef HISTORY
|
||||
case 'A': // arrow up
|
||||
// history previus
|
||||
CLI_stringOut((char*)"(key: arrow up)");
|
||||
historyPrevius();
|
||||
// CLI_stringOut((char*)"(key: arrow up)");
|
||||
CLI_State = CLI_State_Default;
|
||||
break;
|
||||
case 'B': // arrow down
|
||||
|
||||
@ -167,6 +167,33 @@ int History_getFullHistory(History_t* history, char*** list)
|
||||
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)
|
||||
{
|
||||
return history->size;
|
||||
|
||||
@ -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_getNext(History_t* history, char** line);
|
||||
|
||||
extern int History_getCurrPos(History_t* history);
|
||||
|
||||
extern int History_getFullHistory(History_t* history, char*** list);
|
||||
|
||||
extern unsigned int History_getSize(History_t *history);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user