add option to disable the echo
This commit is contained in:
parent
ae59563e7d
commit
8204cb0865
32
CLI/CLI.c
32
CLI/CLI.c
@ -30,13 +30,14 @@ CLI_t CLI_init(CLI_charOutFn lineOut, CMDList_t* cmdList)
|
|||||||
cli.CLI_charOut = lineOut;
|
cli.CLI_charOut = lineOut;
|
||||||
cli.CMDList = cmdList;
|
cli.CMDList = cmdList;
|
||||||
cli.CLI_State = CLI_State_Default;
|
cli.CLI_State = CLI_State_Default;
|
||||||
|
cli.echo = true;
|
||||||
|
|
||||||
cli.FIFO = FIFOBuffChar_create();
|
cli.FIFO = FIFOBuffChar_create();
|
||||||
#ifdef HISTORY
|
#ifdef HISTORY
|
||||||
cli.History = History_init();
|
cli.History = History_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (cli.CLI_charOut != NULL)
|
if (cli.CLI_charOut != NULL && cli.echo)
|
||||||
{
|
{
|
||||||
CLI_stringOut(&cli, (char*)"> ");
|
CLI_stringOut(&cli, (char*)"> ");
|
||||||
}
|
}
|
||||||
@ -168,8 +169,11 @@ int tryExecute(CLI_t* cli, FIFOBuffChar_t* fifo)
|
|||||||
if (*line == '\0')
|
if (*line == '\0')
|
||||||
{ // empty line
|
{ // empty line
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
if (cli->echo)
|
||||||
|
{
|
||||||
CLI_stringOut(cli, (char*)"> ");
|
CLI_stringOut(cli, (char*)"> ");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd = CMDList_get(cli->CMDList, line);
|
cmd = CMDList_get(cli->CMDList, line);
|
||||||
@ -182,7 +186,7 @@ int tryExecute(CLI_t* cli, FIFOBuffChar_t* fifo)
|
|||||||
#endif
|
#endif
|
||||||
int ret = (*(cmd->fn))(line, cli);
|
int ret = (*(cmd->fn))(line, cli);
|
||||||
|
|
||||||
if (ret != INT_MIN)
|
if (ret != INT_MIN && cli->echo)
|
||||||
{
|
{
|
||||||
CLI_stringOut(cli, (char*)"> ");
|
CLI_stringOut(cli, (char*)"> ");
|
||||||
}
|
}
|
||||||
@ -191,8 +195,12 @@ int tryExecute(CLI_t* cli, FIFOBuffChar_t* fifo)
|
|||||||
else if (ret == 0)
|
else if (ret == 0)
|
||||||
{
|
{
|
||||||
char err[100];
|
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]);
|
CLI_stringOut(cli, &err[0]);
|
||||||
|
if (cli->echo)
|
||||||
|
{
|
||||||
|
CLI_stringOut(cli, (char*)"> ");
|
||||||
|
}
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
#ifdef HISTORY
|
#ifdef HISTORY
|
||||||
@ -222,8 +230,11 @@ bool CLI_charIn(CLI_t* cli, char c)
|
|||||||
if ((C >= ' ') && (C <= '~')) // see ascii table
|
if ((C >= ' ') && (C <= '~')) // see ascii table
|
||||||
{
|
{
|
||||||
FIFOBuffChar_put(cli->FIFO, C); // save char in buffer
|
FIFOBuffChar_put(cli->FIFO, C); // save char in buffer
|
||||||
|
if (cli->echo)
|
||||||
|
{
|
||||||
CLI_charOut_save(cli, c);
|
CLI_charOut_save(cli, c);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
@ -231,7 +242,10 @@ bool CLI_charIn(CLI_t* cli, char c)
|
|||||||
case '\n':
|
case '\n':
|
||||||
case '\r':
|
case '\r':
|
||||||
// echo to terminal
|
// echo to terminal
|
||||||
|
if (cli->echo)
|
||||||
|
{
|
||||||
CLI_charOut_save(cli, c);
|
CLI_charOut_save(cli, c);
|
||||||
|
}
|
||||||
// copy buffer and create new buffer
|
// copy buffer and create new buffer
|
||||||
FIFOBuffChar_t* fifo = cli->FIFO;
|
FIFOBuffChar_t* fifo = cli->FIFO;
|
||||||
cli->FIFO = FIFOBuffChar_create();
|
cli->FIFO = FIFOBuffChar_create();
|
||||||
@ -245,8 +259,11 @@ bool CLI_charIn(CLI_t* cli, char c)
|
|||||||
case 127: // delete (backspace)
|
case 127: // delete (backspace)
|
||||||
if (FIFOBuffChar_pop(cli->FIFO))
|
if (FIFOBuffChar_pop(cli->FIFO))
|
||||||
{ // pop something of the buffer
|
{ // pop something of the buffer
|
||||||
|
if (cli->echo)
|
||||||
|
{
|
||||||
CLI_stringOut(cli, (char*)"\x1b[D \x1b[D"); // "<left arrow><space><left arrow>"
|
CLI_stringOut(cli, (char*)"\x1b[D \x1b[D"); // "<left arrow><space><left arrow>"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 27: // escape (start for arrow keys)
|
case 27: // escape (start for arrow keys)
|
||||||
@ -254,8 +271,11 @@ bool CLI_charIn(CLI_t* cli, char c)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
if (cli->echo)
|
||||||
|
{
|
||||||
sprintf(&str[0], "\ninvlid char: '%c' - (%i)\n", c, c);
|
sprintf(&str[0], "\ninvlid char: '%c' - (%i)\n", c, c);
|
||||||
CLI_stringOut(cli, &str[0]);
|
CLI_stringOut(cli, &str[0]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,11 +305,17 @@ bool CLI_charIn(CLI_t* cli, char c)
|
|||||||
historyNext(cli);
|
historyNext(cli);
|
||||||
break;
|
break;
|
||||||
case 'C': // arrow right
|
case 'C': // arrow right
|
||||||
|
if (cli->echo)
|
||||||
|
{
|
||||||
CLI_stringOut(cli, (char*)"(key: arrow right)");
|
CLI_stringOut(cli, (char*)"(key: arrow right)");
|
||||||
|
}
|
||||||
cli->CLI_State = CLI_State_Default;
|
cli->CLI_State = CLI_State_Default;
|
||||||
break;
|
break;
|
||||||
case 'D': // arrow left
|
case 'D': // arrow left
|
||||||
|
if (cli->echo)
|
||||||
|
{
|
||||||
CLI_stringOut(cli, (char*)"(key: arrow left)");
|
CLI_stringOut(cli, (char*)"(key: arrow left)");
|
||||||
|
}
|
||||||
cli->CLI_State = CLI_State_Default;
|
cli->CLI_State = CLI_State_Default;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user