From 591935b6c3e87cdb7eb75fc679e20ffc8366811b Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 1 May 2001 22:51:49 +0000 Subject: Zop, un terminal --- include/terminal.h | 12 ++++++++++++ lib/terminal.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 include/terminal.h create mode 100644 lib/terminal.c diff --git a/include/terminal.h b/include/terminal.h new file mode 100644 index 0000000..cf3eafb --- /dev/null +++ b/include/terminal.h @@ -0,0 +1,12 @@ +#ifndef __TERMINAL_H__ +#define __TERMINAL_H__ +#include + +extern FILE *input; +extern struct termios initial_settings, new_settings; + +void openterm(void); +void clearterm(void); +void initterm(void); + +#endif 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