Compare commits
3 Commits
multie-cli
...
esp-idf
| Author | SHA1 | Date | |
|---|---|---|---|
|
8204cb0865
|
|||
|
ae59563e7d
|
|||
|
259ad0a6f1
|
48
CLI/CLI.c
48
CLI/CLI.c
@@ -30,13 +30,14 @@ CLI_t CLI_init(CLI_charOutFn lineOut, CMDList_t* cmdList)
|
||||
cli.CLI_charOut = lineOut;
|
||||
cli.CMDList = cmdList;
|
||||
cli.CLI_State = CLI_State_Default;
|
||||
cli.echo = true;
|
||||
|
||||
cli.FIFO = FIFOBuffChar_create();
|
||||
#ifdef HISTORY
|
||||
cli.History = History_init();
|
||||
#endif
|
||||
|
||||
if (cli.CLI_charOut != NULL)
|
||||
if (cli.CLI_charOut != NULL && cli.echo)
|
||||
{
|
||||
CLI_stringOut(&cli, (char*)"> ");
|
||||
}
|
||||
@@ -168,7 +169,10 @@ int tryExecute(CLI_t* cli, FIFOBuffChar_t* fifo)
|
||||
if (*line == '\0')
|
||||
{ // empty line
|
||||
ret = 1;
|
||||
CLI_stringOut(cli, (char*)"> ");
|
||||
if (cli->echo)
|
||||
{
|
||||
CLI_stringOut(cli, (char*)"> ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -182,7 +186,7 @@ int tryExecute(CLI_t* cli, FIFOBuffChar_t* fifo)
|
||||
#endif
|
||||
int ret = (*(cmd->fn))(line, cli);
|
||||
|
||||
if (ret != INT_MIN)
|
||||
if (ret != INT_MIN && cli->echo)
|
||||
{
|
||||
CLI_stringOut(cli, (char*)"> ");
|
||||
}
|
||||
@@ -191,8 +195,12 @@ int tryExecute(CLI_t* cli, FIFOBuffChar_t* fifo)
|
||||
else if (ret == 0)
|
||||
{
|
||||
char err[100];
|
||||
sprintf(&err[0], "command not found: %s\n> ", line);
|
||||
sprintf(&err[0], "command not found: %s\n", line);
|
||||
CLI_stringOut(cli, &err[0]);
|
||||
if (cli->echo)
|
||||
{
|
||||
CLI_stringOut(cli, (char*)"> ");
|
||||
}
|
||||
ret = -1;
|
||||
|
||||
#ifdef HISTORY
|
||||
@@ -222,7 +230,10 @@ bool CLI_charIn(CLI_t* cli, char c)
|
||||
if ((C >= ' ') && (C <= '~')) // see ascii table
|
||||
{
|
||||
FIFOBuffChar_put(cli->FIFO, C); // save char in buffer
|
||||
CLI_charOut_save(cli, c);
|
||||
if (cli->echo)
|
||||
{
|
||||
CLI_charOut_save(cli, c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -231,7 +242,10 @@ bool CLI_charIn(CLI_t* cli, char c)
|
||||
case '\n':
|
||||
case '\r':
|
||||
// echo to terminal
|
||||
CLI_charOut_save(cli, c);
|
||||
if (cli->echo)
|
||||
{
|
||||
CLI_charOut_save(cli, c);
|
||||
}
|
||||
// copy buffer and create new buffer
|
||||
FIFOBuffChar_t* fifo = cli->FIFO;
|
||||
cli->FIFO = FIFOBuffChar_create();
|
||||
@@ -245,7 +259,10 @@ bool CLI_charIn(CLI_t* cli, char c)
|
||||
case 127: // delete (backspace)
|
||||
if (FIFOBuffChar_pop(cli->FIFO))
|
||||
{ // pop something of the buffer
|
||||
CLI_stringOut(cli, (char*)"\x1b[D \x1b[D"); // "<left arrow><space><left arrow>"
|
||||
if (cli->echo)
|
||||
{
|
||||
CLI_stringOut(cli, (char*)"\x1b[D \x1b[D"); // "<left arrow><space><left arrow>"
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -254,8 +271,11 @@ bool CLI_charIn(CLI_t* cli, char c)
|
||||
break;
|
||||
|
||||
default:
|
||||
sprintf(&str[0], "\ninvlid char: '%c' - (%i)\n", c, c);
|
||||
CLI_stringOut(cli, &str[0]);
|
||||
if (cli->echo)
|
||||
{
|
||||
sprintf(&str[0], "\ninvlid char: '%c' - (%i)\n", c, c);
|
||||
CLI_stringOut(cli, &str[0]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -285,11 +305,17 @@ bool CLI_charIn(CLI_t* cli, char c)
|
||||
historyNext(cli);
|
||||
break;
|
||||
case 'C': // arrow right
|
||||
CLI_stringOut(cli, (char*)"(key: arrow right)");
|
||||
if (cli->echo)
|
||||
{
|
||||
CLI_stringOut(cli, (char*)"(key: arrow right)");
|
||||
}
|
||||
cli->CLI_State = CLI_State_Default;
|
||||
break;
|
||||
case 'D': // arrow left
|
||||
CLI_stringOut(cli, (char*)"(key: arrow left)");
|
||||
if (cli->echo)
|
||||
{
|
||||
CLI_stringOut(cli, (char*)"(key: arrow left)");
|
||||
}
|
||||
cli->CLI_State = CLI_State_Default;
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,7 @@ typedef struct CLI {
|
||||
History_t* History;
|
||||
#endif
|
||||
CLI_State_t CLI_State;
|
||||
bool echo;
|
||||
} CLI_t;
|
||||
|
||||
// initilize and register the lineout print function
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
|
||||
# FIFO Buffer
|
||||
add_library(FIFOBuffChar FIFOBuff/FIFOBuffChar.c)
|
||||
|
||||
# CMD List
|
||||
add_library(CMDList CMDList/CMDList.c)
|
||||
add_library(CMDListPrint CMDList/printList.c)
|
||||
|
||||
# History
|
||||
add_library(history History/History.c)
|
||||
|
||||
# CLI
|
||||
add_library(CLI CLI/CLI.c)
|
||||
target_link_libraries(CLI CMDList FIFOBuffChar history)
|
||||
|
||||
add_library(CLI_History CLI/CLI.c)
|
||||
target_link_libraries(CLI_History CMDList FIFOBuffChar history)
|
||||
target_compile_definitions(CLI_History PRIVATE HISTORY)
|
||||
idf_component_register(
|
||||
COMPONENT_ALIAS "cli"
|
||||
SRCS
|
||||
CLI/CLI.c
|
||||
FIFOBuff/FIFOBuffChar.c
|
||||
CMDList/CMDList.c
|
||||
History/History.c
|
||||
INCLUDE_DIRS "./"
|
||||
PRIV_INCLUDE_DIRS "../../src")
|
||||
|
||||
Reference in New Issue
Block a user