From 2e72ad114bdae5de7a1fdae73c0dee7aa2f50505 Mon Sep 17 00:00:00 2001 From: gwojda Date: Fri, 17 Mar 2017 17:22:54 +0100 Subject: [PATCH] =?UTF-8?q?fix=20bug=20completion=20lors=20du=20multiligne?= =?UTF-8?q?=20et=20positionn=C3=A9=20sur=20une=20ligne=20!=3D=20de=20la=20?= =?UTF-8?q?premiere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 42sh/includes/completion.h | 4 +++- 42sh/src/completion/c_clear.c | 2 +- 42sh/src/completion/c_init.c | 2 +- 42sh/src/completion/c_misc.c | 2 +- 42sh/src/completion/c_output.c | 2 +- 42sh/src/completion/c_terminal.c | 20 ++++++++++++++++++-- 42sh/src/line-editing/completion.c | 4 ++-- 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 399d81cd..56ad1b8f 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/16 09:14:30 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:40:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -185,5 +185,7 @@ char *path_solver(t_comp *c, char *cmd, char *cwd); int c_exclusion_folder(t_comp *c); int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); +size_t ft_strlenw_i(char *str, size_t pos, char c); +size_t ft_strpos_i(char *str, size_t pos, char c); #endif diff --git a/42sh/src/completion/c_clear.c b/42sh/src/completion/c_clear.c index 2e1dc33b..5378d72b 100644 --- a/42sh/src/completion/c_clear.c +++ b/42sh/src/completion/c_clear.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 11:37:43 by alao #+# #+# */ -/* Updated: 2017/03/16 08:27:50 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:46:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index 7840296e..91039f74 100644 --- a/42sh/src/completion/c_init.c +++ b/42sh/src/completion/c_init.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 11:21:16 by alao #+# #+# */ -/* Updated: 2017/03/16 08:30:52 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:51:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_misc.c b/42sh/src/completion/c_misc.c index 34ee487e..92dd2101 100644 --- a/42sh/src/completion/c_misc.c +++ b/42sh/src/completion/c_misc.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/16 22:17:10 by alao #+# #+# */ -/* Updated: 2017/03/16 08:08:19 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:51:53 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index cd73c1f8..e3c207e2 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/03/16 08:48:05 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:48:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index ffc880e2..9719ad0f 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/16 09:02:14 by alao ### ########.fr */ +/* Updated: 2017/03/17 17:07:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,22 @@ void c_term_clear(t_comp *c) } } +static size_t c_virtual_position(t_comp *c) +{ + char *str; + size_t pos; + size_t virtual_pos; + + pos = c->ircmd; + virtual_pos = pos; + str = data_singleton()->line.input; + while (pos && str[pos] != '\n') + --pos; + if (str[pos] == '\n') + ++pos; + return (virtual_pos - pos); +} + /* ** Move the terminal up by the number of line needed and move it back up to ** the original position. @@ -58,7 +74,7 @@ void c_term_mv_back(t_comp *c) ft_putstr(tgetstr("cr", NULL)); i = 0; lcmd = 0; - c->rcmd ? lcmd += c->ircmd + c->prompt + 1 : 0; + c->rcmd ? lcmd += c_virtual_position(c) + c->prompt + 1 : 0; while (i < lcmd) { ft_putstr(tgetstr("nd", NULL)); diff --git a/42sh/src/line-editing/completion.c b/42sh/src/line-editing/completion.c index 18470e74..8a21df39 100644 --- a/42sh/src/line-editing/completion.c +++ b/42sh/src/line-editing/completion.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */ -/* Updated: 2017/03/17 12:13:41 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 17:22:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,7 +51,7 @@ int ft_completion(int ret, char **str, size_t *pos) ft_current_str(*str, tmp); ft_get_next_str(*str, &tmp); ft_putnc('\b', right); - *pos = ft_strleni_w(*str, pos_tmp, '\n') - right; + *pos = pos_tmp + ft_strleni_w(*str, pos_tmp, '\n') - right; } return (1); }