boilerplate for ncurses interface

This commit is contained in:
tth 2019-01-10 01:44:47 +01:00
parent 7e376763b8
commit 6fe2c54cfb
7 changed files with 232 additions and 0 deletions

21
viz/curses/7segments.c Normal file
View File

@ -0,0 +1,21 @@
/*
* DD2 Monitoring
*
* ncurses seven segment display
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
int verbosity;
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */

21
viz/curses/Makefile Normal file
View File

@ -0,0 +1,21 @@
# --------------- ***
ecran.o: ecran.c Makefile ecran.h
gcc -Wall -c $<
7segments.o: 7segments.c Makefile
gcc -Wall -c $<
waterfall.o: waterfall.c Makefile
gcc -Wall -c $<
# --------------- ***
OBJ = ecran.o waterfall.o 7segments.o
t: t.c Makefile $(OBJ) ecran.h
gcc -Wall $< $(OBJ) -lncurses -o $@
# --------------- ***

2
viz/curses/README.md Normal file
View File

@ -0,0 +1,2 @@
# Dataviz with AsciiArt

50
viz/curses/ecran.c Normal file
View File

@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
int verbosity;
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
void barre_inverse(char c, int ligne)
{
int foo;
standout();
for (foo=0; foo<COLS; foo++)
mvaddch(ligne, foo, c);
standend();
/* refresh(); */
}
/* ---------------------------------------------------------------- */
int fond_ecran(void)
{
#if TRACE
int foo;
char buffer[200];
#endif
barre_inverse('+', 0);
standout();
mvaddstr(0, 2, " DD2 MONITORING by tTh 2019 ");
#if TRACE
sprintf(buffer, " ecran %dx%d ", COLS, LINES);
foo = strlen(buffer);
mvaddstr(0, COLS-2-foo, buffer);
#endif
standend();
refresh();
#if TRACE
fprintf(stderr, "HAUT %3d\n", HAUT);
fprintf(stderr, "HAUT_1 %3d BARRE_1 %3d\n", HAUT_1, BARRE_1);
fprintf(stderr, "HAUT_2 %3d BARRE_2 %3d\n", HAUT_2, BARRE_2);
#endif
return 0;
}
/* ---------------------------------------------------------------- */

6
viz/curses/ecran.h Normal file
View File

@ -0,0 +1,6 @@
int fond_ecran(void);
WINDOW * open_waterfall(char *title, int flags);

73
viz/curses/t.c Normal file
View File

@ -0,0 +1,73 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
int verbosity;
/* ---------------------------------------------------------------- */
void demo(int nbl, int k)
{
int loop;
char line[100];
WINDOW *water;
water = open_waterfall("premier essai", 0);
for (loop=0; loop<nbl; loop++) {
sprintf(line, "%04X %04X", loop, rand()&0xffff);
mvaddstr(5, 5, line);
sleep(1);
refresh();
}
}
/* ---------------------------------------------------------------- */
static void finish(int signal)
{
endwin(); exit(0);
}
/* ---------------------------------------------------------------- */
int main (int argc, char *argv[])
{
int opt;
/* set some default values */
verbosity = 0;
while ((opt = getopt(argc, argv, "v")) != -1) {
switch (opt) {
case 'v': verbosity++; break;
default:
fprintf(stderr, "%s : uh ?", argv[0]);
exit(1);
break;
}
}
initscr();
nonl(); cbreak(); noecho();
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
fond_ecran();
demo(1024, 0);
/*
* plop, on a fini, restaurer la console
*/
finish(0);
return 0;
}
/* ---------------------------------------------------------------- */

59
viz/curses/waterfall.c Normal file
View File

@ -0,0 +1,59 @@
/*
* DD2 Monitoring
*
* ncurses waterfall interface
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
extern int verbosity;
/* ---------------------------------------------------------------- */
WINDOW *open_waterfall(char *title, int flags)
{
WINDOW *win;
int l, c, w, h;
l = 2; c = 1;
w = COLS - 2; h = LINES -3;
win = newwin(h, w, l, c);
return win;
}
/* ---------------------------------------------------------------- */
int plot_waterfall(WINDOW *wf, float values[4])
{
#define TL 1000
int foo;
char tag, ligne[TL+1];
for(foo=0; foo<TL; foo++) *(ligne+foo) = '-';
for(foo=0; foo<4; foo++) {
tag = "ATOX"[foo];
}
return -1;
}
/* ---------------------------------------------------------------- */
int close_waterfall(WINDOW *wf, int notused)
{
if (NULL == wf) {
fprintf(stderr, "%s wf is null\n", __func__);
return -1;
}
return 0;
}
/* ---------------------------------------------------------------- */