aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-02-23 20:26:04 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-02-23 20:26:04 +0000
commit46e53d124d03faedd11e99fdb0153d84ce174f99 (patch)
tree2b305f7413f7b6fdb074cb970cae2e08249b6c93 /termkey.c
parent8f8e96f015efa9541f6584ff5d15fe3f01a32b28 (diff)
downloadtermo-46e53d124d03faedd11e99fdb0153d84ce174f99.tar.gz
termo-46e53d124d03faedd11e99fdb0153d84ce174f99.tar.xz
termo-46e53d124d03faedd11e99fdb0153d84ce174f99.zip
Moved termios magic out of demo.c into termkey.c where it belongs
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/termkey.c b/termkey.c
index 2830f01..7ea6ff2 100644
--- a/termkey.c
+++ b/termkey.c
@@ -4,6 +4,7 @@
#include <poll.h>
#include <unistd.h>
#include <string.h>
+#include <termios.h>
#include <stdio.h>
@@ -21,6 +22,9 @@ struct termkey {
size_t buffcount; // NUMBER of entires valid in buffer
size_t buffsize; // Total malloc'ed size
+ struct termios restore_termios;
+ char restore_termios_valid;
+
int waittime; // msec
char is_closed;
@@ -78,6 +82,8 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
tk->buffcount = 0;
tk->buffsize = buffsize;
+ tk->restore_termios_valid = 0;
+
tk->waittime = waittime;
tk->is_closed = 0;
@@ -181,6 +187,19 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
termkey_register_csifunc(tk, TERMKEY_SYM_F19, 33, "F19");
termkey_register_csifunc(tk, TERMKEY_SYM_F20, 34, "F20");
+ if(!(flags & TERMKEY_FLAG_NOTERMIOS)) {
+ struct termios termios;
+ if(tcgetattr(fd, &termios) == 0) {
+ tk->restore_termios = termios;
+ tk->restore_termios_valid = 1;
+
+ termios.c_iflag &= ~(IXON|INLCR|ICRNL);
+ termios.c_lflag &= ~(ICANON|ECHO|ISIG);
+
+ tcsetattr(fd, TCSANOW, &termios);
+ }
+ }
+
return tk;
}
@@ -198,6 +217,14 @@ void termkey_free(termkey_t *tk)
free(tk);
}
+void termkey_destroy(termkey_t *tk)
+{
+ if(tk->restore_termios_valid)
+ tcsetattr(tk->fd, TCSANOW, &tk->restore_termios);
+
+ termkey_free(tk);
+}
+
void termkey_setwaittime(termkey_t *tk, int msec)
{
tk->waittime = msec;