From b46725feffee6f8492e3cfa009506c614ae2663c Mon Sep 17 00:00:00 2001 From: Gene Cumm Date: Fri, 2 Jul 2010 20:08:07 -0400 Subject: [PATCH] rosh: make getscreensize more effective and usable --- com32/rosh/rosh.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/com32/rosh/rosh.h b/com32/rosh/rosh.h index a8edda6..bb768fc 100644 --- a/com32/rosh/rosh.h +++ b/com32/rosh/rosh.h @@ -32,6 +32,7 @@ #include /* macro: true false */ #include /* strcpy() strlen() memcpy() strchr() */ #include +#include #include /* fstat() */ #include /* open(); open mode macros */ #include /* fdopendir() opendir() readdir() closedir() DIR */ @@ -41,7 +42,8 @@ #include /* isspace() */ #include -#include +#include /* console_ansi_raw() console_ansi_std() */ +#include #ifdef DO_DEBUG # define ROSH_DEBUG printf @@ -102,15 +104,24 @@ static inline int getscreensize(int fd, int *rows, int *cols) { char *str; int rv; - *rows = 0; - *cols = 0; + struct winsize ws; + if (rows) + *rows = 0; + if (cols) + *cols = 0; + str = NULL; if (fd == 1) { - if (rows) { + ioctl(0, TIOCGWINSZ, &ws); +/* if (rows) + *rows = ws.ws_row; + if (cols) + *cols = ws.ws_col;*/ + if (rows && !*rows) { str = getenv("LINES"); if (str) *rows = atoi(str); } - if (cols) { + if (cols && !*cols) { str = getenv("COLUMNS"); if (str) *cols = atoi(str); -- 2.7.4