DD2-monitor/viz/curses/ecran.c

77 lines
1.5 KiB
C
Raw Normal View History

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