improve CLI handling of non-tty sources

This commit is contained in:
ІО-23 Шмуляр Олег 2025-05-18 13:22:34 +03:00
parent b6bc6da235
commit ae0a2c0430
2 changed files with 12 additions and 6 deletions

View File

@ -14,9 +14,9 @@
/* CLI config section */ /* CLI config section */
#define CLI_MAX_LINE_LENGTH 256 #define CLI_MAX_LINE_LENGTH 1024
#define CLI_MAX_ACCEPTED_ARGS 4 #define CLI_MAX_ACCEPTED_ARGS 4
#define CLI_MAX_TOKEN_LENGTH 64 #define CLI_MAX_TOKEN_LENGTH 256
/* FS config section */ /* FS config section */

View File

@ -9,6 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
static const struct CliCommandEntry cmd[] = { static const struct CliCommandEntry cmd[] = {
@ -208,11 +209,11 @@ abandon_struct:
unsigned int cli_poll_process_next(void) unsigned int cli_poll_process_next(void)
{ {
for ( ;; ) { int echo_commands = !isatty(STDIN_FILENO);
fputs(fs_get_cwd(), stdout);
for ( ;; ) {
if (fs_get_cwd()[0]) { if (fs_get_cwd()[0]) {
printf(" $ "); printf("%s $ ", fs_get_cwd());
} else { } else {
printf("$ "); printf("$ ");
} }
@ -221,8 +222,13 @@ unsigned int cli_poll_process_next(void)
char *line = NULL; char *line = NULL;
ssize_t result = getline(&line, &buf_size, stdin); ssize_t result = getline(&line, &buf_size, stdin);
if (result == -1) if (result == -1) {
printf("\n");
return 0x1; return 0x1;
}
if (echo_commands)
printf(line);
char **tokenized_line = tokenize_line(line, result); char **tokenized_line = tokenize_line(line, result);
free(line); free(line);