mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
read: do not display prompt if not in a tty
This commit is contained in:
parent
8bfdb04630
commit
6aabe49df1
1 changed files with 15 additions and 2 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.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.
|
||||
|
|
@ -26,7 +39,7 @@ static char *get_command(void)
|
|||
{
|
||||
char *line;
|
||||
|
||||
line = readline("$ ");
|
||||
line = readline(get_prompt());
|
||||
if (line != NULL && line[0] != '\0')
|
||||
add_history(line);
|
||||
return (line);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue