From 6ab0634d4cfe89c1a8a341cad42ed49f14f5f7d4 Mon Sep 17 00:00:00 2001 From: m600x Date: Fri, 3 Feb 2017 15:49:03 +0100 Subject: [PATCH] Reworked autocompletion multichoice --- 42sh/includes/completion.h | 4 ++-- 42sh/src/completion/c_output.c | 23 ++++++++++++++++------- 42sh/src/completion/completion.c | 4 ++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 36902c8a..86e5e57f 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/02/03 13:37:11 by alao ### ########.fr */ +/* Updated: 2017/02/03 15:47:35 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -90,7 +90,7 @@ int c_sizing(t_comp *c); ** Output functions. */ -int c_updater(t_comp *c); +int c_updater(t_comp *c, char *select); int c_gtfo(t_comp *c, long int keypress); /* diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index cc703143..3273d4b8 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/03 15:33:53 by gwojda ### ########.fr */ +/* Updated: 2017/02/03 15:47:16 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,19 +20,19 @@ ** Once that done, it will clear all the memory related and return zero. */ -int c_updater(t_comp *c) +int c_updater(t_comp *c, char *select) { char *tmp; char *rt; int new_pos; DG("\tUpdater"); - DG("RCMD [%s] match [%s] Candidat [%s]", c->rcmd, c->match, c->lst->name); + DG("RCMD [%s] match [%s] Candidat [%s]", c->rcmd, c->match, select); tmp = NULL; rt = NULL; - new_pos = c->ircmd + (ft_strlen(c->lst->name) - ft_strlen(c->match)) + 1; + new_pos = c->ircmd + (ft_strlen(select) - ft_strlen(c->match)) + 1; tmp = ft_strsub(c->rcmd, 0, ft_strlen(c->rcmd) - ft_strlen(c->match)); - rt = ft_strjoin(tmp, c->lst->name); + rt = ft_strjoin(tmp, select); tmp ? ft_memdel((void *)&tmp) : (0); if (c->trail) data_singleton()->line.input = ft_strjoin(rt, c->trail); @@ -52,7 +52,16 @@ int c_updater(t_comp *c) int c_gtfo(t_comp *c, long int keypress) { + t_clst *ptr; + DG("It's time to GTFO. Keypress [%d]", keypress); - (void)c; - return (0); + if (keypress != 10) + { + c_clear(data_singleton()); + return (0); + } + ptr = c->lst; + while (!ptr->cursor) + ptr = ptr->next; + return (c_updater(c, ptr->name)); } diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index f63bc0ea..af316a74 100644 --- a/42sh/src/completion/completion.c +++ b/42sh/src/completion/completion.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/09/20 14:50:33 by alao #+# #+# */ -/* Updated: 2017/02/03 15:39:26 by gwojda ### ########.fr */ +/* Updated: 2017/02/03 15:47:19 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,7 +83,7 @@ static int c_dispatcher(t_data *s) c_clear(s); } else if (s->comp && s->comp->lst == s->comp->lst->next) - return (c_updater(s->comp)); + return (c_updater(s->comp, s->comp->lst->name)); else if (s->comp && s->comp->lst != s->comp->lst->next) { c_term_mv_down(s->comp);