From 591935b6c3e87cdb7eb75fc679e20ffc8366811b Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 1 May 2001 22:51:49 +0000 Subject: Zop, un terminal --- lib/terminal.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/terminal.c (limited to 'lib') diff --git a/lib/terminal.c b/lib/terminal.c new file mode 100644 index 0000000..58e6851 --- /dev/null +++ b/lib/terminal.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#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")); + } +} -- cgit v1.2.3