quelques bugs resolus (longue ligne ne bug plus). pas encore totalement stable

This commit is contained in:
Gautier WOJDA 2017-01-23 15:18:20 +01:00
parent 7bca444ddc
commit a8471df8a7
8 changed files with 76 additions and 125 deletions

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_readline.h :+: :+: :+: */ /* ft_readline.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 18:02:25 by sbenning #+# #+# */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/01/22 14:34:41 by gwojda ### ########.fr */ /* Updated: 2017/01/23 15:14:03 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -62,6 +62,8 @@ typedef struct s_list_history
struct s_list_history *next; struct s_list_history *next;
} t_list_history; } t_list_history;
int ft_found_next_char(char *str, size_t i);
void ft_check_end_of_line(char *str, size_t pos);
void ft_printall(char *str, size_t *pos); void ft_printall(char *str, size_t *pos);
void ft_get_beggin_with_curs(char *str, size_t *pos); void ft_get_beggin_with_curs(char *str, size_t *pos);
void ft_history(char **str, int ret, t_list_history **head, size_t *pos); void ft_history(char **str, int ret, t_list_history **head, size_t *pos);
@ -115,5 +117,4 @@ void ft_cxv(int ret, size_t *pos, char **str);
char *ft_lecture(t_list_history *head); char *ft_lecture(t_list_history *head);
void ft_prompt(void); void ft_prompt(void);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ /* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
/* Updated: 2017/01/22 15:03:13 by gwojda ### ########.fr */ /* Updated: 2017/01/23 13:32:04 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,8 +53,11 @@ char *ft_lecture(t_list_history *head)
i = 0; i = 0;
while (42) while (42)
{ {
ft_check_end_of_line(str, i);
ret = 0; ret = 0;
read(0, &ret, sizeof(int)); read(0, &ret, sizeof(int));
if (ret == TOUCHE_F6 && read(0, &ret, sizeof(int)) > 0)
continue ;
// if (ret == TOUCHE_TAB) // if (ret == TOUCHE_TAB)
// ret = ft_completion(&str, &i); // ret = ft_completion(&str, &i);
if (ret == TOUCHE_CTRL_C || ret == TOUCHE_CTRL_D) if (ret == TOUCHE_CTRL_C || ret == TOUCHE_CTRL_D)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */ /* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
/* Updated: 2017/01/21 17:13:55 by gwojda ### ########.fr */ /* Updated: 2017/01/23 15:17:18 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -47,6 +47,7 @@ void ft_home_end(char *str, int ret, size_t *pos)
*pos = 0; *pos = 0;
ft_current_str(str, *pos); ft_current_str(str, *pos);
ft_get_next_str(str, pos); ft_get_next_str(str, pos);
ft_check_end_of_line(str, *pos);
if (!str[*pos]) if (!str[*pos])
--(*pos); --(*pos);
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(str, pos);
@ -61,31 +62,39 @@ void ft_move_term(int ret, size_t *pos, char *str)
{ {
if (str[*pos] == '\n') if (str[*pos] == '\n')
{ {
tmp = *pos - 1; if (*pos)
ft_get_beggin_with_curs(str, &tmp); {
tmp = *pos - 1;
ft_get_beggin_with_curs(str, &tmp);
}
//si premiere ligne ne contient que \n, puis fleche droite -> decalage//
ft_puttermcaps("cd"); ft_puttermcaps("cd");
++(*pos); ++(*pos);
ft_current_str(str, *pos); ft_current_str(str, *pos);
ft_get_next_str(str, pos); ft_get_next_str(str, pos);
if (!str[*pos]) if (!str[*pos])
--(*pos); --(*pos);
++(*pos);
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(str, pos);
if (*pos > 0 && str[*pos - 1] == '\n')
ft_puttermcaps("nd");
} }
else else
{ {
ft_putchar(str[*pos]); ft_putchar(str[*pos]);
++(*pos); ++(*pos);
} }
if (ft_nb_last_line(str, *pos) == ft_size_term() - 1)
{
ft_putchar(' ');
ft_putchar('\b');
}
} }
else if (ret == FLECHE_GAUCHE && *pos > 0) else if (ret == FLECHE_GAUCHE && *pos > 0)
{ {
if (str[*pos - 1] == '\n') if (str[*pos - 1] == '\n')
{ {
if (*pos - 1 == 0)
{
ft_puttermcaps("cd");
--(*pos);
return ;
}
ft_puttermcaps("cd"); ft_puttermcaps("cd");
(*pos) -= 2; (*pos) -= 2;
ft_get_beggin(str, pos); ft_get_beggin(str, pos);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/06 14:32:12 by gwojda #+# #+# */ /* Created: 2017/01/06 14:32:12 by gwojda #+# #+# */
/* Updated: 2017/01/19 16:42:54 by gwojda ### ########.fr */ /* Updated: 2017/01/23 10:57:17 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -105,39 +105,3 @@ void ft_move_suppr(char *str, size_t pos)
} }
} }
} }
void ft_curse_move(char *str)
{
int i;
int count;
int prompt_size;
prompt_size = data_singleton()->line.prompt_size;
count = 0;
i = 0;
while (str[i])
{
if (str[i] == '\n')
{
count += ft_nb_line(str, i - 1);
count++;
}
++i;
}
while (i && str[i] != '\n')
{
ft_putchar('\b');
--i;
}
if (count)
{
while (count)
{
ft_puttermcaps("up");
--count;
}
while (--prompt_size + 2)
ft_puttermcaps("nd");
}
ft_puttermcaps("cd");
}

View file

@ -6,12 +6,23 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */ /* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
/* Updated: 2017/01/22 15:02:02 by gwojda ### ########.fr */ /* Updated: 2017/01/23 15:13:57 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int ft_found_next_char(char *str, size_t i)
{
while (str[i])
{
if (str[i] == '\n')
return (1);
++i;
}
return (0);
}
void ft_print(char **str, int ret, size_t *i) void ft_print(char **str, int ret, size_t *i)
{ {
int j; int j;
@ -30,23 +41,27 @@ void ft_print(char **str, int ret, size_t *i)
void ft_suppr(char **str, size_t *i) void ft_suppr(char **str, size_t *i)
{ {
size_t tmp; size_t tmp;
char boolean;
boolean = 0;
if ((*str)[*i - 1] != '\n')
boolean = 1;
--(*i); --(*i);
tmp = *i; tmp = *i;
if (boolean)
ft_get_beggin_with_curs(*str, i);
else
ft_get_beggin(*str, i);
*str = ft_remove_imput((*str), tmp); *str = ft_remove_imput((*str), tmp);
ft_get_beggin_with_curs(*str, i);
ft_puttermcaps("cd"); ft_puttermcaps("cd");
ft_current_str(*str, *i); ft_current_str(*str, *i);
ft_get_next_str(*str, i); ft_get_next_str(*str, i);
/* if (ft_nb_last_line(*str, *i) == ft_size_term() - 2) if (str[*i] && ft_found_next_char(*str, *i))
{ ++(*i);
ft_puttermcaps("nd");
ft_putnc('\b', *i - tmp);
}
else
ft_putnc('\b', *i - tmp + 1);*/
ft_putnc('\b', *i - tmp); ft_putnc('\b', *i - tmp);
(*i) = tmp; (*i) = tmp;
if (ft_strlen(*str) == 0)
*str = NULL;
} }
void ft_del(char **str, size_t *i) void ft_del(char **str, size_t *i)
@ -55,18 +70,14 @@ void ft_del(char **str, size_t *i)
tmp = *i; tmp = *i;
*str = ft_remove_imput((*str), tmp); *str = ft_remove_imput((*str), tmp);
--(*i); if (*i)
--(*i);
ft_get_beggin_with_curs(*str, i); ft_get_beggin_with_curs(*str, i);
ft_puttermcaps("cd"); ft_puttermcaps("cd");
ft_current_str(*str, *i); ft_current_str(*str, *i);
ft_get_next_str(*str, i); ft_get_next_str(*str, i);
/* if (ft_nb_last_line(*str, *i) == ft_size_term() - 2) if (str[*i])
{ ++(*i);
ft_puttermcaps("nd");
ft_putnc('\b', *i - tmp);
}
else
ft_putnc('\b', *i - tmp + 1);*/
ft_putnc('\b', *i - tmp); ft_putnc('\b', *i - tmp);
(*i) = tmp; (*i) = tmp;
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */ /* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */
/* Updated: 2017/01/22 17:20:05 by gwojda ### ########.fr */ /* Updated: 2017/01/23 11:31:36 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,13 +29,12 @@ void ft_printall(char *str, size_t *pos)
size_t pos_tmp; size_t pos_tmp;
int ret; int ret;
ret = 0;
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !str) if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !str)
return ; return ;
ft_clear_window(); ft_clear_window();
ft_prompt(); ft_prompt();
sleep(1);
pos_tmp = *pos; pos_tmp = *pos;
ft_putstr("\033[31m"); ft_putstr("\033[31m");
ft_puttermcaps("cd"); ft_puttermcaps("cd");
ft_puttermcaps("sc"); ft_puttermcaps("sc");
@ -64,6 +63,19 @@ void ft_printall(char *str, size_t *pos)
*pos = pos_tmp; *pos = pos_tmp;
} }
void ft_check_end_of_line(char *str, size_t pos)
{
if (!str)
return ;
//ft_printf("\n\n\nnd = %d\n\n", ft_nb_last_line(str, pos));
if (ft_nb_last_line(str, pos) == 0)
{
//ft_printf("\n\n\nhere\n\n");
ft_putchar(' ');
ft_puttermcaps("le");
}
}
void ft_get_beggin_with_curs(char *str, size_t *pos) void ft_get_beggin_with_curs(char *str, size_t *pos)
{ {
while ((*pos) && str[(*pos)] != '\n') while ((*pos) && str[(*pos)] != '\n')

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */ /* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */
/* Updated: 2017/01/22 11:58:06 by gwojda ### ########.fr */ /* Updated: 2017/01/23 13:40:41 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -59,7 +59,7 @@ void ft_found_prev_word(char *str, size_t *pos)
i = 0; i = 0;
if (!*pos) if (!*pos)
return ; return ;
if (!(str[*pos] == '\n' || str[*pos] == ' ')) if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' '))
{ {
ft_puttermcaps("le"); ft_puttermcaps("le");
--(*pos); --(*pos);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */ /* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */
/* Updated: 2017/01/21 14:31:47 by gwojda ### ########.fr */ /* Updated: 2017/01/23 11:23:23 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,63 +32,14 @@ int ft_get_size_prev(char *str, size_t pos)
return (len); return (len);
} }
int ft_nb_line(char *str, size_t pos)
{
int len;
len = 0;
if (!ft_get_ind_prev(str, pos))
len += data_singleton()->line.prompt_size;
len += ft_get_size_prev(str, pos);
return (len / ft_size_term());
}
int ft_nb_last_line(char *str, size_t pos) int ft_nb_last_line(char *str, size_t pos)
{ {
int len; int len;
len = 0; len = 1;
if (str[pos] == '\n') if (str[pos] == '\n')
--pos; --pos;
if (!ft_get_ind_prev(str, pos)) len += data_singleton()->line.prompt_size;
len += data_singleton()->line.prompt_size;
len += ft_get_size_prev(str, pos); len += ft_get_size_prev(str, pos);
return (len % ft_size_term()); return ((len) ? len % ft_size_term() : -1);
}
void ft_move_to_beggin(char *str, size_t *pos)
{
size_t str_len;
int prompt_size;
prompt_size = data_singleton()->line.prompt_size;
str_len = 0;
if (!str)
return ;
if (str[*pos] == '\n')
{
ft_putchar('\b');
--(*pos);
}
while (*pos && str[*pos] != '\n')
{
ft_putchar('\b');
--(*pos);
}
while (*pos && --prompt_size + 2)
ft_puttermcaps("nd");
while (*pos)
{
if (str[*pos] == '\n')
{
ft_printf("\n\n\nft_nb_line(str, *pos - 1) = %d\n\n\n", ft_nb_line(str, *pos - 1));
str_len = ft_nb_line(str, *pos - 1) + 1;
while (str_len)
{
ft_puttermcaps("up");
--str_len;
}
}
--(*pos);
}
} }