This repository has been archived by the owner on Aug 11, 2023. It is now read-only.
forked from sebastiencs/my_select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.c
102 lines (93 loc) · 1.98 KB
/
move.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
** move.c for my_select in /home/sebastien/travaux/my_select
**
** Made by sebastien
** Login <sebastien@epitech.net>
**
** Started on Thu Jan 16 17:21:08 2014 sebastien
** Last update Thu Jan 16 17:22:40 2014 sebastien
*/
#include <sys/ioctl.h>
#include "my_select.h"
void goto_prec(t_list *root)
{
t_list *tmp;
if (root->nb_elem != 1)
{
tmp = root->next;
while (tmp && tmp->is_current == 0)
tmp = tmp->next;
if (tmp->prec != root)
tmp->prec->is_current = 1;
else
tmp->prec->prec->is_current = 1;
tmp->is_current = 0;
clearscreen(root);
print_list(root);
}
}
void goto_next(t_list *root)
{
t_list *tmp;
if (root->nb_elem != 1)
{
tmp = root->next;
while (tmp && tmp->is_current == 0)
tmp = tmp->next;
tmp->is_current = 0;
if (tmp->next != root)
tmp->next->is_current = 1;
else
tmp->next->next->is_current = 1;
clearscreen(root);
print_list(root);
}
}
void goto_left(t_list *root)
{
struct winsize win;
t_list *tmp;
int i;
i = 0;
if ((ioctl(fd_tty, TIOCGWINSZ, &win)) == -1)
return ;
if (root->nb_elem != 1 && win.ws_row < root->nb_elem)
{
tmp = root->next;
while (tmp && tmp->is_current == 0 && ++i)
tmp = tmp->next;
if (i < win.ws_row - 1)
return ;
i = 1;
tmp->is_current = 0;
while (i++ < win.ws_row)
tmp = tmp->prec;
tmp->is_current = 1;
clearscreen(root);
print_list(root);
}
}
void goto_right(t_list *root)
{
struct winsize win;
t_list *tmp;
int i;
i = 0;
if ((ioctl(fd_tty, TIOCGWINSZ, &win)) == -1)
return ;
if (root->nb_elem != 1 && win.ws_row < root->nb_elem)
{
tmp = root->next;
while (tmp && tmp->is_current == 0 && ++i)
tmp = tmp->next;
if (i > root->nb_elem - win.ws_row)
return ;
i = 1;
tmp->is_current = 0;
while (tmp != root && i++ < win.ws_row)
tmp = tmp->next;
tmp->is_current = 1;
clearscreen(root);
print_list(root);
}
}