summaryrefslogtreecommitdiff
path: root/lib/terminal.c
blob: 58e6851f06dfa613b51a6636b82af663c625def8 (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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <string.h>
#include "config.h"
#include "exceptions.h"

FILE *input;
struct termios initial_settings, new_settings;

void initterm(void)
{
    tcgetattr(fileno(input), &initial_settings);
    new_settings = initial_settings;
    new_settings.c_lflag &= ~ICANON;
    new_settings.c_lflag &= ~ECHO;
    new_settings.c_cc[VMIN] = 1;
    new_settings.c_cc[VTIME] = 0;
    new_settings.c_lflag &= ~ISIG;

    if (tcsetattr(fileno(input), TCSANOW, &new_settings) != 0) {
	exception(2, _("could not set terminal attributes"));
    }

}

void clearterm(void)
{
    tcsetattr(fileno(input), TCSANOW, &initial_settings);
}

void openterm(void)
{
    if (!(input = fopen("/dev/tty", "r"))) {
	exception(2, _("could not open terminal"));
    }
}