notcurses-demo: accept -p to find data files #160

pull/193/head
nick black 5 years ago
parent db89e71595
commit 792b1f2cfb
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -3,12 +3,16 @@
notcurses-demo \- Show off some notcurses features
.SH SYNOPSIS
.B notcurses-demo
[ \fB\-p \fIpath \fR]
[ \fB\-d \fIdelaymult \fR]
[ \fB\-k \fR]
[ \fB\-h / \fB\-\-help \fR]
.IR demospec
.SH OPTIONS
.TP
.BR \-p \fIpath\fR
Look in the specified path for data files.
.TP
.BR \-d \fIdelaymult\fR
Apply a (floating-point) multiplier to the standard delay of 1s.
.TP
@ -27,6 +31,8 @@ contains a set of text-based demonstrations of capabilities from the notcurses l
.P
(i)ntro—a setting of tone
.P
(e)agle—zoom in on a background from Ninja Gaiden
.P
(m)axcolors—smoothly changing colors
.P
(l)uigi-a dashing plumber of Apennine persuasion

@ -1,6 +1,7 @@
#include <time.h>
#include <wchar.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
@ -10,6 +11,15 @@
#include "demo.h"
static const char DEFAULT_DEMO[] = "iemlubgswvpo";
static char datadir[PATH_MAX] = "/usr/share/notcurses"; // FIXME
char* find_data(const char* datum){
char* path = malloc(strlen(datadir) + 1 + strlen(datum));
strcpy(path, datadir);
strcat(path, "/");
strcat(path, datum);
return path;
}
int timespec_subtract(struct timespec *result, const struct timespec *time0,
struct timespec *time1){
@ -200,7 +210,7 @@ static const char*
handle_opts(int argc, char** argv, notcurses_options* opts){
int c;
memset(opts, 0, sizeof(*opts));
while((c = getopt(argc, argv, "hkd:f:")) != EOF){
while((c = getopt(argc, argv, "hkd:f:p:")) != EOF){
switch(c){
case 'h':
usage(*argv, EXIT_SUCCESS);
@ -217,6 +227,9 @@ handle_opts(int argc, char** argv, notcurses_options* opts){
usage(*argv, EXIT_FAILURE);
}
break;
case 'p':
strcpy(datadir, optarg);
break;
case 'd':{
float f;
if(sscanf(optarg, "%f", &f) != 1){
@ -272,6 +285,10 @@ int main(int argc, char** argv){
return EXIT_FAILURE;
}
for(size_t i = 0 ; i < strlen(demos) ; ++i){
if(!results[i].selector){
printf(" Error running last demo. Did you need provide -p?\n");
break;
}
printf("%2zu|%c|%2lu.%03lus|%4lu|\n", i, results[i].selector,
results[i].timens / GIG,
(results[i].timens % GIG) / 1000000,

@ -2,6 +2,7 @@
#define NOTCURSES_DEMO
#include <time.h>
#include <limits.h>
#include <notcurses.h>
#ifdef __cplusplus
@ -11,6 +12,9 @@ extern "C" {
// configured via command line option -- the base number of ns between demos
extern struct timespec demodelay;
// heap-allocated, caller must free. locates data files per command line args.
char* find_data(const char* datum);
int unicodeblocks_demo(struct notcurses* nc);
int widechomper_demo(struct notcurses* nc);
int box_demo(struct notcurses* nc);

@ -92,14 +92,17 @@ zoom_map(struct notcurses* nc, const char* map){
// motherfucking eagles!
int eagle_demo(struct notcurses* nc){
const char* map = "../tests/eagles.png";
char* map = find_data("eagles.png");
struct ncvisual* zo;
if((zo = outzoomed_map(nc, map)) == NULL){
free(map);
return -1;
}
ncvisual_destroy(zo);
if(zoom_map(nc, map)){
free(map);
return -1;
}
free(map);
return 0;
}

Loading…
Cancel
Save