mirror of
https://github.com/troglobit/finit.git
synced 2026-10-06 15:50:12 +07:00
Add util.c:screen_init() to probe screen size once per boot
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include "sig.h"
|
||||
#include "sm.h"
|
||||
#include "tty.h"
|
||||
#include "util.h"
|
||||
#include "utmp-api.h"
|
||||
#include "watchdog.h"
|
||||
|
||||
@@ -228,6 +229,9 @@ int main(int argc, char* argv[])
|
||||
if (getpid() != 1)
|
||||
return client(argc, argv);
|
||||
|
||||
/* Set up canvas */
|
||||
screen_init();
|
||||
|
||||
/*
|
||||
* In case of emergency.
|
||||
*/
|
||||
|
||||
+3
-2
@@ -32,13 +32,14 @@
|
||||
#include <stdarg.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <lite/lite.h>
|
||||
#include <lite/conio.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
#include "private.h"
|
||||
#include "util.h"
|
||||
#include "utmp-api.h"
|
||||
|
||||
|
||||
char *strip_line(char *line)
|
||||
{
|
||||
char *ptr;
|
||||
@@ -79,7 +80,7 @@ static int print_timestamp(void)
|
||||
|
||||
void printv(const char *fmt, va_list ap)
|
||||
{
|
||||
char buf[80];
|
||||
char buf[SCREEN_WIDTH];
|
||||
size_t len;
|
||||
const char dots[] = " .....................................................................";
|
||||
|
||||
|
||||
+1
-3
@@ -37,9 +37,6 @@
|
||||
#include <sys/un.h>
|
||||
#include <lite/lite.h>
|
||||
|
||||
#define SCREEN_WIDTH screen_width()
|
||||
#include <lite/conio.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "cond.h"
|
||||
#include "serv.h"
|
||||
@@ -662,6 +659,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
screen_init();
|
||||
if (optind < argc) {
|
||||
char *cmd = argv[optind++];
|
||||
char arg[120] = "";
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include <stdio.h>
|
||||
#include <lite/lite.h>
|
||||
|
||||
#define SCREEN_WIDTH screen_width()
|
||||
#include <lite/conio.h>
|
||||
#include "util.h"
|
||||
|
||||
static const char *cwd;
|
||||
|
||||
+26
-6
@@ -32,7 +32,10 @@
|
||||
#include <termios.h>
|
||||
#endif
|
||||
|
||||
char *prognm = NULL;
|
||||
int screen_setup = -1;
|
||||
int screen_rows = 24;
|
||||
int screen_cols = 80;
|
||||
char *prognm = NULL;
|
||||
|
||||
char *progname(char *arg0)
|
||||
{
|
||||
@@ -77,14 +80,16 @@ char *sanitize(char *arg, size_t len)
|
||||
}
|
||||
|
||||
#define ESC "\033"
|
||||
int screen_width(void)
|
||||
void screen_init(void)
|
||||
{
|
||||
int ret = 80;
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
char buf[42];
|
||||
struct termios tc, saved;
|
||||
struct pollfd fd = { STDIN_FILENO, POLLIN, 0 };
|
||||
|
||||
if (screen_setup != -1)
|
||||
return;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
tcgetattr(STDERR_FILENO, &tc);
|
||||
saved = tc;
|
||||
@@ -96,14 +101,29 @@ int screen_width(void)
|
||||
if (poll(&fd, 1, 300) > 0) {
|
||||
int row, col;
|
||||
|
||||
if (scanf(ESC "[%d;%dR", &row, &col) == 2)
|
||||
ret = col;
|
||||
if (scanf(ESC "[%d;%dR", &row, &col) == 2) {
|
||||
screen_rows = row;
|
||||
screen_cols = col;
|
||||
screen_setup = 1;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, ESC "8");
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &saved);
|
||||
#endif
|
||||
return ret;
|
||||
|
||||
if (screen_cols > 132)
|
||||
screen_cols = 132;
|
||||
}
|
||||
|
||||
int screen_width(void)
|
||||
{
|
||||
screen_init();
|
||||
|
||||
if (screen_cols < 1)
|
||||
return 80;
|
||||
|
||||
return screen_cols;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,11 +24,18 @@
|
||||
#ifndef FINIT_UTIL_H_
|
||||
#define FINIT_UTIL_H_
|
||||
|
||||
#define SCREEN_WIDTH screen_cols
|
||||
#include <lite/conio.h>
|
||||
|
||||
extern int screen_rows;
|
||||
extern int screen_cols;
|
||||
extern char *prognm;
|
||||
|
||||
char *progname (char *arg0);
|
||||
void do_sleep (unsigned int sec);
|
||||
char *sanitize (char *arg, size_t len);
|
||||
|
||||
void screen_init (void);
|
||||
int screen_width (void);
|
||||
|
||||
#endif /* FINIT_UTIL_H_ */
|
||||
|
||||
Reference in New Issue
Block a user