read: do not display prompt if not in a tty

This commit is contained in:
Khaïs COLIN 2025-02-06 14:24:17 +01:00
parent 8bfdb04630
commit 6aabe49df1
No known key found for this signature in database

View file

@ -6,7 +6,7 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */ /* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */
/* Updated: 2025/02/06 14:19:04 by kcolin ### ########.fr */ /* Updated: 2025/02/06 14:25:02 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,6 +15,19 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
/*
** get the prompt to show to the user when getting a command
**
** if the terminal is a tty, the prompt is '$ ', else it is ''
*/
static const char *get_prompt(void)
{
if (isatty(STDIN_FILENO))
return ("$ ");
return ("");
}
/* /*
** get a command line using readline. ** get a command line using readline.
@ -26,7 +39,7 @@ static char *get_command(void)
{ {
char *line; char *line;
line = readline("$ "); line = readline(get_prompt());
if (line != NULL && line[0] != '\0') if (line != NULL && line[0] != '\0')
add_history(line); add_history(line);
return (line); return (line);