/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   signals.c                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: lperrey <lperrey@student.42.fr>            +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2021/10/23 18:56:53 by lperrey           #+#    #+#             */
/*   Updated: 2021/11/26 21:45:22 by lperrey          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

void	sigint_handler_interactive(int signum)
{
	(void)signum;
	write(1, "\n", 1);
	rl_on_new_line();
	rl_replace_line("", 1);
	rl_redisplay();
}

void	sigint_handler_heredoc(int signum)
{
	(void)signum;
	g_switch_heredoc_sigint = 1;
	rl_done = 1;
//	write (1, rl_line_buffer, ft_strlen(rl_line_buffer) + 1);
//	rl_line_buffer = "\004";
//	write(1, "\004", 1);
//	rl_on_new_line();
//	rl_replace_line((char *)NULL, 1);
//	rl_replace_line("\004", 1);
//	rl_replace_line("", 1);
//	rl_redisplay();
}

int set_signals_handling(struct sigaction *signal_behaviour)
{
	signal_behaviour->sa_handler = sigint_handler_interactive;
	sigaction(SIGINT, signal_behaviour, NULL);
	signal_behaviour->sa_handler = SIG_IGN;
	sigaction(SIGQUIT, signal_behaviour, NULL);
	return (1);
}
