diff --git a/42sh/Makefile b/42sh/Makefile index 3f641915..221f230c 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -267,6 +267,7 @@ line_editing/print_and_del.c\ line_editing/queue.c\ line_editing/readline.c\ line_editing/resize.c\ +line_editing/underline_function.c\ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 4a900517..47c887d6 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/22 18:02:05 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 20:57:29 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -129,6 +129,8 @@ int ft_nb_of_line(char *str, size_t pos); int ft_get_size_prev(char *str, size_t pos); void sigwinch_resize(int sig); size_t ft_hist_len(void); +void underline_right(char **str, size_t *pos, size_t pos_ref); +void underline_left(char **str, size_t *pos, size_t pos_ref); int ft_read_stdin(char **input); diff --git a/42sh/src/line_editing/copy_cut_paste.c b/42sh/src/line_editing/copy_cut_paste.c index bdff7919..5e524c15 100644 --- a/42sh/src/line_editing/copy_cut_paste.c +++ b/42sh/src/line_editing/copy_cut_paste.c @@ -6,41 +6,12 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/03/22 20:52:24 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 20:58:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_v(char **str, size_t *pos) -{ - size_t tmp_pos; - int i; - char *tmp; - - i = -1; - tmp_pos = *pos; - tmp = data_singleton()->line.copy_tmp; - if (!*str || !tmp) - return (0); - while (tmp[++i]) - { - if (ft_strlen(*str) > SIZE_LINE) - break ; - *str = ft_realloc_imput(*str, tmp[i], *pos + i); - } - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(*str, pos); - } - ft_current_str(*str, *pos); - ft_get_next_str(*str, pos); - ft_putnc('\b', *pos - tmp_pos); - *pos = tmp_pos; - return (0); -} - static void reset_term(char **str, size_t *pos) { size_t pos_ref; @@ -58,56 +29,6 @@ static void reset_term(char **str, size_t *pos) (*pos) = pos_ref; } -static void underline_right(char **str, size_t *pos, size_t pos_ref) -{ - if (!(*pos < ft_strlen(*str))) - return ; - if (*pos >= pos_ref) - { - ft_puttermcaps("mr"); - data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()->line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); - ft_putchar((*str)[*pos]); - ft_puttermcaps("me"); - ++(data_singleton()->line.pos_tmp); - ++(*pos); - } - else - { - data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()->line.copy_tmp, data_singleton()->line.pos_tmp); - ft_putchar((*str)[*pos]); - if (data_singleton()->line.pos_tmp) - --(data_singleton()->line.pos_tmp); - ++(*pos); - } -} - -static void underline_left(char **str, size_t *pos, size_t pos_ref) -{ - if (!*pos) - return ; - if (*pos > pos_ref) - { - --(*pos); - ft_putchar('\b'); - ft_putchar((*str)[*pos]); - ft_putchar('\b'); - data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()->line.copy_tmp, data_singleton()->line.pos_tmp); - if (data_singleton()->line.pos_tmp) - --(data_singleton()->line.pos_tmp); - } - else - { - data_singleton()->line.pos_tmp = 0; - --(*pos); - ft_putchar('\b'); - ft_puttermcaps("mr"); - data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()->line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); - ft_putchar((*str)[*pos]); - ft_puttermcaps("me"); - ft_putchar('\b'); - } -} - static void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp) { size_t pos_ref; @@ -130,7 +51,7 @@ static void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp) ft_current_str(*str, *pos); ft_get_next_str(*str, pos); ft_putnc('\b', *pos - pos_ref); - (*pos) = pos_ref; + (*pos) = pos_ref; } int ft_x(char **str, size_t *pos) @@ -189,3 +110,32 @@ int ft_c(char **str, size_t *pos) reset_term(str, pos); return (0); } + +int ft_v(char **str, size_t *pos) +{ + size_t tmp_pos; + int i; + char *tmp; + + i = -1; + tmp_pos = *pos; + tmp = data_singleton()->line.copy_tmp; + if (!*str || !tmp) + return (0); + while (tmp[++i]) + { + if (ft_strlen(*str) > SIZE_LINE) + break ; + *str = ft_realloc_imput(*str, tmp[i], *pos + i); + } + if (*pos) + { + --(*pos); + ft_get_beggin_with_curs(*str, pos); + } + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + ft_putnc('\b', *pos - tmp_pos); + *pos = tmp_pos; + return (0); +}