mirror of
https://github.com/troglobit/finit.git
synced 2026-11-06 15:51:03 +00:00
Refactor, use libite (-lite) version of initscr()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
52fe525442
commit
14ee218443
2 files changed
+10
-55
No files matched your search
+1
-53
@@ -25,12 +25,7 @@
|
|||||||
#include <ctype.h> /* isprint() */
|
#include <ctype.h> /* isprint() */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "util.h"
|
||||||
#ifdef HAVE_TERMIOS_H /* for screen_width() */
|
|
||||||
#include <poll.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <termios.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int screen_rows = 24;
|
int screen_rows = 24;
|
||||||
int screen_cols = 80;
|
int screen_cols = 80;
|
||||||
@@ -78,53 +73,6 @@ char *sanitize(char *arg, size_t len)
|
|||||||
return NULL;
|
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)
|
void screen_init(void)
|
||||||
{
|
{
|
||||||
initscr(&screen_rows, &screen_cols);
|
initscr(&screen_rows, &screen_cols);
|
||||||
|
|||||||
+9
-2
@@ -24,13 +24,20 @@
|
|||||||
#ifndef FINIT_UTIL_H_
|
#ifndef FINIT_UTIL_H_
|
||||||
#define FINIT_UTIL_H_
|
#define FINIT_UTIL_H_
|
||||||
|
|
||||||
#define SCREEN_WIDTH screen_cols
|
#include "config.h"
|
||||||
#include <lite/conio.h>
|
#ifdef HAVE_TERMIOS_H /* for screen_width() */
|
||||||
|
#include <poll.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
extern int screen_rows;
|
extern int screen_rows;
|
||||||
extern int screen_cols;
|
extern int screen_cols;
|
||||||
extern char *prognm;
|
extern char *prognm;
|
||||||
|
|
||||||
|
#define SCREEN_WIDTH screen_cols
|
||||||
|
#include <lite/conio.h>
|
||||||
|
|
||||||
char *progname (char *arg0);
|
char *progname (char *arg0);
|
||||||
void do_sleep (unsigned int sec);
|
void do_sleep (unsigned int sec);
|
||||||
char *sanitize (char *arg, size_t len);
|
char *sanitize (char *arg, size_t len);
|
||||||
|
|||||||
Reference in new issue
Block a user