|
version 1.17.2.1, 2022/10/13 21:29:15
|
version 1.18, 2022/10/17 22:04:24
|
|
Line 1246 cliInit(int fin, int fout, const char *prompt)
|
Line 1246 cliInit(int fin, int fout, const char *prompt)
|
| } |
} |
| |
|
| /* |
/* |
| * cliInitLine() - Init CLI input line terminal | * cliSetLine() - Set CLI input line terminal |
| * |
* |
| * @cli_buffer = CLI buffer |
* @cli_buffer = CLI buffer |
| * return: none | * @old = Old terminal settings |
| | * return: -1 error or 0 ok |
| */ |
*/ |
| int |
int |
| cliInitLine(linebuffer_t * __restrict cli_buffer) | cliSetLine(linebuffer_t * __restrict cli_buffer, struct termios * __restrict old) |
| { |
{ |
| struct termios t; |
struct termios t; |
| |
|
| memset(&t, 0, sizeof t); |
memset(&t, 0, sizeof t); |
| tcgetattr(cli_buffer->line_in, &t); |
tcgetattr(cli_buffer->line_in, &t); |
| |
if (old) |
| |
memcpy(old, &t, sizeof(struct termios)); |
| t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | |
t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | |
| ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); |
ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); |
| t.c_iflag |= IGNBRK; |
t.c_iflag |= IGNBRK; |
|
Line 1267 cliInitLine(linebuffer_t * __restrict cli_buffer)
|
Line 1270 cliInitLine(linebuffer_t * __restrict cli_buffer)
|
| } |
} |
| |
|
| /* |
/* |
| |
* cliResetLine() - Reset CLI input line terminal |
| |
* |
| |
* @cli_buffer = CLI buffer |
| |
* @old = Original terminal settings |
| |
* return: -1 error or 0 ok |
| |
*/ |
| |
int |
| |
cliResetLine(linebuffer_t * __restrict cli_buffer, struct termios * __restrict orig) |
| |
{ |
| |
return tcsetattr(cli_buffer->line_in, TCSANOW, orig); |
| |
} |
| |
|
| |
/* |
| * cliReadLine() - Read line from opened CLI session |
* cliReadLine() - Read line from opened CLI session |
| * |
* |
| * @cli_buffer = CLI buffer |
* @cli_buffer = CLI buffer |
|
Line 1538 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
Line 1554 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
| { |
{ |
| char *line; |
char *line; |
| int ret = RETCODE_OK; |
int ret = RETCODE_OK; |
| |
struct termios t; |
| |
|
| /* --- main body of CLI --- */ |
/* --- main body of CLI --- */ |
| cliInitLine(cli_buffer); | cliSetLine(cli_buffer, &t); |
| |
|
| if (cli_loadHistory(cli_buffer, csHistFile) == RETCODE_ERR) |
if (cli_loadHistory(cli_buffer, csHistFile) == RETCODE_ERR) |
| return RETCODE_ERR; |
return RETCODE_ERR; |
|
Line 1561 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
Line 1578 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
| } while (cli_buffer->line_kill || ret < 1); |
} while (cli_buffer->line_kill || ret < 1); |
| |
|
| cli_saveHistory(cli_buffer, csHistFile, HISTORY_LINES); |
cli_saveHistory(cli_buffer, csHistFile, HISTORY_LINES); |
| |
|
| |
/* --- restore tty --- */ |
| |
cliResetLine(cli_buffer, &t); |
| |
|
| return ret; |
return ret; |
| } |
} |