From 2190d3eaf0acd242ef5795f992053fa416da0e67 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 21 Feb 2021 12:36:20 -0500 Subject: [PATCH] extract init_banner_warnings() factor init_banner_warnings() out of init_banner(). check the output FILE for ttyness, and only emit control sequences when it is indeed a tty. this eliminates some control sequences that were being dumped when stderr was redirected. --- src/lib/notcurses.c | 48 ++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index bc5fdb3b2..4a0feaced 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -739,6 +739,35 @@ void notcurses_stats_reset(notcurses* nc, ncstats* stats){ pthread_mutex_unlock(&nc->statlock); } +// only invoked without suppress banners flag. prints various warnings based on +// the environment / terminal definition. +static void +init_banner_warnings(const notcurses* nc, FILE* out){ + const bool tty = isatty(fileno(out)); + if(tty){ + term_fg_palindex(nc, out, nc->tcache.colors <= 88 ? 1 % nc->tcache.colors : 0xcb); + } + if(!nc->tcache.RGBflag){ // FIXME + fprintf(out, "\n Warning! Colors subject to https://github.com/dankamongmen/notcurses/issues/4"); + fprintf(out, "\n Specify a (correct) TrueColor TERM, or COLORTERM=24bit.\n"); + }else{ + if(!nc->tcache.CCCflag){ + fprintf(out, "\n Warning! Advertised TrueColor but no 'ccc' flag\n"); + } + } + if(!notcurses_canutf8(nc)){ + fprintf(out, "\n Warning! Encoding is not UTF-8; output may be degraded.\n"); + } + if(!nc->tcache.hpa){ + fprintf(out, "\n Warning! No absolute horizontal placement.\n"); + } + if(nc->tcache.sgr0){ + if(tty){ + term_emit(nc->tcache.sgr0, out, true); + } + } +} + // unless the suppress_banner flag was set, print some version information and // (if applicable) warnings to stdout. we are not yet on the alternate screen. static void @@ -767,24 +796,7 @@ init_banner(const notcurses* nc){ , curses_version()); ncvisual_printbanner(nc); fflush(stdout); - term_fg_palindex(nc, stderr, nc->tcache.colors <= 88 ? 1 % nc->tcache.colors : 0xcb); - if(!nc->tcache.RGBflag){ // FIXME - fprintf(stderr, "\n Warning! Colors subject to https://github.com/dankamongmen/notcurses/issues/4"); - fprintf(stderr, "\n Specify a (correct) TrueColor TERM, or COLORTERM=24bit.\n"); - }else{ - if(!nc->tcache.CCCflag){ - fprintf(stderr, "\n Warning! Advertised TrueColor but no 'ccc' flag\n"); - } - } - if(!notcurses_canutf8(nc)){ - fprintf(stderr, "\n Warning! Encoding is not UTF-8; output may be degraded.\n"); - } - if(!nc->tcache.hpa){ - fprintf(stderr, "\n Warning! No absolute horizontal placement.\n"); - } - if(nc->tcache.sgr0){ - term_emit(nc->tcache.sgr0, stderr, true); - } + init_banner_warnings(nc, stderr); } }