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 :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 18:02:25 by sbenning #+# #+# */
/* Updated: 2017/01/22 14:34:41 by gwojda ### ########.fr */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/01/23 15:14:03 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,6 +62,8 @@ typedef struct s_list_history
struct s_list_history *next;
} 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_get_beggin_with_curs(char *str, 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);
void ft_prompt(void);
#endif

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
while (42)
{
ft_check_end_of_line(str, i);
ret = 0;
read(0, &ret, sizeof(int));
if (ret == TOUCHE_F6 && read(0, &ret, sizeof(int)) > 0)
continue ;
// if (ret == TOUCHE_TAB)
// ret = ft_completion(&str, &i);
if (ret == TOUCHE_CTRL_C || ret == TOUCHE_CTRL_D)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
ft_check_end_of_line(str, *pos);
if (!str[*pos])
--(*pos);
ft_get_beggin_with_curs(str, pos);
@ -60,32 +61,40 @@ void ft_move_term(int ret, size_t *pos, char *str)
if (ret == FLECHE_DROITE && str && ft_strlen(str) > *pos)
{
if (str[*pos] == '\n')
{
if (*pos)
{
tmp = *pos - 1;
ft_get_beggin_with_curs(str, &tmp);
}
//si premiere ligne ne contient que \n, puis fleche droite -> decalage//
ft_puttermcaps("cd");
++(*pos);
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
if (!str[*pos])
--(*pos);
++(*pos);
ft_get_beggin_with_curs(str, pos);
if (*pos > 0 && str[*pos - 1] == '\n')
ft_puttermcaps("nd");
}
else
{
ft_putchar(str[*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)
{
if (str[*pos - 1] == '\n')
{
if (*pos - 1 == 0)
{
ft_puttermcaps("cd");
--(*pos);
return ;
}
ft_puttermcaps("cd");
(*pos) -= 2;
ft_get_beggin(str, pos);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"
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)
{
int j;
@ -30,23 +41,27 @@ void ft_print(char **str, int ret, size_t *i)
void ft_suppr(char **str, size_t *i)
{
size_t tmp;
char boolean;
boolean = 0;
if ((*str)[*i - 1] != '\n')
boolean = 1;
--(*i);
tmp = *i;
*str = ft_remove_imput((*str), tmp);
if (boolean)
ft_get_beggin_with_curs(*str, i);
else
ft_get_beggin(*str, i);
*str = ft_remove_imput((*str), tmp);
ft_puttermcaps("cd");
ft_current_str(*str, *i);
ft_get_next_str(*str, i);
/* if (ft_nb_last_line(*str, *i) == ft_size_term() - 2)
{
ft_puttermcaps("nd");
ft_putnc('\b', *i - tmp);
}
else
ft_putnc('\b', *i - tmp + 1);*/
if (str[*i] && ft_found_next_char(*str, *i))
++(*i);
ft_putnc('\b', *i - tmp);
(*i) = tmp;
if (ft_strlen(*str) == 0)
*str = NULL;
}
void ft_del(char **str, size_t *i)
@ -55,18 +70,14 @@ void ft_del(char **str, size_t *i)
tmp = *i;
*str = ft_remove_imput((*str), tmp);
if (*i)
--(*i);
ft_get_beggin_with_curs(*str, i);
ft_puttermcaps("cd");
ft_current_str(*str, *i);
ft_get_next_str(*str, i);
/* if (ft_nb_last_line(*str, *i) == ft_size_term() - 2)
{
ft_puttermcaps("nd");
ft_putnc('\b', *i - tmp);
}
else
ft_putnc('\b', *i - tmp + 1);*/
if (str[*i])
++(*i);
ft_putnc('\b', *i - tmp);
(*i) = tmp;
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
int ret;
ret = 0;
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !str)
return ;
ft_clear_window();
ft_prompt();
sleep(1);
pos_tmp = *pos;
ft_putstr("\033[31m");
ft_puttermcaps("cd");
ft_puttermcaps("sc");
@ -64,6 +63,19 @@ void ft_printall(char *str, size_t *pos)
*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)
{
while ((*pos) && str[(*pos)] != '\n')

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
if (!*pos)
return ;
if (!(str[*pos] == '\n' || str[*pos] == ' '))
if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' '))
{
ft_puttermcaps("le");
--(*pos);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
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 len;
len = 0;
len = 1;
if (str[pos] == '\n')
--pos;
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());
}
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);
}
return ((len) ? len % ft_size_term() : -1);
}