summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
blob: bbf8f2275933c5b35c7f494fe9c0d0a80fe408cc (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   u_init.c                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <unistd.h>
#include <stdio.h>
#include <termios.h>
#include <stdlib.h>
#include <string.h>
#include <term.h>
#include <curses.h>

#include "c_init.h"

t_caps
    *c_get_struct(int mode, t_caps *src)
{
    static t_caps *caps;

    if (mode == 1)
    {
        caps = src;
    }
    return (caps);
}

int16_t c_init_tcaps(void)
{
    t_caps tcaps;
    char *bp;
    char *term;

    bp = NULL;
    term = getenv("TERM");
    if (!tgetent(bp, term))
        return (-1);
    tcaps.lc = tgetstr("lc", &term);
    tcaps.kl = tgetstr("kl", &term);
    tcaps.kr = tgetstr("kr", &term);
    tcaps.pc = tgetstr("pc", &term);
    tcaps.bc = tgetstr("bc", &term);
    tcaps.up = tgetstr("up", &term);
    tcaps.nd = tgetstr("nd", &term);
    tcgetattr(STDIN_FILENO, &tcaps.tios);

    tcaps.tios.c_lflag &= ~(ECHO | ICANON);
    tcaps.tios.c_cc[VMIN] = 0;
    tcaps.tios.c_cc[VTIME] = 1;
    tcsetattr(STDIN_FILENO, TCSAFLUSH, &tcaps.tios);
    c_get_struct(1, &tcaps);
    return (1);
}