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/22 19:10:13 by sede-san #+# #+# */
/* Updated: 2026/02/12 20:19:23 by sede-san ### ########.fr */
/* Updated: 2026/02/13 20:06:08 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -66,6 +66,13 @@ typedef struct s_variables
// char **internal;
} t_variables;
typedef struct s_prompt
{
const char *ps1; // primary prompt string
const char *ps2; // secondary prompt string for multiline input
} t_prompt;
/**
* @brief Main minishell structure containing global state information
*
@@ -78,6 +85,7 @@ typedef struct s_minishell
{
t_variables variables;
t_hashmap *builtins;
t_prompt prompt;
uint8_t exit_status;
bool exit;
} t_minishell;

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/20 16:35:10 by sede-san #+# #+# */
/* Updated: 2026/02/10 22:12:58 by sede-san ### ########.fr */
/* Updated: 2026/02/13 20:12:25 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,6 +15,7 @@
# include "libft.h"
# include "ft_printf.h"
# include "get_next_line.h"
# include "chardefs.h"
# include <stdbool.h>
# include <stdint.h>

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);
}