improve CLI handling of non-tty sources
This commit is contained in:
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);
|
||||
|
||||
Reference in New Issue
Block a user