diff --git a/42sh/src/line_editing/underline_function.c b/42sh/src/line_editing/underline_function.c new file mode 100644 index 00000000..54830597 --- /dev/null +++ b/42sh/src/line_editing/underline_function.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* underline_function.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/22 20:55:24 by gwojda #+# #+# */ +/* Updated: 2017/03/22 20:56:54 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +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); + } +} + +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'); + } +}