extract banner code into banner.{ch} #2134

pull/2148/head
nick black 3 years ago
parent 0be7412376
commit 335f47afe8
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -0,0 +1,81 @@
#include <zlib.h>
#include "internal.h"
// only invoked without suppress banners flag. prints various warnings based on
// the environment / terminal definition. returns the number of lines printed.
static int
init_banner_warnings(const notcurses* nc, fbuf* f){
term_fg_palindex(nc, f, nc->tcache.caps.colors <= 88 ? 1 : 0xcb);
if(!notcurses_canutf8(nc)){
fbuf_puts(f, " Warning! Encoding is not UTF-8; output may be degraded.\n");
}
if(!get_escape(&nc->tcache, ESCAPE_HPA)){
fbuf_puts(f, " Warning! No absolute horizontal placement.\n");
}
return 0;
}
// unless the suppress_banner flag was set, print some version information and
// (if applicable) warnings to ttyfp. we are not yet on the alternate screen.
int init_banner(const notcurses* nc, fbuf* f){
if(!nc->suppress_banner){
term_fg_palindex(nc, f, 50 % nc->tcache.caps.colors);
fbuf_printf(f, "notcurses %s on %s %s\n", notcurses_version(),
nc->tcache.termname ? nc->tcache.termname : "?",
nc->tcache.termversion ? nc->tcache.termversion : "");
term_fg_palindex(nc, f, nc->tcache.caps.colors <= 256 ?
14 % nc->tcache.caps.colors : 0x2080e0);
if(nc->tcache.cellpixy && nc->tcache.cellpixx){
fbuf_printf(f, "%d rows (%dpx) %d cols (%dpx) %dx%d ",
nc->stdplane->leny, nc->tcache.cellpixy,
nc->stdplane->lenx, nc->tcache.cellpixx,
nc->stdplane->leny * nc->tcache.cellpixy,
nc->stdplane->lenx * nc->tcache.cellpixx);
}else{
fbuf_printf(f, "%d rows %d cols ",
nc->stdplane->leny, nc->stdplane->lenx);
}
if(nc->tcache.caps.rgb && get_escape(&nc->tcache, ESCAPE_SETAF)){
term_fg_rgb8(&nc->tcache, f, 0xe0, 0x60, 0x60);
fbuf_putc(f, 'r');
term_fg_rgb8(&nc->tcache, f, 0x60, 0xe0, 0x60);
fbuf_putc(f, 'g');
term_fg_rgb8(&nc->tcache, f, 0x20, 0x80, 0xff);
fbuf_putc(f, 'b');
term_fg_palindex(nc, f, nc->tcache.caps.colors <= 256 ?
14 % nc->tcache.caps.colors : 0x2080e0);
fbuf_putc(f, '+');
}
fbuf_printf(f, "%u colors\n%s%s (%s)\nterminfo from %s zlib %s GPM %s\n",
nc->tcache.caps.colors,
#ifdef __clang__
"", // name is contained in __VERSION__
#else
#ifdef __GNUC__
"gcc-",
#else
#error "Unknown compiler"
#endif
#endif
__VERSION__,
#ifdef __BYTE_ORDER__
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
"LE",
#else
"BE",
#endif
#else
#error "No __BYTE_ORDER__ definition"
#endif
curses_version(), zlibVersion(), gpm_version());
ncvisual_printbanner(f);
init_banner_warnings(nc, f);
const char* esc;
if( (esc = get_escape(&nc->tcache, ESCAPE_SGR0)) ||
(esc = get_escape(&nc->tcache, ESCAPE_OP))){
fbuf_emit(f, esc);
}
}
return 0;
}

@ -0,0 +1,17 @@
#ifndef NOTCURSES_BANNER
#define NOTCURSES_BANNER
#ifdef __cplusplus
extern "C" {
#endif
struct fbuf;
struct notcurses;
int init_banner(const struct notcurses* nc, struct fbuf* f);
#ifdef __cplusplus
}
#endif
#endif

@ -1,5 +1,5 @@
#ifndef NOTCURSES_PNG
#define NOTCURSES_PNG
#ifndef NOTCURSES_BASE64
#define NOTCURSES_BASE64
#ifdef __cplusplus
extern "C" {

@ -3,7 +3,6 @@
#include "version.h"
#include "egcpool.h"
#include "internal.h"
#include <zlib.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
@ -18,6 +17,7 @@
#include <inttypes.h>
#include <notcurses/direct.h>
#include "compat/compat.h"
#include "banner.h"
#define ESC "\x1b"
@ -923,85 +923,6 @@ int ncplane_destroy_family(ncplane *ncp){
return ret;
}
// only invoked without suppress banners flag. prints various warnings based on
// the environment / terminal definition. returns the number of lines printed.
static int
init_banner_warnings(const notcurses* nc, fbuf* f){
term_fg_palindex(nc, f, nc->tcache.caps.colors <= 88 ? 1 : 0xcb);
if(!notcurses_canutf8(nc)){
fbuf_puts(f, " Warning! Encoding is not UTF-8; output may be degraded.\n");
}
if(!get_escape(&nc->tcache, ESCAPE_HPA)){
fbuf_puts(f, " Warning! No absolute horizontal placement.\n");
}
return 0;
}
// unless the suppress_banner flag was set, print some version information and
// (if applicable) warnings to ttyfp. we are not yet on the alternate screen.
static int
init_banner(const notcurses* nc, fbuf* f){
if(!nc->suppress_banner){
term_fg_palindex(nc, f, 50 % nc->tcache.caps.colors);
fbuf_printf(f, "notcurses %s on %s %s\n", notcurses_version(),
nc->tcache.termname ? nc->tcache.termname : "?",
nc->tcache.termversion ? nc->tcache.termversion : "");
term_fg_palindex(nc, f, nc->tcache.caps.colors <= 256 ?
14 % nc->tcache.caps.colors : 0x2080e0);
if(nc->tcache.cellpixy && nc->tcache.cellpixx){
fbuf_printf(f, "%d rows (%dpx) %d cols (%dpx) %dx%d ",
nc->stdplane->leny, nc->tcache.cellpixy,
nc->stdplane->lenx, nc->tcache.cellpixx,
nc->stdplane->leny * nc->tcache.cellpixy,
nc->stdplane->lenx * nc->tcache.cellpixx);
}else{
fbuf_printf(f, "%d rows %d cols ",
nc->stdplane->leny, nc->stdplane->lenx);
}
if(nc->tcache.caps.rgb && get_escape(&nc->tcache, ESCAPE_SETAF)){
term_fg_rgb8(&nc->tcache, f, 0xe0, 0x60, 0x60);
fbuf_putc(f, 'r');
term_fg_rgb8(&nc->tcache, f, 0x60, 0xe0, 0x60);
fbuf_putc(f, 'g');
term_fg_rgb8(&nc->tcache, f, 0x20, 0x80, 0xff);
fbuf_putc(f, 'b');
term_fg_palindex(nc, f, nc->tcache.caps.colors <= 256 ?
14 % nc->tcache.caps.colors : 0x2080e0);
fbuf_putc(f, '+');
}
fbuf_printf(f, "%u colors\n%s%s (%s)\nterminfo from %s zlib %s GPM %s\n",
nc->tcache.caps.colors,
#ifdef __clang__
"", // name is contained in __VERSION__
#else
#ifdef __GNUC__
"gcc-",
#else
#error "Unknown compiler"
#endif
#endif
__VERSION__,
#ifdef __BYTE_ORDER__
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
"LE",
#else
"BE",
#endif
#else
#error "No __BYTE_ORDER__ definition"
#endif
curses_version(), zlibVersion(), gpm_version());
ncvisual_printbanner(f);
init_banner_warnings(nc, f);
const char* esc;
if( (esc = get_escape(&nc->tcache, ESCAPE_SGR0)) ||
(esc = get_escape(&nc->tcache, ESCAPE_OP))){
fbuf_emit(f, esc);
}
}
return 0;
}
// it's critical that we're using UTF-8 encoding if at all possible. since the
// client might not have called setlocale(2) (if they weren't reading the
// directions...), go ahead and try calling setlocale(LC_ALL, "") and then

Loading…
Cancel
Save