improve CLI handling of non-tty sources
This commit is contained in:
parent
b6bc6da235
commit
ae0a2c0430
4
config.h
4
config.h
|
@ -14,9 +14,9 @@
|
|||
|
||||
|
||||
/* CLI config section */
|
||||
#define CLI_MAX_LINE_LENGTH 256
|
||||
#define CLI_MAX_LINE_LENGTH 1024
|
||||
#define CLI_MAX_ACCEPTED_ARGS 4
|
||||
#define CLI_MAX_TOKEN_LENGTH 64
|
||||
#define CLI_MAX_TOKEN_LENGTH 256
|
||||
|
||||
|
||||
/* FS config section */
|
||||
|
|
14
src/cli.c
14
src/cli.c
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
static const struct CliCommandEntry cmd[] = {
|
||||
|
@ -208,11 +209,11 @@ abandon_struct:
|
|||
|
||||
unsigned int cli_poll_process_next(void)
|
||||
{
|
||||
for ( ;; ) {
|
||||
fputs(fs_get_cwd(), stdout);
|
||||
int echo_commands = !isatty(STDIN_FILENO);
|
||||
|
||||
for ( ;; ) {
|
||||
if (fs_get_cwd()[0]) {
|
||||
printf(" $ ");
|
||||
printf("%s $ ", fs_get_cwd());
|
||||
} else {
|
||||
printf("$ ");
|
||||
}
|
||||
|
@ -221,8 +222,13 @@ unsigned int cli_poll_process_next(void)
|
|||
char *line = NULL;
|
||||
|
||||
ssize_t result = getline(&line, &buf_size, stdin);
|
||||
if (result == -1)
|
||||
if (result == -1) {
|
||||
printf("\n");
|
||||
return 0x1;
|
||||
}
|
||||
|
||||
if (echo_commands)
|
||||
printf(line);
|
||||
|
||||
char **tokenized_line = tokenize_line(line, result);
|
||||
free(line);
|
||||
|
|
Loading…
Reference in New Issue