fix bugs multiligne c/c/p
This commit is contained in:
parent
a40577fce9
commit
59d37acc61
5 changed files with 90 additions and 49 deletions
|
|
@ -268,6 +268,7 @@ line_editing/queue.c\
|
||||||
line_editing/readline.c\
|
line_editing/readline.c\
|
||||||
line_editing/resize.c\
|
line_editing/resize.c\
|
||||||
line_editing/underline_function.c\
|
line_editing/underline_function.c\
|
||||||
|
line_editing/underline_reset.c\
|
||||||
main/data_exit.c\
|
main/data_exit.c\
|
||||||
main/data_init.c\
|
main/data_init.c\
|
||||||
main/data_singleton.c\
|
main/data_singleton.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/22 20:59:35 by gwojda ### ########.fr */
|
/* Updated: 2017/03/22 21:14:55 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -129,6 +129,9 @@ void sigwinch_resize(int sig);
|
||||||
size_t ft_hist_len(void);
|
size_t ft_hist_len(void);
|
||||||
void underline_right(char **str, size_t *pos, size_t pos_ref);
|
void underline_right(char **str, size_t *pos, size_t pos_ref);
|
||||||
void underline_left(char **str, size_t *pos, size_t pos_ref);
|
void underline_left(char **str, size_t *pos, size_t pos_ref);
|
||||||
|
void reset_term(char **str, size_t *pos);
|
||||||
|
void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp);
|
||||||
|
int reset_term_hard(void);
|
||||||
|
|
||||||
int ft_read_stdin(char **input);
|
int ft_read_stdin(char **input);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,54 +6,12 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
|
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/22 20:58:12 by gwojda ### ########.fr */
|
/* Updated: 2017/03/22 21:14:34 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
static void reset_term(char **str, size_t *pos)
|
|
||||||
{
|
|
||||||
size_t pos_ref;
|
|
||||||
|
|
||||||
pos_ref = *pos;
|
|
||||||
if (*pos)
|
|
||||||
{
|
|
||||||
--(*pos);
|
|
||||||
ft_get_beggin_with_curs(*str, pos);
|
|
||||||
}
|
|
||||||
ft_puttermcaps("cd");
|
|
||||||
ft_current_str(*str, *pos);
|
|
||||||
ft_get_next_str(*str, pos);
|
|
||||||
ft_putnc('\b', *pos - pos_ref);
|
|
||||||
(*pos) = pos_ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp)
|
|
||||||
{
|
|
||||||
size_t pos_ref;
|
|
||||||
|
|
||||||
pos_ref = *pos;
|
|
||||||
if (!data_singleton()->line.pos_tmp)
|
|
||||||
pos_ref += ft_strlen(data_singleton()->line.copy_tmp);
|
|
||||||
while (*copy_tmp)
|
|
||||||
{
|
|
||||||
--pos_ref;
|
|
||||||
*str = ft_remove_imput(*str, pos_ref);
|
|
||||||
++copy_tmp;
|
|
||||||
}
|
|
||||||
if (*pos)
|
|
||||||
{
|
|
||||||
--(*pos);
|
|
||||||
ft_get_beggin_with_curs(*str, pos);
|
|
||||||
}
|
|
||||||
ft_puttermcaps("cd");
|
|
||||||
ft_current_str(*str, *pos);
|
|
||||||
ft_get_next_str(*str, pos);
|
|
||||||
ft_putnc('\b', *pos - pos_ref);
|
|
||||||
(*pos) = pos_ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_x(char **str, size_t *pos)
|
int ft_x(char **str, size_t *pos)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -70,7 +28,7 @@ int ft_x(char **str, size_t *pos)
|
||||||
if (read(STDIN, &ret, sizeof(int)) < 0)
|
if (read(STDIN, &ret, sizeof(int)) < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
if ((*str)[*pos] == '\n')
|
if ((*str)[*pos] == '\n')
|
||||||
return (0);
|
return (reset_term_hard());
|
||||||
if (ret == FLECHE_GAUCHE)
|
if (ret == FLECHE_GAUCHE)
|
||||||
underline_left(str, pos, pos_ref);
|
underline_left(str, pos, pos_ref);
|
||||||
else if (ret == FLECHE_DROITE)
|
else if (ret == FLECHE_DROITE)
|
||||||
|
|
@ -99,7 +57,7 @@ int ft_c(char **str, size_t *pos)
|
||||||
if (read(STDIN, &ret, sizeof(int)) < 0)
|
if (read(STDIN, &ret, sizeof(int)) < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
if ((*str)[*pos] == '\n')
|
if ((*str)[*pos] == '\n')
|
||||||
return (0);
|
return (reset_term_hard());
|
||||||
if (ret == FLECHE_GAUCHE)
|
if (ret == FLECHE_GAUCHE)
|
||||||
underline_left(str, pos, pos_ref);
|
underline_left(str, pos, pos_ref);
|
||||||
else if (ret == FLECHE_DROITE)
|
else if (ret == FLECHE_DROITE)
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,24 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/22 20:55:24 by gwojda #+# #+# */
|
/* Created: 2017/03/22 20:55:24 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/22 20:56:54 by gwojda ### ########.fr */
|
/* Updated: 2017/03/22 21:28:31 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void underline_right(char **str, size_t *pos, size_t pos_ref)
|
static void underline_check_end_of_line(char *str, size_t pos)
|
||||||
|
{
|
||||||
|
if (!str)
|
||||||
|
return ;
|
||||||
|
if (ft_nb_last_line(str, pos) == 0)
|
||||||
|
{
|
||||||
|
ft_putchar(str[pos]);
|
||||||
|
ft_puttermcaps("le");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void underline_right(char **str, size_t *pos, size_t pos_ref)
|
||||||
{
|
{
|
||||||
if (!(*pos < ft_strlen(*str)))
|
if (!(*pos < ft_strlen(*str)))
|
||||||
return ;
|
return ;
|
||||||
|
|
@ -25,6 +36,7 @@ void underline_right(char **str, size_t *pos, size_t pos_ref)
|
||||||
ft_puttermcaps("me");
|
ft_puttermcaps("me");
|
||||||
++(data_singleton()->line.pos_tmp);
|
++(data_singleton()->line.pos_tmp);
|
||||||
++(*pos);
|
++(*pos);
|
||||||
|
underline_check_end_of_line(*str, *pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -34,10 +46,11 @@ void underline_right(char **str, size_t *pos, size_t pos_ref)
|
||||||
if (data_singleton()->line.pos_tmp)
|
if (data_singleton()->line.pos_tmp)
|
||||||
--(data_singleton()->line.pos_tmp);
|
--(data_singleton()->line.pos_tmp);
|
||||||
++(*pos);
|
++(*pos);
|
||||||
|
underline_check_end_of_line(*str, *pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void underline_left(char **str, size_t *pos, size_t pos_ref)
|
void underline_left(char **str, size_t *pos, size_t pos_ref)
|
||||||
{
|
{
|
||||||
if (!*pos)
|
if (!*pos)
|
||||||
return ;
|
return ;
|
||||||
|
|
@ -46,6 +59,7 @@ void underline_left(char **str, size_t *pos, size_t pos_ref)
|
||||||
--(*pos);
|
--(*pos);
|
||||||
ft_putchar('\b');
|
ft_putchar('\b');
|
||||||
ft_putchar((*str)[*pos]);
|
ft_putchar((*str)[*pos]);
|
||||||
|
underline_check_end_of_line(*str, *pos + 1);
|
||||||
ft_putchar('\b');
|
ft_putchar('\b');
|
||||||
data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()->
|
data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()->
|
||||||
line.copy_tmp, data_singleton()->line.pos_tmp);
|
line.copy_tmp, data_singleton()->line.pos_tmp);
|
||||||
|
|
@ -61,6 +75,7 @@ void underline_left(char **str, size_t *pos, size_t pos_ref)
|
||||||
data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()->
|
data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()->
|
||||||
line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp);
|
line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp);
|
||||||
ft_putchar((*str)[*pos]);
|
ft_putchar((*str)[*pos]);
|
||||||
|
underline_check_end_of_line(*str, *pos + 1);
|
||||||
ft_puttermcaps("me");
|
ft_puttermcaps("me");
|
||||||
ft_putchar('\b');
|
ft_putchar('\b');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
64
42sh/src/line_editing/underline_reset.c
Normal file
64
42sh/src/line_editing/underline_reset.c
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* underline_reset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/22 21:14:07 by gwojda #+# #+# */
|
||||||
|
/* Updated: 2017/03/22 21:16:24 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void reset_term(char **str, size_t *pos)
|
||||||
|
{
|
||||||
|
size_t pos_ref;
|
||||||
|
|
||||||
|
pos_ref = *pos;
|
||||||
|
if (*pos)
|
||||||
|
{
|
||||||
|
--(*pos);
|
||||||
|
ft_get_beggin_with_curs(*str, pos);
|
||||||
|
}
|
||||||
|
ft_puttermcaps("cd");
|
||||||
|
ft_current_str(*str, *pos);
|
||||||
|
ft_get_next_str(*str, pos);
|
||||||
|
ft_putnc('\b', *pos - pos_ref);
|
||||||
|
(*pos) = pos_ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp)
|
||||||
|
{
|
||||||
|
size_t pos_ref;
|
||||||
|
|
||||||
|
pos_ref = *pos;
|
||||||
|
if (!data_singleton()->line.pos_tmp)
|
||||||
|
pos_ref += ft_strlen(data_singleton()->line.copy_tmp);
|
||||||
|
while (*copy_tmp)
|
||||||
|
{
|
||||||
|
--pos_ref;
|
||||||
|
*str = ft_remove_imput(*str, pos_ref);
|
||||||
|
++copy_tmp;
|
||||||
|
}
|
||||||
|
if (*pos)
|
||||||
|
{
|
||||||
|
--(*pos);
|
||||||
|
ft_get_beggin_with_curs(*str, pos);
|
||||||
|
}
|
||||||
|
ft_puttermcaps("cd");
|
||||||
|
ft_current_str(*str, *pos);
|
||||||
|
ft_get_next_str(*str, pos);
|
||||||
|
ft_putnc('\b', *pos - pos_ref);
|
||||||
|
(*pos) = pos_ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
int reset_term_hard(void)
|
||||||
|
{
|
||||||
|
ft_putnc('\b', ft_strlen(data_singleton()->line.copy_tmp));
|
||||||
|
ft_putstr(data_singleton()->line.copy_tmp);
|
||||||
|
ft_strdel(&data_singleton()->line.copy_tmp);
|
||||||
|
data_singleton()->line.pos_tmp = 0;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue