add renderfp option to render to a file

pull/85/head
nick black 5 years ago committed by Nick Black
parent 8c6d0495ee
commit b3c6f9232a

@ -105,6 +105,9 @@ typedef struct notcurses_options {
// We typically install a signal handler for SIGWINCH that generates a resize // We typically install a signal handler for SIGWINCH that generates a resize
// event in the notcurses_getc() queue. Set this to inhibit the handler. // event in the notcurses_getc() queue. Set this to inhibit the handler.
bool no_winch_sighandler; bool no_winch_sighandler;
// If non-NULL, notcurses_render() will write each rendered frame to this
// FILE* in addition to outfp. This is used primarily for debugging.
FILE* renderfp;
} notcurses_options; } notcurses_options;
// Initialize a notcurses context, corresponding to a connected terminal. // Initialize a notcurses context, corresponding to a connected terminal.

@ -85,6 +85,7 @@ typedef struct notcurses {
bool RGBflag; // terminfo-reported "RGB" flag for 24bpc directcolor bool RGBflag; // terminfo-reported "RGB" flag for 24bpc directcolor
ncplane* top; // the contents of our topmost plane (initially entire screen) ncplane* top; // the contents of our topmost plane (initially entire screen)
ncplane* stdscr;// aliases some plane from the z-buffer, covers screen ncplane* stdscr;// aliases some plane from the z-buffer, covers screen
FILE* renderfp; // debugging FILE* to which renderings are written
} notcurses; } notcurses;
// only one notcurses object can be the target of signal handlers, due to their // only one notcurses object can be the target of signal handlers, due to their
@ -578,6 +579,7 @@ notcurses* notcurses_init(const notcurses_options* opts){
return ret; return ret;
} }
ret->ttyfp = opts->outfp; ret->ttyfp = opts->outfp;
ret->renderfp = opts->renderfp;
ret->ttyinfp = stdin; // FIXME ret->ttyinfp = stdin; // FIXME
if((ret->ttyfd = fileno(ret->ttyfp)) < 0){ if((ret->ttyfd = fileno(ret->ttyfp)) < 0){
fprintf(stderr, "No file descriptor was available in opts->outfp\n"); fprintf(stderr, "No file descriptor was available in opts->outfp\n");
@ -1008,7 +1010,9 @@ int notcurses_render(notcurses* nc){
if(w < 0 || (size_t)w != buflen){ if(w < 0 || (size_t)w != buflen){
ret = -1; ret = -1;
} }
// fprintf(stderr, "%s\n", buf); if(nc->renderfp){
fprintf(nc->renderfp, "%s\n", buf);
}
clock_gettime(CLOCK_MONOTONIC, &done); clock_gettime(CLOCK_MONOTONIC, &done);
free(buf); free(buf);
update_render_stats(&done, &start, &nc->stats); update_render_stats(&done, &start, &nc->stats);

Loading…
Cancel
Save