diff --git a/42sh/Makefile b/42sh/Makefile index 54f998ee..f2327123 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/05 15:36:45 by wescande ### ########.fr *# +# Updated: 2017/03/10 17:40:02 by gwojda ### ########.fr # # # # **************************************************************************** # @@ -44,9 +44,12 @@ builtin/builtin_setenv.c\ builtin/builtin_unset.c\ builtin/builtin_unsetenv.c\ builtin/is_builtin.c\ +completion/c_abs_path.c\ +completion/c_arrow.c\ completion/c_binary.c\ completion/c_clear.c\ completion/c_files.c\ +completion/c_glob_matching.c\ completion/c_init.c\ completion/c_matching.c\ completion/c_misc.c\ @@ -55,6 +58,7 @@ completion/c_parser.c\ completion/c_pathsolver.c\ completion/c_printer.c\ completion/c_rematch.c\ +completion/c_seek_env.c\ completion/c_sizing.c\ completion/c_terminal.c\ completion/completion.c\ @@ -245,6 +249,7 @@ line-editing/home_end.c\ line-editing/init_history.c\ line-editing/init_line.c\ line-editing/init_termcaps.c\ +line-editing/lib_line_editing/ft_nb_line.c\ line-editing/lib_line_editing/tool_line.c\ line-editing/lib_line_editing/tool_line_2.c\ line-editing/lib_line_editing/toolz.c\ @@ -297,7 +302,7 @@ NB = $(words $(SRC_BASE)) INDEX = 0 all : - @make -j $(NAME) + @make $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) @$(CC) $(OBJS) -o $(NAME) \ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 76b10e06..54ae20b1 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/17 11:10:48 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 17:38:50 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ # define COMPLETION_H # include "minishell.h" +#define RETARDED_BEHAVIOR 0 /* ** Autocompletion list for the valid candidates from the parser. @@ -55,6 +56,10 @@ typedef struct s_clst ** c_pline : Number of item per line when printing. ** c_line : Number of line required to move to terminal up. ** win_x : Size of the window in length. +** win_y : Size of the window in height. +** m_size : Max size of the list in pagination. +** pos_x : Position of the element relative to the terminal in list mode (X). +** pos_y : Position of the element relative to the terminal in list mode (Y). ** key : The keypressed lastly. ** isfolder : If the match is a folder. boolean. ** lst : List of the item corresponding to the completion. @@ -63,9 +68,9 @@ typedef struct s_clst ** ** Exemple: [ ls / ; cd (tab) ; pwd ] ** -** (int)cutpoint -** | -** | +** (int)cutpoint +** | +** | ** Become: [ls / ;] [ ] [cd ] [ ; pwd] ** | | | | ** | | | | @@ -90,8 +95,13 @@ typedef struct s_comp int c_pline; int c_line; int win_x; + int win_y; + int m_size; + int pos_x; + int pos_y; int key; int isfolder; + int isrematch; t_clst *lst; } t_comp; @@ -132,12 +142,14 @@ int c_rematch(t_comp *c, long int keypress); ** c_term_mv_down : Make space for the list. ** c_term_mv_back : Reset the cursor position. ** c_term_clear : Delete the list from the terminal. +** c_term_resize : Refresh win_x and win_y. ** c_printer : Printer of the list. */ void c_term_mv_down(t_comp *c); void c_term_mv_back(t_comp *c); void c_term_clear(t_comp *c); +int c_term_resize(t_comp *c); void c_printer(t_comp *c); /* @@ -151,12 +163,20 @@ void c_printer(t_comp *c); int c_clear(t_data *s); int c_clear_lst(t_comp *c); char *path_solver(t_comp *c, char *cmd, char *cwd); +int c_spacing_escape(t_clst *node, int x, int o); +int c_spacing_clear(t_comp *c); +int ft_sstrlen(char **s); +char *ft_sstrtostr(char **s, char *sep); /* -** ajout rapide gwojda pour compiler : +** j'ajoute a la va vite^^ */ -int ft_sstrlen(char **s); -char *ft_sstrtostr(char **s, char *sep); +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); +int c_chevron(t_comp *c); #endif diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 22f2d51f..807bda54 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/10 17:39:42 by ariard ### ########.fr */ +/* Updated: 2017/03/10 18:09:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 17a0434a..cbd312d1 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/09 11:55:17 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 17:40:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -129,6 +129,8 @@ int ft_put(int nb); void ft_check_line(void); void ft_clear_window(void); void free_history_list(t_list_history *head); +int ft_nb_of_line(char *str, size_t pos); +int ft_get_size_prev(char *str, size_t pos); char *ft_read_stdin(void); void ft_end(void); diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 5013d09c..d67c687b 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:38:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:57:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_abs_path.c b/42sh/src/completion/c_abs_path.c new file mode 100644 index 00000000..cd2537c8 --- /dev/null +++ b/42sh/src/completion/c_abs_path.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_abs_path.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */ +/* Updated: 2017/03/09 17:34:43 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "completion.h" + +static int c_exclusion_folder(t_comp *c) +{ + DIR *rep; + char *tmp; + char *tmp2; + + tmp = ft_strjoin(c->cpath, c->match); + tmp2 = NULL; + if (tmp[ft_strlen(tmp) - 1] == '/') + return (0); + if ((rep = opendir(tmp)) && (!closedir(rep))) + { + tmp ? ft_memdel((void *)&tmp) : (0); + tmp2 = ft_strjoin(c->match, "/"); + c_updater(c, tmp2); + tmp2 ? ft_memdel((void *)&tmp2) : (0); + return (1); + } + tmp ? ft_memdel((void *)&tmp) : (0); + tmp ? ft_memdel((void *)&tmp) : (0); + return (0); +} + +void c_seek_abs_path(t_comp *c, char *current_word) +{ + char *tmp; + + c->cpath = ft_strndup(current_word, ft_strrchr(c->rcmd, '/') - current_word + 1); + if (current_word[0] == '~') + { + tmp = c->cpath; + c->cpath = ft_str3join(getenv("PWD"), "/", c->cpath + 2); + free(tmp); + } + !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; + c_parser(c, c->cpath, c->match); + c_exclusion_folder(c); +} diff --git a/42sh/src/completion/c_arrow.c b/42sh/src/completion/c_arrow.c new file mode 100644 index 00000000..4890cec9 --- /dev/null +++ b/42sh/src/completion/c_arrow.c @@ -0,0 +1,105 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_arrow.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: alao +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/10 09:04:42 by alao #+# #+# */ +/* Updated: 2017/03/10 12:44:05 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++; + } + if (c->pos_x == (c->c_pline - 1)) + { + i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); + while (i < c->c_line) + { + ptr = ptr->next; + 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++; + } +/* if (c->pos_x == 1) + { + i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line)); + while (i < c->c_line) + { + ptr = ptr->prev; + 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_binary.c b/42sh/src/completion/c_binary.c index bf359ca4..0a3dbb33 100644 --- a/42sh/src/completion/c_binary.c +++ b/42sh/src/completion/c_binary.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:30:57 by alao #+# #+# */ -/* Updated: 2017/02/16 21:03:18 by alao ### ########.fr */ +/* Updated: 2017/02/27 13:17:27 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,8 @@ int c_seek_binary(t_data *s, t_comp *c) if (!(tmp = ft_strdup(ft_getenv(s->env, "PATH")))) return (-1); paths = ft_strsplit(tmp, ':'); - c->match = ft_strdup(c->rcmd); + if (c->match == NULL) + c->match = ft_strdup(c->rcmd); while (paths[i]) c_parser(c, paths[i++], c->rcmd); tmp ? ft_memdel((void *)&tmp) : (0); diff --git a/42sh/src/completion/c_clear.c b/42sh/src/completion/c_clear.c index 80f6f3fb..7ab7f837 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/02/16 22:03:41 by alao ### ########.fr */ +/* Updated: 2017/02/17 14:57:09 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,8 @@ int c_clear_lst(t_comp *c) t_clst *c_lst; t_clst *p_lst; + if (c->lst == NULL) + return (0); c_lst = c->lst; c->lst->prev ? (c->lst = c->lst->prev) : (0); c_lst->prev->next = NULL; @@ -48,6 +50,8 @@ int c_clear(t_data *s) { t_comp *ptr; + if (s->comp == NULL) + return (0); ptr = s->comp; ptr->rcmd ? ft_memdel((void *)&ptr->rcmd) : (0); ptr->match ? ft_memdel((void *)&ptr->match) : (0); diff --git a/42sh/src/completion/c_files.c b/42sh/src/completion/c_files.c index 5931ca22..30006e18 100644 --- a/42sh/src/completion/c_files.c +++ b/42sh/src/completion/c_files.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:31:21 by alao #+# #+# */ -/* Updated: 2017/02/16 22:14:51 by alao ### ########.fr */ +/* Updated: 2017/03/10 17:38:37 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,15 +27,22 @@ static int c_exclusion_folder(t_comp *c) char *tmp2; tmp = ft_strjoin(c->cpath, c->match); + tmp2 = NULL; if ((rep = opendir(tmp)) && (!closedir(rep))) { + tmp ? ft_memdel((void *)&tmp) : (0); + if (c->rcmd[ft_strlen(c->rcmd) - 1] == '/') + { + c_clear(data_singleton()); + return (0); + } tmp2 = ft_strjoin(c->match, "/"); c_updater(c, tmp2); - tmp ? ft_memdel((void *)&tmp) : (0); tmp2 ? ft_memdel((void *)&tmp2) : (0); return (1); } tmp ? ft_memdel((void *)&tmp) : (0); + tmp ? ft_memdel((void *)&tmp) : (0); return (0); } /* @@ -63,7 +70,9 @@ static char *c_slicer(t_comp *c) i--; tmp[i] == '/' ? i++ : (0); rt = (i == (int)ft_strlen(tmp) - 1) ? NULL : ft_strsub(tmp, 0, i); - if (i <= (int)ft_strlen(tmp) - i + 1) + if (c_chevron(c)) + c->match = ft_strdup(""); + else c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i); tmp ? ft_memdel((void *)&tmp) : (0); return (rt); @@ -78,6 +87,11 @@ int c_seek_files(t_data *s, t_comp *c) char *path; (void)s; + if (c->rcmd[0] == '.') + { + c->cpath = ft_strdup("./"); + c->match = ft_strdup("."); + } if (c->cpath == NULL) { path = c_slicer(c); @@ -85,7 +99,12 @@ int c_seek_files(t_data *s, t_comp *c) path ? ft_memdel((void *)&path) : (0); } c_parser(c, c->cpath, c->match); - if (c->lst == NULL) + if (c->lst == NULL && c->isrematch == 0) c_exclusion_folder(c); + else if ((c->lst && (c->lst == c->lst->next)) && c->isrematch == 0) + { + if (c->match && ft_strequ(c->match, c->lst->name)) + c_exclusion_folder(c); + } return (0); } diff --git a/42sh/src/completion/c_glob_matching.c b/42sh/src/completion/c_glob_matching.c new file mode 100644 index 00000000..66f39d9d --- /dev/null +++ b/42sh/src/completion/c_glob_matching.c @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_glob_matching.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */ +/* Updated: 2017/03/10 17:43:15 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static void c_replace_globbing(char **glob, size_t start) +{ + char *ref_next; + char *ref_mid; + char *ref_prev; + char *str; + size_t pos; + + str = data_singleton()->line.input; + pos = data_singleton()->line.pos; + while (str[pos] && str[pos] != ' ') + ++pos; + while (str[pos] && str[pos] == ' ') + ++pos; + ref_prev = ft_strndup(str, start); + ref_mid = ft_sstrtostr(glob, " "); + ref_next = ft_strdup(str + pos); + data_singleton()->line.input = ft_str3join(ref_prev, ref_mid, ref_next); + free(ref_prev); + free(ref_mid); + free(ref_next); + free(str); +} + +int c_glob_matching(void) +{ + char *current_word; + char **ss_glob; + unsigned char *glob_echap; + char *str; + size_t pos; + + str = data_singleton()->line.input; + pos = data_singleton()->line.pos; + if (!str) + return (0); + if (pos && str[pos] == ' ') + --pos; + while (pos && str[pos] != ' ') + --pos; + if (str[pos] == ' ') + ++pos; + current_word = ft_strdupi_w(str + pos); + if (current_word[0] == '$') + { + free(current_word); + return (0); + } + glob_echap = (unsigned char *)ft_strnew(ft_strlen(str) >> 3); + ft_bzero(glob_echap, ft_strlen(str) >> 3); + ss_glob = glob(current_word, glob_echap, glob_echap, 1); +// ss_glob = glob(current_word, glob_echap, glob_echap); + free(current_word); + if (!*ss_glob || !**ss_glob || !ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob))) + return (0); + c_replace_globbing(ss_glob, pos); + return (1); +} diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index 5b5c6934..e625e035 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/02/16 22:08:25 by alao ### ########.fr */ +/* Updated: 2017/03/10 12:43:57 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,9 +55,17 @@ static void c_init_base(t_comp *c) ioctl(0, TIOCGWINSZ, &win); c->win_x = win.ws_col; + c->win_y = win.ws_row; + c->m_size = data_singleton()->line.prompt_size; + c->m_size += ft_strlen(data_singleton()->line.input); + c->m_size = (c->m_size / c->win_y); + c->m_size = c->win_y - c->m_size - 1; + c->pos_x = 1; + c->pos_y = 1; c->cutpoint = 0; c->between = NULL; c->isfolder = 0; + c->isrematch = 0; c->match = NULL; c->cpath = NULL; c->lst = NULL; @@ -70,9 +78,8 @@ static void c_init_base(t_comp *c) ** structure data and call for the c_matching() function. */ -void c_init(t_data *s, long int input) +void c_init(t_data *s, long int input) { - int len_trail; if (!(s->comp = (t_comp *)malloc((sizeof(t_comp))))) diff --git a/42sh/src/completion/c_matching.c b/42sh/src/completion/c_matching.c index 25936087..68dc4d8f 100644 --- a/42sh/src/completion/c_matching.c +++ b/42sh/src/completion/c_matching.c @@ -6,12 +6,32 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/02/16 21:57:47 by alao ### ########.fr */ +/* Updated: 2017/03/10 17:20:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +/* +** chevron y es-tu ??? +*/ + +int c_chevron(t_comp *c) +{ + size_t pos; + + pos = c->ircmd; + while (pos) + { + if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>') + return (1); + --pos; + } + if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>') + return (1); + return (0); +} + /* ** Start the parsing for the autocompletion. ** Check the first char of the c->rcmd for a . or /. to see if it's a local @@ -25,19 +45,32 @@ ** Else 0 is returned. */ +static char *c_current_words(t_comp *c) +{ + int pos; + + pos = c->ircmd; + while (pos && c->rcmd[pos] != ' ') + --pos; + if (c->rcmd[pos] == ' ') + ++pos; + return (c->rcmd + pos); +} + int c_matching(t_data *s, t_comp *c) { - if (c->rcmd[0] == '.' || c->rcmd[0] == '/') - { - c->rcmd[0] == '.' ? c->cpath = path_solver(c, "./", NULL) : 0; - c->rcmd[0] == '/' ? c->cpath = path_solver(c, "/", NULL) : 0; - c_parser(c, c->cpath, c->match); - } - else if (!(ft_strchr(c->rcmd, ' '))) + char *current_word; + + current_word = c_current_words(c); + if (ft_strchr(c->rcmd, '/')) + c_seek_abs_path(c, current_word); + else if (ft_strchr(c->rcmd, '$')) + c_seek_env(c, current_word); + else if (c->rcmd[0] != '.' && !(ft_strchr(c->rcmd, ' ')) && !c_chevron(c)) c_seek_binary(s, c); else c_seek_files(s, c); - if (s->comp && c->lst) + if (s->comp && s->comp->lst) { c_sizing(c); return (1); diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index 6704ad3a..af1ed37d 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/16 22:00:38 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_parser.c b/42sh/src/completion/c_parser.c index 3788ff73..d29fc547 100644 --- a/42sh/src/completion/c_parser.c +++ b/42sh/src/completion/c_parser.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */ -/* Updated: 2017/02/16 22:00:49 by alao ### ########.fr */ +/* Updated: 2017/03/09 16:47:31 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ ** Add the matching element to the list */ -static void c_add_to_lst(t_comp *c, t_clst *node) +void c_add_to_lst(t_comp *c, t_clst *node) { if (c->lst == NULL) { @@ -49,8 +49,6 @@ static int c_storing(t_comp *c, char *value, unsigned char type) return (0); if (c->match && ft_strnequ(c->match, value, ft_strlen(c->match)) != 1) return (0); - if (c->match && ft_strequ(c->match, value)) - return (0); if (!(tmp = (t_clst *)malloc(sizeof(t_clst)))) return (-1); tmp->name = ft_strdup(value); diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index c46fd10d..57908b3a 100644 --- a/42sh/src/completion/c_printer.c +++ b/42sh/src/completion/c_printer.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 12:55:39 by alao #+# #+# */ -/* Updated: 2017/02/16 22:11:48 by alao ### ########.fr */ +/* Updated: 2017/03/10 16:09:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,6 +72,48 @@ static int c_printer_line(t_comp *c, t_clst *lst, int loop, int i) return (0); } +/* +** Controlling the offset value for the rolling list if the space in the +** terminal is too small to display the whole list. +** +** Controlled value are: +** - x : the column of the element currently selected. +*/ + +static t_clst *c_rolling(t_comp *c) +{ + t_clst *ptr; + int x; + int y; + int id; + + ptr = c->lst; + while (!ptr->cursor) + ptr = ptr->next; + + x = 1; + while ((x * c->c_line) < ptr->id) + x++; + id = ((x == 1) ? ptr->id : (ptr->id - ((x - 1) * c->c_line))); + y = 1; + while ((y * (c->m_size - 1)) < id) + y++; + c->pos_x = id; + c->pos_y = y; + if (y > 1) + { + x = (y - 1) * (c->m_size - 1); + ptr = c->lst; + while (x) + { + ptr = ptr->next; + x--; + } + return (ptr); + } + return (c->lst); +} + /* ** Control the number of time it cycle for LINE */ @@ -80,14 +122,24 @@ void c_printer(t_comp *c) { t_clst *ptr; int loop; + int max_line; + int offset; - ptr = c->lst; loop = c->c_line; - while (loop) + + max_line = c->c_line - (c->m_size - 1); + ptr = c_rolling(c); + if ((c->pos_y * (c->m_size - 1)) > c->c_line) + max_line = (c->c_line % (c->m_size - 1)); + else + max_line = c->m_size - 1; + offset = (c->m_size - 1) - max_line; + while (loop && max_line) { c_printer_line(c, ptr, c->c_pline, 1); loop > 1 ? ft_putstr(tgetstr("do", NULL)) : (0); ptr = ptr->next; loop--; + max_line--; } } diff --git a/42sh/src/completion/c_rematch.c b/42sh/src/completion/c_rematch.c index 6771e656..edea661e 100644 --- a/42sh/src/completion/c_rematch.c +++ b/42sh/src/completion/c_rematch.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 12:03:30 by alao #+# #+# */ -/* Updated: 2017/02/16 22:03:42 by alao ### ########.fr */ +/* Updated: 2017/03/10 17:27:06 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,22 +50,17 @@ int c_rematch(t_comp *c, long int keypress) { if (ft_isascii(keypress)) { + c->isrematch = 1; c_term_clear(c); c_refresh_match(c, keypress); c_clear_lst(c); c_matching(data_singleton(), c); if (c->lst == NULL) - { c_clear(data_singleton()); - return (1); - } else if (c->lst == c->lst->next) return (1); - else - { - ft_print(keypress); - return(1); - } + ft_print(keypress); + return(1); } else { diff --git a/42sh/src/completion/c_seek_env.c b/42sh/src/completion/c_seek_env.c new file mode 100644 index 00000000..d69eb6c4 --- /dev/null +++ b/42sh/src/completion/c_seek_env.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* c_seek_env.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ +/* Updated: 2017/03/10 17:33:37 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int c_storing(t_comp *c, char *value) +{ + t_clst *tmp; + + if (!(tmp = (t_clst *)malloc(sizeof(t_clst)))) + return (-1); + tmp->name = value; + tmp->len = ft_strlen(tmp->name); + tmp->type = 10; + tmp->cursor = 0; + c_add_to_lst(c, tmp); + return (0); +} + +static void c_maj_rcmd(t_comp *c, char *current_word) +{ + char *tmp; + + tmp = c->rcmd; + c->rcmd = ft_strdupi_w(current_word); + free(tmp); +} + +int c_seek_env(t_comp *c, char *current_word) +{ + char *match; + char **env; + int i; + + i = 0; + env = data_singleton()->env; + match = ft_strdupi_w(current_word + 1); + c_maj_rcmd(c, current_word); + while (env[i]) + { + if (!ft_strncmp(match, env[i], ft_strlen(match))) + c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i])); + ++i; + } + return (0); +} diff --git a/42sh/src/completion/c_sizing.c b/42sh/src/completion/c_sizing.c index 559b3329..542f5a13 100644 --- a/42sh/src/completion/c_sizing.c +++ b/42sh/src/completion/c_sizing.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 08:50:26 by alao #+# #+# */ -/* Updated: 2017/02/16 22:01:47 by alao ### ########.fr */ +/* Updated: 2017/03/10 08:45:52 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,7 @@ int c_sizing(t_comp *c) c->c_line = 0; while ((c->c_line * c->c_pline) < c->c_sy) c->c_line++; - if (c->win_x < c->c_sx) + if ((c->win_x < c->c_sx)) { c->c_pline = 0; c->c_line = 0; diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index 58d01bd7..185c35bc 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/02/16 22:01:37 by alao ### ########.fr */ +/* Updated: 2017/03/10 16:07:36 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,9 +43,14 @@ void c_term_mv_back(t_comp *c) { int i; int lcmd; + int value; i = 0; - while (i != (c->c_line)) + if (c->c_sy > c->win_y) + value = c->m_size; + else + value = c->c_line; + while (i != value) { ft_putstr(tgetstr("up", NULL)); i++; @@ -69,18 +74,46 @@ void c_term_mv_back(t_comp *c) void c_term_mv_down(t_comp *c) { int i; + int value; i = 0; - while (i < c->c_line) + if (c->c_sy > c->win_y) + value = c->m_size; + else + value = c->c_line; + while (i < value) { ft_putstr(tgetstr("do", NULL)); ft_putstr(tgetstr("cd", NULL)); i++; } i = 0; - while (i != (c->c_line - 1)) + if (c->c_sy > c->win_y) + value = c->m_size - 1; + else + value = c->c_line - 1; + while (i != value) { ft_putstr(tgetstr("up", NULL)); i++; } } + +/* +** If the terminal has changed in size, the function will refresh these values +** and clear the previous print list. +*/ + +int c_term_resize(t_comp *c) +{ + struct winsize win; + + ioctl(0, TIOCGWINSZ, &win); + if ((win.ws_col == c->win_x) && (win.ws_row == c->win_y)) + return (0); + c->win_x = win.ws_col; + c->win_y = win.ws_row; + c_sizing(c); + c_term_clear(c); + return (0); +} diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index ba4717c7..e9c82539 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/16 22:01:18 by alao ### ########.fr */ +/* Updated: 2017/03/10 17:20:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,18 +38,16 @@ static void c_next_item(t_comp *c) static int c_dispatcher(t_data *s) { - if (s->comp && s->comp->lst == NULL && s->comp->isfolder) - { - c_clear(s); - return (1); - } if (s->comp && s->comp->lst == NULL) { c_clear(s); return (1); } else if (s->comp && s->comp->lst == s->comp->lst->next) - return (c_updater(s->comp, s->comp->lst->name)); + { + c_updater(s->comp, s->comp->lst->name); + return (1); + } else if (s->comp && s->comp->lst != s->comp->lst->next) { c_term_mv_down(s->comp); @@ -83,6 +81,8 @@ int completion(long int keypress) t_data *s; s = data_singleton(); + if (c_glob_matching()) + return (1); if (s->comp == NULL) { if (s->line.pos == 0) @@ -96,6 +96,7 @@ int completion(long int keypress) } else { + c_term_resize(s->comp); if (keypress == TOUCHE_TAB) c_next_item(s->comp); else diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 424cf51f..f750c5e7 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/10 15:36:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:58:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,8 +29,6 @@ int exec_leaf(t_btree **ast) { if (JOB_IS_FG(job->attrs)) put_job_in_foreground(job, 0); - /* else */ - /* put_job_in_background(job, 0); */ job->pgid = 0; } } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 354b3cde..df434fd0 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/10 13:48:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:49:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,15 +20,13 @@ int exec_reset(void) /* exec->fd_save[0] = 1;//fcntl(STDIN, F_DUPFD_CLOEXEC); */ /* exec->fd_save[1] = 1;//fcntl(STDOUT, F_DUPFD_CLOEXEC); */ /* exec->fd_save[2] = 1;//fcntl(STDERR, F_DUPFD_CLOEXEC); */ - DG("check 0"); if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i %s{eoc}\n", SHELL_NAME, errno); - DG("check 1"); if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i %s{eoc}\n", SHELL_NAME, errno); if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i %s{eoc}\n", SHELL_NAME, errno); - DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]); + /* DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]); */ exec->op_stack = NULL; exec->fdin = STDIN; exec->attrs = 0; diff --git a/42sh/src/exec/launch_if.c b/42sh/src/exec/launch_if.c index 7d389d56..71c1534e 100644 --- a/42sh/src/exec/launch_if.c +++ b/42sh/src/exec/launch_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ -/* Updated: 2017/03/08 15:07:47 by wescande ### ########.fr */ +/* Updated: 2017/03/10 17:08:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index ce257525..0fff5117 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:21:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:50:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_while.c b/42sh/src/exec/launch_while.c index 3b396d76..d545b894 100644 --- a/42sh/src/exec/launch_while.c +++ b/42sh/src/exec/launch_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/10 14:28:06 by ariard ### ########.fr */ +/* Updated: 2017/03/10 17:09:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 58c1ab9d..509b8ef4 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/10 14:32:05 by ariard ### ########.fr */ +/* Updated: 2017/03/10 17:09:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 37cf1b81..cc63b209 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/09 14:28:39 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:51:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,7 @@ int process_setgroup(t_process *p, pid_t pid) if (!SH_HAS_JOBC(data->opts)) return (0); j = &data->exec.job; - if (!j->pgid) - j->pgid = pid ? pid : getpid(); + /* DG("setpgid(%i, %i)", pid, j->pgid); */ setpgid(pid, j->pgid); if (pid == 0 && JOB_IS_FG(j->attrs)) tcsetpgrp(STDIN, j->pgid); diff --git a/42sh/src/job-control/builtin_fg.c b/42sh/src/job-control/builtin_fg.c index 9e7720f6..df1cf8c1 100644 --- a/42sh/src/job-control/builtin_fg.c +++ b/42sh/src/job-control/builtin_fg.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ -/* Updated: 2017/02/21 20:09:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:27:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index fb153c30..e8dd64ea 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:36:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:45:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,15 +27,12 @@ int job_addprocess(t_process *p) job->pgid = p->pid; ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } - DG("check 0"); job = jobc->first_job->content; ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p))); - DG("[BG:%i]", JOB_IS_BG(job->attrs)); + /* DG("[BG:%i]", JOB_IS_BG(job->attrs)); */ if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p)) { - DG("check 2"); job_notify_new(job); } - DG("check 3"); return (0); } diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index a3088f15..33c3eb72 100644 --- a/42sh/src/job-control/job_update_status.c +++ b/42sh/src/job-control/job_update_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:38:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:45:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index d655567f..8aa3be7f 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:40:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:48:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,14 @@ int job_wait(int id) t_jobc *jobc; int status; - DG("job wait [%i]", id); jobc = &data_singleton()->jobc; j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; + DG("job wait id=[%i], pgid=[%i]", id, j->pgid); do + { pid = waitpid(-j->pgid, &status, WUNTRACED); + DG("pid=[%d]", pid); + } while (pid > 1 && !mark_process_status(pid, status) && !job_is_stopped(id) && !job_is_completed(id)); diff --git a/42sh/src/job-control/process_format.c b/42sh/src/job-control/process_format.c index c8a36422..9fcd987f 100644 --- a/42sh/src/job-control/process_format.c +++ b/42sh/src/job-control/process_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:08:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:27:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 97b9ba4a..b07f40be 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:16:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 16:27:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/completion.c b/42sh/src/line-editing/completion.c index 0e09cc3f..10caf891 100644 --- a/42sh/src/line-editing/completion.c +++ b/42sh/src/line-editing/completion.c @@ -6,36 +6,55 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */ -/* Updated: 2017/02/16 14:22:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/09 15:20:18 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_completion(int ret) +static size_t ft_strleni_w(char *str, size_t pos, char c) +{ + size_t len; + + len = 0; + if (!STR) + return (0); + while (str[pos] && str[pos] != c) + { + ++len; + ++pos; + } + return (len); +} + +int ft_completion(int ret) { size_t tmp; size_t pos_tmp; - int beg_len; + size_t right; char boolean; boolean = 0; - beg_len = ft_strlen(data_singleton()->line.input); + pos_tmp = POS; + right = ft_strleni_w(STR, POS, '\n'); if (((ret != TOUCHE_TAB && ret != 10) || (ret == 10)) && !(data_singleton()->comp)) return (0); - tmp = POS; - pos_tmp = POS; if (data_singleton()->comp || ret == TOUCHE_TAB) boolean = completion(ret); if (boolean || ret == 10) { + if (pos_tmp) + --pos_tmp; + else + ft_puttermcaps("nd"); + ft_get_beggin_with_curs(STR, &pos_tmp); + tmp = pos_tmp; ft_puttermcaps("cd"); ft_current_str(STR, tmp); ft_get_next_str(STR, &tmp); - ft_putnc('\b', tmp - - (pos_tmp + ft_strlen(data_singleton()->line.input) - beg_len)); - POS = pos_tmp + ft_strlen(data_singleton()->line.input) - beg_len; + ft_putnc('\b', right); + POS = ft_strleni_w(STR, pos_tmp, '\n') - right; } return (1); } diff --git a/42sh/src/line-editing/lib_line_editing/ft_nb_line.c b/42sh/src/line-editing/lib_line_editing/ft_nb_line.c new file mode 100644 index 00000000..c8fef299 --- /dev/null +++ b/42sh/src/line-editing/lib_line_editing/ft_nb_line.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_nb_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 17:11:57 by gwojda #+# #+# */ +/* Updated: 2017/03/08 17:43:14 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int ft_nb_of_line(char *str, size_t pos) +{ + int len; + + len = 1; + if (pos && str[pos] == '\n') + --pos; + len += data_singleton()->line.prompt_size; + len += ft_get_size_prev(str, pos); + return (len / ft_size_term()); +} diff --git a/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c b/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c index 75d0ec34..f93f2917 100644 --- a/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c +++ b/42sh/src/line-editing/lib_line_editing/toolz_termcaps.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */ -/* Updated: 2017/03/08 23:38:50 by ariard ### ########.fr */ +/* Updated: 2017/03/10 17:43:59 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,7 +49,7 @@ int ft_nb_last_line(char *str, size_t pos) --pos; len += data_singleton()->line.prompt_size; len += ft_get_size_prev(str, pos); - return ((len) ? len % ft_size_term() : -1); + return (len % ft_size_term()); } void ft_check_end_of_line(char *str, size_t pos)