aboutsummaryrefslogtreecommitdiff
path: root/lib/tctl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tctl')
-rw-r--r--lib/tctl/tctl.c40
-rw-r--r--lib/tctl/tctl.h9
2 files changed, 46 insertions, 3 deletions
diff --git a/lib/tctl/tctl.c b/lib/tctl/tctl.c
index 187d1a9..d54f2dd 100644
--- a/lib/tctl/tctl.c
+++ b/lib/tctl/tctl.c
@@ -4,6 +4,10 @@
#define GET_WIN_SIZE 0x5413
#define SET_WIN_SIZE 0x5414
#define TC_GET_ATTR 0x5401
+#define TC_SET_ATTR 0x5402
+#define FD_FLUSH 0x000b
+#define ICANON 000002
+#define ECHO 000010
window_size_t tctl_get_window_size()
{
@@ -24,3 +28,39 @@ int isatty()
termios_t term;
return ioctl(1, TC_GET_ATTR, &term) == 0;
}
+
+
+int tcgetattr(int fd, termios_t *termios)
+{
+ return ioctl(fd, TC_GET_ATTR, termios);
+}
+
+
+void tcsetattr(int fd, termios_t *termios)
+{
+ ioctl(fd, TC_SET_ATTR, termios);
+}
+
+
+void setcanonical(termios_t *term, int is_canonical)
+{
+ if (is_canonical)
+ term->c_lflag |= ICANON;
+ else
+ term->c_lflag &= ~ICANON;
+}
+
+
+void setecho(termios_t *term, int is_echo)
+{
+ if (is_echo)
+ term->c_lflag |= ECHO;
+ else
+ term->c_lflag &= ~ECHO;
+}
+
+
+void flush(unsigned int fd)
+{
+ ioctl(fd, FD_FLUSH, 0);
+}
diff --git a/lib/tctl/tctl.h b/lib/tctl/tctl.h
index bdcdb66..d16c9eb 100644
--- a/lib/tctl/tctl.h
+++ b/lib/tctl/tctl.h
@@ -14,13 +14,16 @@ typedef struct {
unsigned int c_cflag;
unsigned int c_lflag;
unsigned char c_line;
- unsigned char c_cc[32];
- unsigned int c_ispeed;
- unsigned int c_ospeed;
+ unsigned char c_cc[19];
} termios_t;
window_size_t tctl_get_window_size();
void tctl_set_window_size(window_size_t size);
int isatty();
+int tcgetattr(int fd, termios_t *termios);
+void tcsetattr(int fd, termios_t *termios);
+void setcanonical(termios_t *term, int is_canonical);
+void setecho(termios_t *term, int is_echo);
+void flush(unsigned int fd);
#endif