DD2-monitor/viz/curses/ecran.c

111 lines
2.1 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-05-22 09:50:25 +02:00
/* ---------------------------------------------------------------- */
void bordure(WINDOW * w, char *texte, int type)
{
if (type)
box(w, 0, 0);
else
wborder(w, '|', '|', '-', '-', '+', '+', '+', '+');
wstandout(w); mvwaddstr(w, 0, 3, texte); wstandend(w);
wrefresh(w);
}
2019-05-13 17:48:58 +02:00
/* ---------------------------------------------------------------- */
int kbhit(void)
{
int r, ch;
nodelay(stdscr, TRUE);
noecho();
// check for input
ch = getch();
if( ch == ERR) { // no input
r = FALSE;
}
else { // input
r = TRUE;
ungetch(ch);
}
2019-05-22 09:50:25 +02:00
// restore block and echo
2019-05-13 17:48:58 +02:00
echo();
nodelay(stdscr, FALSE);
return r;
}
2019-01-10 01:44:47 +01:00
/* ---------------------------------------------------------------- */
2019-05-14 15:18:03 +02:00
int aff_message(char *txt)
2019-01-22 15:24:49 +01:00
{
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;
}
/* ---------------------------------------------------------------- */