From 14ee2184432d9f3f34c717b35b95e1e9c816381f Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 9 Jul 2017 16:25:22 +0200 Subject: [PATCH] Refactor, use libite (-lite) version of initscr() Signed-off-by: Joachim Nilsson --- src/util.c | 54 +----------------------------------------------------- src/util.h | 11 +++++++++-- 2 files changed, 10 insertions(+), 55 deletions(-) diff --git a/src/util.c b/src/util.c index 52745445..87967442 100644 --- a/src/util.c +++ b/src/util.c @@ -25,12 +25,7 @@ #include /* isprint() */ #include #include - -#ifdef HAVE_TERMIOS_H /* for screen_width() */ -#include -#include -#include -#endif +#include "util.h" int screen_rows = 24; int screen_cols = 80; @@ -78,53 +73,6 @@ char *sanitize(char *arg, size_t len) return NULL; } -static void initscr(int *row, int *col) -{ - if (!row || !col) - return; - -#if defined(TCSANOW) && defined(POLLIN) - struct termios tc, saved; - struct pollfd fd = { STDIN_FILENO, POLLIN, 0 }; - - /* Disable echo to terminal while probing */ - tcgetattr(STDERR_FILENO, &tc); - saved = tc; - tc.c_cflag |= (CLOCAL | CREAD); - tc.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); - tcsetattr(STDERR_FILENO, TCSANOW, &tc); - - /* - * Save cursor pos+attr - * Diable top+bottom margins - * Set cursor at the far bottom,right pos - * Query term for resulting pos - */ - fprintf(stderr, "\e7" "\e[r" "\e[999;999H" "\e[6n"); - - /* - * Wait here for terminal to echo back \e[row,lineR ... - */ - if (poll(&fd, 1, 300) <= 0 || scanf("\e[%d;%dR", row, col) != 2) { - *row = 24; - *col = 80; - } - - /* - * Restore above saved cursor pos+attr - */ - fprintf(stderr, "\e8"); - - /* Restore terminal */ - tcsetattr(STDERR_FILENO, TCSANOW, &saved); - - return; -#else - *row = 24; - *col = 80; -#endif -} - void screen_init(void) { initscr(&screen_rows, &screen_cols); diff --git a/src/util.h b/src/util.h index db44a876..a6bf77d6 100644 --- a/src/util.h +++ b/src/util.h @@ -24,13 +24,20 @@ #ifndef FINIT_UTIL_H_ #define FINIT_UTIL_H_ -#define SCREEN_WIDTH screen_cols -#include +#include "config.h" +#ifdef HAVE_TERMIOS_H /* for screen_width() */ +#include +#include +#include +#endif extern int screen_rows; extern int screen_cols; extern char *prognm; +#define SCREEN_WIDTH screen_cols +#include + char *progname (char *arg0); void do_sleep (unsigned int sec); char *sanitize (char *arg, size_t len);