summaryrefslogtreecommitdiff
path: root/lib/terminal.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/terminal.c')
-rw-r--r--lib/terminal.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/terminal.c b/lib/terminal.c
new file mode 100644
index 0000000..df3e61d
--- /dev/null
+++ b/lib/terminal.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <termios.h>
+#include <string.h>
+#include "config.h"
+
+FILE *input;
+struct termios initial_settings, new_settings;
+
+void initterm() {
+ 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(1, _("could not set terminal attributes"));
+ }
+
+}
+
+void clearterm() {
+ tcsetattr(fileno(input), TCSANOW, &initial_settings);
+}
+
+void openterm() {
+ if (!(input = fopen("/dev/tty", "r"))) {
+ exception(1, _("could not open terminal"));
+ }
+}