add renderfp option to render to a file

This commit is contained in:
nick black 2019-11-29 04:05:40 -05:00 committed by Nick Black
parent 8c6d0495ee
commit b3c6f9232a
2 changed files with 8 additions and 1 deletions

View File

@ -105,6 +105,9 @@ typedef struct notcurses_options {
// We typically install a signal handler for SIGWINCH that generates a resize
// event in the notcurses_getc() queue. Set this to inhibit the handler.
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;
// Initialize a notcurses context, corresponding to a connected terminal.

View File

@ -85,6 +85,7 @@ typedef struct notcurses {
bool RGBflag; // terminfo-reported "RGB" flag for 24bpc directcolor
ncplane* top; // the contents of our topmost plane (initially entire screen)
ncplane* stdscr;// aliases some plane from the z-buffer, covers screen
FILE* renderfp; // debugging FILE* to which renderings are written
} notcurses;
// 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;
}
ret->ttyfp = opts->outfp;
ret->renderfp = opts->renderfp;
ret->ttyinfp = stdin; // FIXME
if((ret->ttyfd = fileno(ret->ttyfp)) < 0){
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){
ret = -1;
}
// fprintf(stderr, "%s\n", buf);
if(nc->renderfp){
fprintf(nc->renderfp, "%s\n", buf);
}
clock_gettime(CLOCK_MONOTONIC, &done);
free(buf);
update_render_stats(&done, &start, &nc->stats);