summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <Pixel>2001-05-01 22:51:49 +0000
committerPixel <Pixel>2001-05-01 22:51:49 +0000
commit591935b6c3e87cdb7eb75fc679e20ffc8366811b (patch)
tree827a6d0de2ea52a71558c95b0d1a8ecba5a42119 /lib
parentec32dd3c2506d341fe7106418f0e538f9407fbce (diff)
Zop, un terminal
Diffstat (limited to 'lib')
-rw-r--r--lib/terminal.c38
1 files changed, 38 insertions, 0 deletions
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 <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"));
+ }
+}