From b3c6f9232a02b7dc2c5f90fd39923c6adccdf666 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 29 Nov 2019 04:05:40 -0500 Subject: [PATCH] add renderfp option to render to a file --- include/notcurses.h | 3 +++ src/lib/notcurses.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/notcurses.h b/include/notcurses.h index ccc75b6ee..75669d238 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -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. diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index fef595eb5..3a3d59be1 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -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);