From 40f852345e34ca994830702894fd862f42155c30 Mon Sep 17 00:00:00 2001 From: gwojda Date: Sat, 18 Mar 2017 15:20:38 +0100 Subject: [PATCH] fix histo avec ! + completion multiligne + rematch --- 42sh/Makefile | 2 +- 42sh/libft/src/str/ft_strlen.c | 4 +-- 42sh/src/completion/c_terminal.c | 46 ++++++++++++------------ 42sh/src/history/history_parsing.c | 20 +++++++++-- 42sh/src/history/surch_in_history.c | 12 +++---- 42sh/src/line-editing/control_features.c | 2 +- 42sh/src/line-editing/ft_prompt.c | 4 +-- 42sh/src/line-editing/readline.c | 3 +- 8 files changed, 51 insertions(+), 42 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index a7e2b495..4d93acf3 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/18 14:15:21 by gwojda ### ########.fr # +# Updated: 2017/03/18 14:17:54 by gwojda ### ########.fr # # # # **************************************************************************** # diff --git a/42sh/libft/src/str/ft_strlen.c b/42sh/libft/src/str/ft_strlen.c index 6b6f4269..9b65ad39 100644 --- a/42sh/libft/src/str/ft_strlen.c +++ b/42sh/libft/src/str/ft_strlen.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */ -/* Updated: 2017/03/07 11:06:41 by ariard ### ########.fr */ +/* Updated: 2017/03/18 14:25:09 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index 9719ad0f..a46135e3 100644 --- a/42sh/src/completion/c_terminal.c +++ b/42sh/src/completion/c_terminal.c @@ -6,34 +6,12 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/11 10:44:40 by alao #+# #+# */ -/* Updated: 2017/03/17 17:07:20 by gwojda ### ########.fr */ +/* Updated: 2017/03/18 15:19:18 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" -/* -** Clear the previous list from the screen and restore the same position. -*/ - -void c_term_clear(t_comp *c) -{ - int i; - int lcmd; - - ft_putstr(tgetstr("do", NULL)); - ft_putstr(tgetstr("cd", NULL)); - ft_putstr(tgetstr("up", NULL)); - i = 0; - lcmd = 0; - c->rcmd ? lcmd += c->ircmd + c->prompt + 1 : 0; - while (i < lcmd) - { - ft_putstr(tgetstr("nd", NULL)); - i++; - } -} - static size_t c_virtual_position(t_comp *c) { char *str; @@ -50,6 +28,28 @@ static size_t c_virtual_position(t_comp *c) return (virtual_pos - pos); } +/* +** Clear the previous list from the screen and restore the same position. +*/ + +void c_term_clear(t_comp *c) +{ + int i; + int lcmd; + + ft_putstr(tgetstr("do", NULL)); + ft_putstr(tgetstr("cd", NULL)); + ft_putstr(tgetstr("up", NULL)); + i = 0; + lcmd = 0; + c->rcmd ? lcmd += c_virtual_position(c) + c->prompt + 1 : 0; + while (i < lcmd) + { + ft_putstr(tgetstr("nd", NULL)); + i++; + } +} + /* ** Move the terminal up by the number of line needed and move it back up to ** the original position. diff --git a/42sh/src/history/history_parsing.c b/42sh/src/history/history_parsing.c index 9bdffdd6..494c07d2 100644 --- a/42sh/src/history/history_parsing.c +++ b/42sh/src/history/history_parsing.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */ -/* Updated: 2017/03/17 12:10:17 by gwojda ### ########.fr */ +/* Updated: 2017/03/18 15:04:16 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,20 @@ static int ft_history_parsing_3(char *str, int *i) return (1); } +static int ft_history_parsing_2(int has_prompt, char **input) +{ + data_singleton()->line.pos = 0; + has_prompt ? ft_prompt() : ft_putstr("> "); + if (ft_read_stdin(input) < 0) + return (-1); + if (data_singleton()->line.input) + ft_current_str(data_singleton()->line.input, + data_singleton()->line.pos); + ft_putchar('\n'); + ft_history_parsing(has_prompt, input); + return (0); +} + int ft_history_parsing(int has_prompt, char **input) { int i; @@ -81,7 +95,7 @@ int ft_history_parsing(int has_prompt, char **input) } ++i; } - if (boolean) - return (readline(has_prompt, input)); + if (boolean && ft_history_parsing_2(has_prompt, input)) + return (-1); return (0); } diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 0920de9c..69c3a8a0 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ -/* Updated: 2017/03/17 16:06:09 by gwojda ### ########.fr */ +/* Updated: 2017/03/18 14:29:15 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,19 +79,17 @@ int ft_surch_in_history(char **str, size_t *pos) ft_give_new_prompt(str_srch, srch_pos); ret = 0; read(0, &ret, sizeof(int)); - if (ft_isprint(ret)) - { - if (ft_surch_and_realloc(str, &str_srch, ret, &srch_pos) < 0) + if (ft_isprint(ret) && + ft_surch_and_realloc(str, &str_srch, ret, &srch_pos) < 0) return (-1); - } - else if (ret == 127 && srch_pos) + else if (!ft_isprint(ret) && ret == 127 && srch_pos) { --srch_pos; str_srch = ft_remove_imput(str_srch, srch_pos); ft_puttermcaps("le"); *str = (!*str_srch) ? NULL : ft_strget_history(str_srch); } - else if (ret != 127) + else if (ret != 127 && !ft_isprint(ret)) break ; } ft_modify_str(str_srch, srch_pos, str, pos); diff --git a/42sh/src/line-editing/control_features.c b/42sh/src/line-editing/control_features.c index df2a351a..8db2f684 100644 --- a/42sh/src/line-editing/control_features.c +++ b/42sh/src/line-editing/control_features.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ -/* Updated: 2017/03/17 12:32:16 by gwojda ### ########.fr */ +/* Updated: 2017/03/18 15:13:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index b3a6331d..4fc017fd 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/03/18 00:14:42 by wescande ### ########.fr */ +/* Updated: 2017/03/18 14:23:53 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,8 +92,6 @@ static int ft_currend_dir(void) return (ft_strlen(currend_dir + 1)); } -//Une fois nouveau prompt avec git fait -> protection des pointeurs/malloc a faire ici ! - void ft_prompt(void) { int ret; diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index a2b96cad..4a7ed5d7 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/18 10:57:19 by gwojda ### ########.fr */ +/* Updated: 2017/03/18 14:55:08 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,6 @@ int readline(int has_prompt, char **input) return ((ret = get_next_line(data_singleton()->fd, input)) >= 0 ? !ret : ret); readline_init(has_prompt); ret = ft_read_stdin(input); - DG("input = %s", *input); if (ret < 0) return (ret); if (data_singleton()->line.input)