-
Notifications
You must be signed in to change notification settings - Fork 0
/
term.c
45 lines (40 loc) · 1.49 KB
/
term.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* term.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbopp <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/25 12:38:13 by lbopp #+# #+# */
/* Updated: 2017/02/25 12:38:15 by lbopp ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <termios.h>
#include <term.h>
struct termios g_init_term;
void default_term(void);
void init_term(void)
{
char *term;
struct termios attr;
tcgetattr(STDIN_FILENO, &g_init_term);
tcgetattr(STDIN_FILENO, &attr);
attr.c_lflag &= ~(ECHO | ICANON);
attr.c_cc[VMIN] = 1;
attr.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSADRAIN, &attr);
if (!(term = getenv("TERM")))
{
ft_putstr_fd("minishell: environment not found\n", 2);
default_term();
exit(0);
}
else
tgetent(NULL, term);
}
void default_term(void)
{
tcsetattr(STDIN_FILENO, TCSADRAIN, &g_init_term);
tgetent(NULL, getenv("TERM"));
}