update: added isatty support and prompt usage

This commit is contained in:
2026-02-13 20:18:26 +01:00
parent 5df1520224
commit 3f17f7789c
4 changed files with 26 additions and 7 deletions

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/20 20:51:33 by sede-san #+# #+# */
/* Updated: 2026/02/09 18:48:34 by sede-san ### ########.fr */
/* Updated: 2026/02/13 20:12:07 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -37,6 +37,14 @@ static bool handle_eof(
return (true);
}
static void set_prompts(
t_minishell *minishell
)
{
minishell->prompt.ps1 = DEFAULT_PS1;
minishell->prompt.ps2 = DEFAULT_PS2;
}
void minishell_init(
t_minishell *minishell,
char **envp
@@ -44,6 +52,7 @@ void minishell_init(
ft_bzero(minishell, sizeof(t_minishell));
set_envp(envp, minishell);
set_builtins(minishell);
set_prompts(minishell);
if (minishell->variables.environment == NULL || minishell->builtins == NULL)
minishell_clear(minishell);
}
@@ -59,7 +68,10 @@ void minishell_run(
minishell_set_interactive_signals();
while (!minishell->exit)
{
line = readline(DEFAULT_PS1);
if (isatty(STDIN_FILENO))
line = readline(minishell->prompt.ps1);
else
line = get_next_line(STDIN_FILENO);
handle_sigint_status(minishell);
if (handle_eof(line, minishell))
continue ;

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/22 18:37:38 by sede-san #+# #+# */
/* Updated: 2026/02/13 15:12:48 by sede-san ### ########.fr */
/* Updated: 2026/02/13 18:17:00 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -238,9 +238,7 @@ t_command *command_new(
current_token = *tokens;
delimiter_token = ft_lstfind(current_token, (bool (*)(void *))is_pipe);
while (command != NULL && current_token != delimiter_token)
{
command_add_tokens(&command, &current_token);
}
*tokens = current_token;
return (command);
}