DD2-monitor/viz/curses/ecran.c

77 lines
1.5 KiB
C
Raw Normal View History

2019-01-10 01:44:47 +01:00
#include <stdio.h>
#include <stdlib.h>
2019-01-10 14:07:56 +01:00
#include <string.h>
#include <sys/utsname.h>
2019-01-10 01:44:47 +01:00
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
2019-01-30 16:44:43 +01:00
extern int verbosity;
2019-01-10 01:44:47 +01:00
/* ---------------------------------------------------------------- */
2019-01-22 15:24:49 +01:00
int message(char *txt)
{
2019-01-27 12:12:49 +01:00
static int pass = 0;
2019-01-30 16:44:43 +01:00
#if TRACE
2019-01-29 23:25:59 +01:00
fprintf(stderr, "%s [%s]\n", __func__, txt);
2019-01-30 16:44:43 +01:00
#endif
2019-01-29 23:25:59 +01:00
2019-01-22 15:24:49 +01:00
standout();
2019-02-05 12:16:27 +01:00
mvhline(LINES-1, 0, ' ', COLS);
2019-01-27 12:12:49 +01:00
mvaddch(LINES-1, 0, "\\|/-"[(pass++)%4]);
2019-01-24 01:20:39 +01:00
mvaddstr(LINES-1, 2, txt);
2019-01-22 15:24:49 +01:00
standend();
refresh();
return 0;
}
2019-01-10 01:44:47 +01:00
/* ---------------------------------------------------------------- */
void barre_inverse(char c, int ligne)
{
int foo;
standout();
for (foo=0; foo<COLS; foo++)
mvaddch(ligne, foo, c);
standend();
/* refresh(); */
}
/* ---------------------------------------------------------------- */
2019-01-30 16:44:43 +01:00
/* make display on the standard screen (stdscr) */
2019-01-10 14:07:56 +01:00
int fond_ecran(char *title)
2019-01-10 01:44:47 +01:00
{
2019-01-27 12:12:49 +01:00
char *tp;
struct utsname utsn;
int foo;
char buffer[200];
2019-01-10 01:44:47 +01:00
2019-01-30 16:44:43 +01:00
tp = " DD2 Monitoring by tTh 2019 ";
2019-01-10 14:07:56 +01:00
if (NULL != title) tp = title;
barre_inverse(' ', 0);
2019-01-10 01:44:47 +01:00
standout();
2019-01-10 14:07:56 +01:00
mvaddstr(0, 2, tp);
2019-01-27 12:12:49 +01:00
if (verbosity) {
2019-01-30 16:44:43 +01:00
sprintf(buffer, " ecr: %dx%d ", COLS, LINES);
fprintf(stderr, "%s ==> %s\n", __func__, buffer);
2019-01-27 12:12:49 +01:00
foo = strlen(buffer);
mvaddstr(0, COLS-2-foo, buffer);
}
/* get and display hostname */
foo = uname(&utsn);
if ( !foo ) {
mvaddstr(0, 2+strlen(tp), "on");
mvaddstr(0, 5+strlen(tp), utsn.nodename);
}
2019-01-10 01:44:47 +01:00
standend();
refresh();
return 0;
}
/* ---------------------------------------------------------------- */