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
|
void my_init_term(t_env *env)
{
char *name;
t_termios new_term;
if (!(name = getenv("TERM")))
name = "xterm";
if (tgetent(NULL, name) <= 0)
my_fputerr(NULL, "Error: Could not access the termcap database.\n");
if (isatty(STDIN) == 0 || tcgetattr(STDIN, env->term) == -1)
my_fputerr(NULL, "Error: Not a terminal.\n");
name = ttyname(STDIN);
if ((env->fd = open(name, O_WRONLY)) == -1)
my_fputerr(NULL, "Error: Could not open fd.\n");
new_term = *(env->term); //Je copie la structure originale dans new_term afin de modifier par la suite ce qui m'interesse
new_term.c_lflag &= ~(ICANON | ECHO);
new_term.c_cc[VMIN] = 1;
new_term.c_cc[VTIME] = 0;
if (tcsetattr(STDIN, TCSANOW, &new_term) < 0) //Je change le terminal, env->term est inchangé
my_fputerr(env, "Error: termios.\n");
tputs(tgetstr(CURSOR_HIDDEN, NULL), 0, my_tputchar);
tputs(tgetstr(CLEAR, NULL), 0, my_tputchar);
}
/* Retour à la normal */
void my_restore_term(t_env *env)
{
tputs(tgetstr(CURSOR_VISIBLE, NULL), 0, my_tputchar);
if (tcsetattr(STDIN, TCSANOW, env->term) < 0) //Utilisation de la structure "propre" enregistrer
{
my_puterror("Error\n");
exit(-1);
}
if (close(env->fd) == -1)
{
my_puterror("Error: Could not close fd.\n");
exit(-1);
}
} |
Partager