From a8471df8a7891a54e084ba319675a32d82d4e314 Mon Sep 17 00:00:00 2001 From: Gautier WOJDA Date: Mon, 23 Jan 2017 15:18:20 +0100 Subject: [PATCH] quelques bugs resolus (longue ligne ne bug plus). pas encore totalement stable --- 42sh/includes/ft_readline.h | 9 ++-- 42sh/src/line-editing/get_touch.c | 5 +- 42sh/src/line-editing/get_touch_toolz_2.c | 25 ++++++---- 42sh/src/line-editing/line_return_toolz.c | 38 +-------------- 42sh/src/line-editing/print_and_del.c | 45 +++++++++++------- 42sh/src/line-editing/tool_line_2.c | 18 +++++-- 42sh/src/line-editing/toolz_parseur.c | 4 +- 42sh/src/line-editing/toolz_termcaps.c | 57 ++--------------------- 8 files changed, 76 insertions(+), 125 deletions(-) diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index ee0dcca6..4e30cff8 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_readline.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ +/* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/42sh/src/line-editing/get_touch.c b/42sh/src/line-editing/get_touch.c index 07281fa2..95fe46c5 100644 --- a/42sh/src/line-editing/get_touch.c +++ b/42sh/src/line-editing/get_touch.c @@ -6,7 +6,7 @@ /* 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; 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) diff --git a/42sh/src/line-editing/get_touch_toolz_2.c b/42sh/src/line-editing/get_touch_toolz_2.c index 265add6f..8419617e 100644 --- a/42sh/src/line-editing/get_touch_toolz_2.c +++ b/42sh/src/line-editing/get_touch_toolz_2.c @@ -6,7 +6,7 @@ /* 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; 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); @@ -61,31 +62,39 @@ void ft_move_term(int ret, size_t *pos, char *str) { if (str[*pos] == '\n') { - tmp = *pos - 1; - ft_get_beggin_with_curs(str, &tmp); + 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); diff --git a/42sh/src/line-editing/line_return_toolz.c b/42sh/src/line-editing/line_return_toolz.c index 7a2e60ef..454fe978 100644 --- a/42sh/src/line-editing/line_return_toolz.c +++ b/42sh/src/line-editing/line_return_toolz.c @@ -6,7 +6,7 @@ /* 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"); -} diff --git a/42sh/src/line-editing/print_and_del.c b/42sh/src/line-editing/print_and_del.c index 8493e3c9..1183b994 100644 --- a/42sh/src/line-editing/print_and_del.c +++ b/42sh/src/line-editing/print_and_del.c @@ -6,12 +6,23 @@ /* 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" +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; + if (boolean) + ft_get_beggin_with_curs(*str, i); + else + ft_get_beggin(*str, i); *str = ft_remove_imput((*str), tmp); - 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] && 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); - --(*i); + 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; } diff --git a/42sh/src/line-editing/tool_line_2.c b/42sh/src/line-editing/tool_line_2.c index e97c1458..8b5b5af5 100644 --- a/42sh/src/line-editing/tool_line_2.c +++ b/42sh/src/line-editing/tool_line_2.c @@ -6,7 +6,7 @@ /* 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; 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') diff --git a/42sh/src/line-editing/toolz_parseur.c b/42sh/src/line-editing/toolz_parseur.c index 465063d8..cd2c8d34 100644 --- a/42sh/src/line-editing/toolz_parseur.c +++ b/42sh/src/line-editing/toolz_parseur.c @@ -6,7 +6,7 @@ /* 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; if (!*pos) return ; - if (!(str[*pos] == '\n' || str[*pos] == ' ')) + if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' ')) { ft_puttermcaps("le"); --(*pos); diff --git a/42sh/src/line-editing/toolz_termcaps.c b/42sh/src/line-editing/toolz_termcaps.c index d33c3d35..6892ac83 100644 --- a/42sh/src/line-editing/toolz_termcaps.c +++ b/42sh/src/line-editing/toolz_termcaps.c @@ -6,7 +6,7 @@ /* 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); } -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 += 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); }