diff --git a/42sh/Makefile b/42sh/Makefile index ab23380f..638cfa8c 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/10 08:47:51 by alao ### ########.fr # +# Updated: 2017/03/10 09:14:50 by alao ### ########.fr # # # # **************************************************************************** # @@ -46,6 +46,7 @@ builtin/builtin_unsetenv.c\ builtin/is_builtin.c\ c_seek_env.c\ completion/c_abs_path.c\ +completion/c_arrow.c\ completion/c_binary.c\ completion/c_clear.c\ completion/c_files.c\ @@ -242,7 +243,7 @@ NB = $(words $(SRC_BASE)) INDEX = 0 all : - @make -f $(NAME) + @make $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) @$(CC) $(FLAGS) $(D_FLAGS) \ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 13bac1cc..88aad82c 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/10 08:31:49 by alao ### ########.fr */ +/* Updated: 2017/03/10 09:15:27 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -176,5 +176,6 @@ int c_glob_matching(void); void c_add_to_lst(t_comp *c, t_clst *node); int c_seek_env(t_comp *c, char *current_word); void c_seek_abs_path(t_comp *c, char *current_word); +void c_arrow(t_comp *c, long int keypress); #endif diff --git a/42sh/src/completion/c_arrow.c b/42sh/src/completion/c_arrow.c new file mode 100644 index 00000000..10476742 --- /dev/null +++ b/42sh/src/completion/c_arrow.c @@ -0,0 +1,87 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_arrow.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: alao +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/10 09:04:42 by alao #+# #+# */ +/* Updated: 2017/03/10 09:57:44 by alao ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "completion.h" + +static void c_arrow_right(t_comp *c) +{ + t_clst *ptr; + int i; + + ptr = c->lst; + i = 0; + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + while (i < c->c_line) + { + ptr = ptr->next; + if (ptr == c->lst) + i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); + i++; + } + ptr->cursor = 1; +} + +static void c_arrow_left(t_comp *c) +{ + t_clst *ptr; + int i; + + ptr = c->lst; + i = 0; + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + while (i < c->c_line) + { + ptr = ptr->prev; + if (ptr == c->lst) + i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); + i++; + } + ptr->cursor = 1; +} + +static void c_arrow_down(t_comp *c) +{ + t_clst *ptr; + + ptr = c->lst; + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + ptr->next->cursor = 1; +} + +static void c_arrow_up(t_comp *c) +{ + t_clst *ptr; + + ptr = c->lst; + while (!ptr->cursor) + ptr = ptr->next; + ptr->cursor = 0; + ptr->prev->cursor = 1; +} + +void c_arrow(t_comp *c, long int keypress) +{ + if (keypress == 4283163) + c_arrow_up(c); + if (keypress == 4348699) + c_arrow_down(c); + if (keypress == 4479771) + c_arrow_left(c); + if (keypress == 4414235) + c_arrow_right(c); +} diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index 3e37f799..72c91f8b 100644 --- a/42sh/src/completion/c_output.c +++ b/42sh/src/completion/c_output.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:10:38 by alao #+# #+# */ -/* Updated: 2017/02/17 13:44:51 by alao ### ########.fr */ +/* Updated: 2017/03/10 09:05:23 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -114,5 +114,11 @@ int c_gtfo(t_comp *c, long int keypress) c_updater(c, ptr->name); return (1); } + if (keypress == 4283163 || keypress == 4348699 + || keypress == 4479771 || keypress == 4414235) + { + c_arrow(c, keypress); + return (0); + } return ((c_rematch(c, keypress)) ? (0) : (1)); } diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index 83800ecf..aa0e65b1 100644 --- a/42sh/src/completion/c_terminal.c +++ b/42sh/src/completion/c_terminal.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/11 10:44:40 by alao #+# #+# */ -/* Updated: 2017/03/10 08:46:13 by alao ### ########.fr */ +/* Updated: 2017/03/10 10:00:03 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,7 @@ void c_term_mv_down(t_comp *c) int i; i = 0; - while (i < c->m_size) + while (i < c->m_size + 1) { ft_putstr(tgetstr("do", NULL)); ft_putstr(tgetstr("cd", NULL));