-
Notifications
You must be signed in to change notification settings - Fork 1
/
termcap_fl.c
77 lines (69 loc) · 1.91 KB
/
termcap_fl.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* termcap_fl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fbouibao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/15 15:48:04 by ssamadi #+# #+# */
/* Updated: 2021/05/27 13:01:26 by fbouibao ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell_hr.h"
int ft_putc(int s)
{
return (write(1, &s, 1));
}
int get_char(void)
{
char c;
int total;
struct termios old;
struct termios term;
tcgetattr(0, &old);
term = old;
term.c_lflag &= ~(ICANON | ECHO);
term.c_cc[VMIN] = 0;
term.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &term);
total = 0;
while (read(0, &c, 1) <= 0)
continue ;
total += c;
while (read(0, &c, 1) > 0)
total += c;
tcsetattr(0, TCSANOW, &old);
return (total);
}
void write_key_up(t_history **h_tmp)
{
write(1, (*h_tmp)->cmd, ft_strlen((*h_tmp)->cmd));
free(g_all->ret);
}
void free_n_enter(void)
{
free(g_all->line);
g_all->line = NULL;
write(1, "\n", 1);
}
char *loop_termcap(t_history **history, t_history **h_tmp, int tm, int a)
{
int d;
d = 0;
while (1)
{
d = half_termcap(d);
if (d == -666)
exit(0);
key_remove(d);
key_down(h_tmp, d);
if (key_up(history, d, h_tmp, a) == 1)
continue ;
tm = key_enter(d, history, h_tmp);
if (tm == 1)
return (g_all->ret);
else if (tm == 2)
continue ;
}
return (NULL);
}