From 328db0b2605a57e72d511f2769000621b0a45cb8 Mon Sep 17 00:00:00 2001 From: M600 Date: Fri, 10 Mar 2017 08:48:21 +0100 Subject: [PATCH] Add rolling list --- 42sh/Makefile | 4 +-- 42sh/includes/completion.h | 14 ++++++--- 42sh/src/completion/c_init.c | 8 ++++- 42sh/src/completion/c_printer.c | 51 ++++++++++++++++++++++++++++++-- 42sh/src/completion/c_sizing.c | 4 +-- 42sh/src/completion/c_terminal.c | 10 +++---- 42sh/src/completion/completion.c | 2 +- 7 files changed, 74 insertions(+), 19 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index f410aef1..ab23380f 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/02/17 17:16:16 by wescande ### ########.fr # +# Updated: 2017/03/10 08:47:51 by alao ### ########.fr # # # # **************************************************************************** # @@ -242,7 +242,7 @@ NB = $(words $(SRC_BASE)) INDEX = 0 all : - @make -j $(NAME) + @make -f $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) @$(CC) $(FLAGS) $(D_FLAGS) \ diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 61943c44..13bac1cc 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/09 17:34:53 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 08:31:49 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,6 +57,9 @@ typedef struct s_clst ** 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. @@ -65,9 +68,9 @@ typedef struct s_clst ** ** Exemple: [ ls / ; cd (tab) ; pwd ] ** -** (int)cutpoint -** | -** | +** (int)cutpoint +** | +** | ** Become: [ls / ;] [ ] [cd ] [ ; pwd] ** | | | | ** | | | | @@ -93,6 +96,9 @@ typedef struct s_comp int c_line; int win_x; int win_y; + int m_size; + int pos_x; + int pos_y; int key; int isfolder; int isrematch; diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index f7df54b5..a661cf45 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/09 14:45:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 08:32:11 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,6 +56,12 @@ 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; diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index f43163de..0dc398b6 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 08:45:06 by alao ### ########.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++; + if (y > 1) + { + c->pos_x = x; + c->pos_y = y; + 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,17 @@ void c_printer(t_comp *c) { t_clst *ptr; int loop; + int max_line; - ptr = c->lst; loop = c->c_line; - while (loop) + max_line = c->m_size - 1; + ptr = c_rolling(c); + 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_sizing.c b/42sh/src/completion/c_sizing.c index 78892cff..7a2697b0 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/17 13:45:33 by alao ### ########.fr */ +/* Updated: 2017/03/10 08:45:52 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,7 +61,5 @@ int c_sizing(t_comp *c) c->c_pline = 0; c->c_line = 0; } - if ((c->win_y < c->c_line)) - c_clear(data_singleton()); return (0); } diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index 4fdc60b1..83800ecf 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/17 18:36:56 by alao ### ########.fr */ +/* Updated: 2017/03/10 08:46:13 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,7 @@ void c_term_mv_back(t_comp *c) int lcmd; i = 0; - while (i != (c->c_line)) + while (i != (c->m_size)) { ft_putstr(tgetstr("up", NULL)); i++; @@ -71,14 +71,14 @@ void c_term_mv_down(t_comp *c) int i; i = 0; - while (i < c->c_line) + while (i < c->m_size) { ft_putstr(tgetstr("do", NULL)); ft_putstr(tgetstr("cd", NULL)); i++; } i = 0; - while (i != (c->c_line - 1)) + while (i != (c->m_size - 1)) { ft_putstr(tgetstr("up", NULL)); i++; @@ -86,7 +86,7 @@ void c_term_mv_down(t_comp *c) } /* -** If the terminal has chaged in size, the function will refresh these values +** If the terminal has changed in size, the function will refresh these values ** and clear the previous print list. */ diff --git a/42sh/src/completion/completion.c b/42sh/src/completion/completion.c index d92dea80..d85a41b6 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/03/09 14:44:52 by gwojda ### ########.fr */ +/* Updated: 2017/03/10 08:46:26 by alao ### ########.fr */ /* */ /* ************************************************************************** */