diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-15 00:07:18 -0700 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-15 00:07:18 -0700 |
commit | 8ddf546d8e36fca6b147b78621df31800b081e60 (patch) | |
tree | 430dd95a4731445c7cf931abaa7d26f21c907686 /tty.c | |
parent | 6bace05aece734fd1efbfa7c46040f4e6fad2d86 (diff) |
Truncate matches at terminal width
Diffstat (limited to 'tty.c')
-rw-r--r-- | tty.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -1,8 +1,11 @@ +#define _GNU_SOURCE #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <stdarg.h> +#include <termios.h> +#include <sys/ioctl.h> #include "tty.h" @@ -28,9 +31,20 @@ void tty_init(tty_t *tty, const char *tty_filename){ tcsetattr(tty->fdin, TCSANOW, &new_termios); + tty_getwinsz(tty); + tty_setnormal(tty); } +void tty_getwinsz(tty_t *tty){ + struct winsize ws; + if(ioctl(fileno(tty->fout), TIOCGWINSZ, &ws) == -1){ + tty->maxwidth = 80; + }else{ + tty->maxwidth = ws.ws_col; + } +} + char tty_getchar(tty_t *tty){ char ch; int size = read(tty->fdin, &ch, 1); @@ -92,3 +106,6 @@ void tty_flush(tty_t *tty){ fflush(tty->fout); } +size_t tty_getwidth(tty_t *tty){ + return tty->maxwidth; +} |