-
Notifications
You must be signed in to change notification settings - Fork 0
/
term_utils.c
57 lines (53 loc) · 1.75 KB
/
term_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* term_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hchorfi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/03 13:36:32 by hchorfi #+# #+# */
/* Updated: 2021/05/03 13:37:48 by hchorfi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_up_down(int c, int *col)
{
if (c == DOWN_ARROW)
{
down_key();
if (ft_strlen(g_data.line))
*col = ft_strlen(g_data.line) + 16;
else
*col = 16;
}
else if (c == UP_ARROW)
{
up_key();
if (ft_strlen(g_data.line))
*col = ft_strlen(g_data.line) + 16;
else
*col = 16;
}
}
void ft_add_line_to_his(void)
{
t_list *prev;
t_list *tail;
t_list *newlist;
if (ft_lstsize(g_data.history) == 1)
{
ft_lstadd_front(&g_data.history, ft_lstnew(ft_strdup(g_data.line)));
g_data.history->prev = NULL;
ft_lstlast(g_data.history)->prev = g_data.history;
}
else if (ft_lstsize(g_data.history) > 1)
{
tail = ft_lstlast(g_data.history);
prev = ft_lstlast(g_data.history)->prev;
newlist = ft_lstnew(ft_strdup(g_data.line));
newlist->next = prev->next;
prev->next = newlist;
newlist->prev = prev;
newlist->next->prev = newlist;
}
}