demo: introduce -d delay param, use everywhere

pull/74/head
nick black 5 years ago committed by Nick Black
parent c7cf4b1c9b
commit 222c532c77

@ -53,6 +53,6 @@ int box_demo(struct notcurses* nc){
if(notcurses_render(nc)){
return -1;
}
sleep(1);
nanosleep(&demodelay, NULL);
return 0;
}

@ -8,12 +8,18 @@
#include <notcurses.h>
#include "demo.h"
struct timespec demodelay = {
.tv_sec = 1,
.tv_nsec = 0,
};
static void
usage(const char* exe, int status){
FILE* out = status == EXIT_SUCCESS ? stdout : stderr;
fprintf(out, "usage: %s [ -h | -k ]\n", exe);
fprintf(out, "usage: %s [ -h ] [ -k ] [ -d ns ]\n", exe);
fprintf(out, " h: this message\n");
fprintf(out, " k: keep screen; do not switch to alternate\n");
fprintf(out, " d: delay in nanoseconds between demos\n");
exit(status);
}
@ -45,7 +51,7 @@ handle_opts(int argc, char** argv, notcurses_options* opts){
int c;
memset(opts, 0, sizeof(*opts));
opts->outfp = stdout;
while((c = getopt(argc, argv, "hk")) != EOF){
while((c = getopt(argc, argv, "hkd:")) != EOF){
switch(c){
case 'h':
usage(*argv, EXIT_SUCCESS);
@ -53,7 +59,16 @@ handle_opts(int argc, char** argv, notcurses_options* opts){
case 'k':
opts->inhibit_alternate_screen = true;
break;
default:
case 'd':{
char* eptr;
unsigned long ns = strtoul(optarg, &eptr, 0);
if(*eptr){
usage(*argv, EXIT_FAILURE);
}
demodelay.tv_sec = ns / 1000000000;
demodelay.tv_nsec = ns % 1000000000;
break;
}default:
usage(*argv, EXIT_FAILURE);
}
}
@ -79,7 +94,7 @@ int main(int argc, char** argv){
fprintf(stderr, "Couldn't get standard plane\n");
goto err;
}
sleep(1);
nanosleep(&demodelay, NULL);
int x, y, rows, cols;
ncplane_dimyx(ncp, &rows, &cols);
cell c;
@ -127,10 +142,6 @@ int main(int argc, char** argv){
if(ncplane_box(ncp, &ul, &ur, &ll, &lr, &hl, &vl, rows - 6, cols - 6)){
goto err;
}
if(notcurses_render(nc)){
goto err;
}
sleep(1);
const char s1[] = " Die Welt ist alles, was der Fall ist. ";
const char str[] = " Wovon man nicht sprechen kann, darüber muss man schweigen. ";
if(ncplane_fg_rgb8(ncp, 192, 192, 192)){
@ -167,7 +178,7 @@ int main(int argc, char** argv){
if(notcurses_render(nc)){
goto err;
}
sleep(1);
nanosleep(&demodelay, NULL);
if(ext_demos(nc)){
goto err;
}

@ -1,12 +1,16 @@
#ifndef NOTCURSES_DEMO
#define NOTCURSES_DEMO
#include <time.h>
#include <notcurses.h>
#ifdef __cplusplus
extern "C" {
#endif
// configured via command line option -- the base number of ns between demos
extern struct timespec demodelay;
#define FADE_MILLISECONDS 500
int unicodeblocks_demo(struct notcurses* nc);

@ -131,8 +131,8 @@ gridswitch_demo(struct notcurses* nc, struct ncplane *n){
// render!
notcurses_render(nc);
sleep(1);
release_cells(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
nanosleep(&demodelay, NULL);
return 0;
}
@ -196,8 +196,8 @@ gridinv_demo(struct notcurses* nc, struct ncplane *n){
// render!
notcurses_render(nc);
sleep(1);
release_cells(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
nanosleep(&demodelay, NULL);
return gridswitch_demo(nc, n);
}
@ -262,7 +262,7 @@ int grid_demo(struct notcurses* nc){
// render!
notcurses_render(nc);
sleep(1);
release_cells(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
nanosleep(&demodelay, NULL);
return gridinv_demo(nc, n);
}

@ -82,12 +82,12 @@ int maxcolor_demo(struct notcurses* nc){
if(notcurses_render(nc)){
return -1;
}
sleep(2);
cell_release(n, &ul);
cell_release(n, &ur);
cell_release(n, &ll);
cell_release(n, &lr);
cell_release(n, &vl);
cell_release(n, &hl);
nanosleep(&demodelay, NULL);
return 0;
}

@ -40,6 +40,7 @@ int sliding_puzzle_demo(struct notcurses* nc){
}
}
}
nanosleep(&demodelay, NULL);
ret = 0;
done:

@ -66,6 +66,13 @@ int unicodeblocks_demo(struct notcurses* nc){
if(ncplane_rounded_box_cells(n, &ul, &ur, &ll, &lr, &hl, &vl)){
return -1;
}
// we don't want a full delay period for each one, urk
struct timespec subdelay;
uint64_t nstotal = demodelay.tv_sec * 1000000000 + demodelay.tv_nsec;
nstotal /= 10;
subdelay.tv_sec = nstotal / 1000000000;
subdelay.tv_nsec = nstotal % 1000000000;
fprintf(stderr, "SUBDELAY: %lu %lu\n", subdelay.tv_sec, subdelay.tv_nsec);
for(sindex = 0 ; sindex < sizeof(blocks) / sizeof(*blocks) ; ++sindex){
uint32_t blockstart = blocks[sindex].start;
const char* description = blocks[sindex].name;
@ -149,9 +156,9 @@ int unicodeblocks_demo(struct notcurses* nc){
if(notcurses_render(nc)){
return -1;
}
usleep(100000);
nanosleep(&subdelay, NULL);
// for a 32-bit wchar_t, we would want up through 24 bits of block ID. but
// really, the vast majority of space is unused. cap at 0x3000.
// really, the vast majority of space is unused.
blockstart += BLOCKSIZE;
}
return 0;

@ -316,7 +316,7 @@ int widecolor_demo(struct notcurses* nc){
key = wgetch(w);
}while(key == ERR);
*/
sleep(1); // FIXME
nanosleep(&demodelay, NULL);
//}while(key == KEY_RESIZE);
}
return 0;

Loading…
Cancel
Save