Reworked colors and fix a few bugs. Still missing advanced research

This commit is contained in:
M600 2017-02-15 21:01:23 +01:00
parent ec9f2c91f3
commit fbecb59a14
9 changed files with 145 additions and 49 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/02/07 20:11:22 by jhalford ### ########.fr # # Updated: 2017/02/15 20:00:50 by alao ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -52,6 +52,7 @@ completion/c_output.c\
completion/c_parser.c\ completion/c_parser.c\
completion/c_pathsolver.c\ completion/c_pathsolver.c\
completion/c_printer.c\ completion/c_printer.c\
completion/c_rematch.c\
completion/c_sizing.c\ completion/c_sizing.c\
completion/c_terminal.c\ completion/c_terminal.c\
completion/completion.c\ completion/completion.c\
@ -229,7 +230,7 @@ NB = $(words $(SRC_BASE))
INDEX = 0 INDEX = 0
all : all :
@make -j $(NAME) @make $(NAME)
$(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
@$(CC) $(FLAGS) $(D_FLAGS) \ @$(CC) $(FLAGS) $(D_FLAGS) \
@ -241,7 +242,7 @@ $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
@printf "\r\e[48;5;15;38;5;25m✅ MAKE $(NAME)\e[0m\e[K\n" @printf "\r\e[48;5;15;38;5;25m✅ MAKE $(NAME)\e[0m\e[K\n"
$(LIBFT_LIB): $(LIBFT_LIB):
@make -j -C $(LIBFT_DIR) @make -C $(LIBFT_DIR)
$(OBJ_DIR) : $(OBJ_DIR) :
@mkdir -p $(OBJ_DIR) @mkdir -p $(OBJ_DIR)

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */
/* Updated: 2017/02/03 15:47:35 by alao ### ########.fr */ /* Updated: 2017/02/15 20:00:32 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,6 +52,8 @@ typedef struct s_clst
** c_pline : Number of item per line when printing. ** c_pline : Number of item per line when printing.
** c_line : Number of line required to move to terminal up. ** c_line : Number of line required to move to terminal up.
** win_x : Size of the window in length. ** win_x : Size of the window in length.
** key : The keypressed lastly.
** isfolder : If the match is a folder. boolean.
** lst : List of the item corresponding to the completion. ** lst : List of the item corresponding to the completion.
*/ */
@ -71,6 +73,7 @@ typedef struct s_comp
int c_line; int c_line;
int win_x; int win_x;
int key; int key;
int isfolder;
t_clst *lst; t_clst *lst;
} t_comp; } t_comp;
@ -92,6 +95,7 @@ int c_sizing(t_comp *c);
int c_updater(t_comp *c, char *select); int c_updater(t_comp *c, char *select);
int c_gtfo(t_comp *c, long int keypress); int c_gtfo(t_comp *c, long int keypress);
int c_rematch(t_comp *c, long int keypress);
/* /*
** Terminal related function (moving and printing the list) ** Terminal related function (moving and printing the list)

View file

@ -6,12 +6,38 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:31:21 by alao #+# #+# */ /* Created: 2017/01/09 13:31:21 by alao #+# #+# */
/* Updated: 2017/02/03 17:32:20 by jhalford ### ########.fr */ /* Updated: 2017/02/15 19:33:11 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "completion.h" #include "completion.h"
/*
** If the parsing for local file fail. The function is called to check if the
** match is actually a folder. If so, the command is updated with a trailing
** slash (/).
*/
static int c_exclusion_folder(t_comp *c)
{
DIR *rep;
char *tmp;
tmp = ft_strjoin(c->cpath, c->match);
if ((rep = opendir(tmp)) && (!closedir(rep)))
{
tmp ? ft_memdel((void *)&tmp) : (0);
tmp = ft_strjoin(c->rcmd, "/");
if (c->trail)
data_singleton()->line.input = ft_strjoin(tmp, c->trail);
else
data_singleton()->line.input = ft_strdup(tmp);
data_singleton()->line.pos = data_singleton()->line.pos + 1;
c->isfolder = 1;
}
tmp ? ft_memdel((void *)&tmp) : (0);
return (0);
}
/* /*
** Clear the binary from c->rcmd ans save the result in c->match. Return the ** Clear the binary from c->rcmd ans save the result in c->match. Return the
** path part of it if exist or NULL. ** path part of it if exist or NULL.
@ -56,5 +82,7 @@ int c_seek_files(t_data *s, t_comp *c)
c->cpath = path_solver(c, path, NULL); c->cpath = path_solver(c, path, NULL);
path ? ft_memdel((void *)&path) : (0); path ? ft_memdel((void *)&path) : (0);
c_parser(c, c->cpath, c->match); c_parser(c, c->cpath, c->match);
if (c->lst == NULL)
c_exclusion_folder(c);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 11:21:16 by alao #+# #+# */ /* Created: 2017/01/09 11:21:16 by alao #+# #+# */
/* Updated: 2017/02/03 17:32:24 by jhalford ### ########.fr */ /* Updated: 2017/02/15 19:05:04 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -61,6 +61,7 @@ void c_init(t_data *s, long int input)
s->comp->home = ft_strdup(ft_getenv(s->env, "HOME")); s->comp->home = ft_strdup(ft_getenv(s->env, "HOME"));
s->comp->pwd = ft_strdup(ft_getenv(s->env, "PWD")); s->comp->pwd = ft_strdup(ft_getenv(s->env, "PWD"));
s->comp->key = input; s->comp->key = input;
s->comp->isfolder = 0;
s->comp->prompt = s->line.prompt_size; s->comp->prompt = s->line.prompt_size;
c_matching(s, s->comp); c_matching(s, s->comp);
} }

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */
/* Updated: 2017/02/03 13:31:36 by alao ### ########.fr */ /* Updated: 2017/02/15 19:06:32 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,7 +21,13 @@
int c_matching(t_data *s, t_comp *c) int c_matching(t_data *s, t_comp *c)
{ {
if (!(ft_strchr(c->rcmd, ' '))) 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, ' ')))
c_seek_binary(s, c); c_seek_binary(s, c);
else else
c_seek_files(s, c); c_seek_files(s, c);

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 13:10:38 by alao #+# #+# */ /* Created: 2017/02/03 13:10:38 by alao #+# #+# */
/* Updated: 2017/02/03 17:32:36 by jhalford ### ########.fr */ /* Updated: 2017/02/15 21:00:22 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,6 +53,7 @@ int c_gtfo(t_comp *c, long int keypress)
if (keypress != 10) if (keypress != 10)
{ {
// c_rematch(c, keypress);
c_clear(data_singleton()); c_clear(data_singleton());
return (1); return (1);
} }

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/10 12:55:39 by alao #+# #+# */ /* Created: 2017/01/10 12:55:39 by alao #+# #+# */
/* Updated: 2017/02/03 17:35:15 by jhalford ### ########.fr */ /* Updated: 2017/02/15 19:28:43 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,21 +19,29 @@
** - (10) Symlink: Cyan "\e[96m" ** - (10) Symlink: Cyan "\e[96m"
*/ */
static void c_printer_node(t_clst *lst) static void c_printer_node(t_clst *lst, int c_sx)
{
int i;
i = lst->len;
if (lst->cursor)
ft_putstr_fd("\e[7m", 2);
else
{ {
lst->cursor ? ft_putstr(tgetstr("us", NULL)) : (0);
lst->cursor ? (ft_putstr_fd("\033[31m", 2)) : (0);
lst->type == 4 ? ft_putstr_fd("\e[1;31m", 2) : (0); lst->type == 4 ? ft_putstr_fd("\e[1;31m", 2) : (0);
lst->type == 10 ? ft_putstr_fd("\e[1;96m", 2) : (0); lst->type == 10 ? ft_putstr_fd("\e[1;96m", 2) : (0);
}
ft_putstr_fd(lst->name, 2); ft_putstr_fd(lst->name, 2);
ft_putstr_fd("\033[00m", 2);
if (lst->type == 4) if (lst->type == 4)
ft_putstr_fd("/", 2); ft_putstr_fd("/", 2);
else if (lst->type == 10) else if (lst->type == 10)
ft_putstr_fd("@", 2); ft_putstr_fd("@", 2);
else else
ft_putstr_fd(" ", 2); ft_putstr_fd(" ", 2);
lst->cursor ? ft_putstr(tgetstr("ue", NULL)) : (0); while (i++ < (c_sx))
ft_putstr(" ");
ft_putstr_fd("\e[00m", 2);
ft_putstr(" ");
} }
/* /*
@ -47,7 +55,7 @@ static int c_printer_line(t_comp *c, t_clst *lst, int loop, int i)
t_clst *ptr; t_clst *ptr;
ptr = lst->next; ptr = lst->next;
c_printer_node(lst); c_printer_node(lst, c->c_sx);
while (loop) while (loop)
{ {
i = 1; i = 1;
@ -60,9 +68,7 @@ static int c_printer_line(t_comp *c, t_clst *lst, int loop, int i)
if (ptr != c->lst) if (ptr != c->lst)
{ {
i = lst->len; i = lst->len;
while (i++ < (c->c_sx + 1)) c_printer_node(ptr, c->c_sx);
ft_putstr(" ");
c_printer_node(ptr);
lst = ptr; lst = ptr;
ptr = ptr->next; ptr = ptr->next;
} }

View file

@ -0,0 +1,71 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* c_rematch.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
/* Updated: 2017/02/15 20:17:55 by alao ### ########.fr */
/* */
/* ************************************************************************** */
#include "completion.h"
static int c_refresh_match(t_comp *c, long int keypress)
{
DG("Refresh match");
char *tmp;
char kpconv[2];
kpconv[0] = keypress;
kpconv[1] = '\0';
tmp = c->match ? ft_strjoin(c->match, kpconv) : ft_strdup(kpconv);
c->match ? ft_memdel((void *)&c->match) : (0);
c->match = ft_strdup(tmp);
tmp ? ft_memdel((void *)&tmp) : (0);
(void)c;
return (0);
}
static int c_refresh_list(t_comp *c)
{
DG("Refresh list");
t_clst *ptr;
t_clst *ptr_bk;
ptr = c->lst;
c->lst->prev->next = NULL;
c->lst->prev = NULL;
while (ptr->next)
{
DG("Refresh list loop on [%s]", ptr->name);
if (ft_strncmp(c->match, ptr->name, ft_strlen(c->match)) != 0)
{
if (ptr == c->lst)
{
c->lst = ptr->next;
c->lst->prev = NULL;
}
ptr->prev->next = ptr->next;
ptr->next->prev = ptr->prev;
ptr_bk = ptr->next;
ptr->name ? ft_memdel((void *)&ptr->name) : (0);
ptr ? ft_memdel((void *)&ptr) : (0);
ptr = ptr_bk;
}
ptr = ptr->next;
}
DG("Refresh list end");
return (0);
}
int c_rematch(t_comp *c, long int keypress)
{
if (ft_isascii(keypress))
{
c_refresh_match(c, keypress);
c_refresh_list(c);
}
return (0);
}

View file

@ -6,38 +6,12 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/20 14:50:33 by alao #+# #+# */ /* Created: 2016/09/20 14:50:33 by alao #+# #+# */
/* Updated: 2017/02/03 17:33:41 by jhalford ### ########.fr */ /* Updated: 2017/02/15 19:30:18 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "completion.h" #include "completion.h"
/*
** DEBUG FUNCTION
*/
int test(t_comp *c)
{
t_clst *tmp;
int i;
i = 1;
if (!(c->lst))
{
return (0);
}
if (c->lst->prev != c->lst)
{
tmp = c->lst->next;
while (tmp != c->lst)
{
i++;
tmp = tmp->next;
}
}
return (0);
}
/* /*
** Function to select the next item in the list if it has already been Created ** Function to select the next item in the list if it has already been Created
** and if the keypressed is tab. ** and if the keypressed is tab.
@ -64,6 +38,11 @@ static void c_next_item(t_comp *c)
static int c_dispatcher(t_data *s) 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) if (s->comp && s->comp->lst == NULL)
{ {
c_clear(s); c_clear(s);
@ -119,6 +98,5 @@ int completion(long int keypress)
else else
return (c_gtfo(s->comp, keypress)); return (c_gtfo(s->comp, keypress));
} }
test(s->comp);
return (c_dispatcher(s)); return (c_dispatcher(s));
} }