Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
banner.c
Go to the documentation of this file.
1#include "internal.h"
2#include <curses.h>
3#ifdef USE_DEFLATE
4#include <libdeflate.h>
5#else
6#include <zlib.h>
7#endif
8
9// only invoked without suppress banners flag. prints various warnings based on
10// the environment / terminal definition. returns the number of lines printed.
11static int
12init_banner_warnings(const notcurses* nc, fbuf* f, const char* clreol){
13 term_fg_palindex(nc, f, nc->tcache.caps.colors <= 88 ? 1 : 0xcb);
14 if(!notcurses_canutf8(nc)){
15 fbuf_puts(f, clreol);
16 fbuf_puts(f, " Warning! Encoding is not UTF-8; output may be degraded." NL);
17 }
18 if(!get_escape(&nc->tcache, ESCAPE_HPA)){
19 fbuf_puts(f, clreol);
20 fbuf_puts(f, " Warning! No absolute horizontal placement." NL);
21 }
22 return 0;
23}
24
25// unless the suppress_banner flag was set, print some version information and
26// (if applicable) warnings to ttyfp. we are not yet on the alternate screen.
27int init_banner(const notcurses* nc, fbuf* f){
28 const char* clreol = get_escape(&nc->tcache, ESCAPE_EL);
29 if(clreol == NULL){
30 clreol = "";
31 }
33 term_fg_palindex(nc, f, 50 % nc->tcache.caps.colors);
34 char* osver = notcurses_osversion();
35 fbuf_printf(f, "%snotcurses %s on %s %s%s(%s)" NL,
36 clreol, notcurses_version(),
37 nc->tcache.termname ? nc->tcache.termname : "?",
38 nc->tcache.termversion ? nc->tcache.termversion : "",
39 nc->tcache.termversion ? " " : "", osver ? osver : "unknown");
40 free(osver);
41 term_fg_palindex(nc, f, nc->tcache.caps.colors <= 256 ?
42 14 % nc->tcache.caps.colors : 0x2080e0);
43 if(nc->tcache.cellpxy && nc->tcache.cellpxx){
44 fbuf_printf(f, "%s%d rows (%dpx) %d cols (%dpx) %dx%d ",
45 clreol,
46 nc->stdplane->leny, nc->tcache.cellpxy,
47 nc->stdplane->lenx, nc->tcache.cellpxx,
48 nc->stdplane->leny * nc->tcache.cellpxy,
49 nc->stdplane->lenx * nc->tcache.cellpxx);
50 }else{
51 fbuf_printf(f, "%d rows %d cols ",
52 nc->stdplane->leny, nc->stdplane->lenx);
53 }
54 if(nc->tcache.caps.rgb && get_escape(&nc->tcache, ESCAPE_SETAF)){
55 term_fg_rgb8(&nc->tcache, f, 0xe0, 0x60, 0x60);
56 fbuf_putc(f, 'r');
57 term_fg_rgb8(&nc->tcache, f, 0x60, 0xe0, 0x60);
58 fbuf_putc(f, 'g');
59 term_fg_rgb8(&nc->tcache, f, 0x20, 0x80, 0xff);
60 fbuf_putc(f, 'b');
61 term_fg_palindex(nc, f, nc->tcache.caps.colors <= 256 ?
62 14 % nc->tcache.caps.colors : 0x2080e0);
63 fbuf_putc(f, '+');
64 }
65 // we want the terminfo version, which is tied to ncurses
66 const char* ncursesver = curses_version();
67 const char* ncver = strchr(ncursesver, ' ');
68 ncver = ncver ? ncver + 1 : ncursesver;
69#ifdef USE_DEFLATE
70 fbuf_printf(f, "%u colors" NL "%s%s%s (%s)" NL "%sterminfo %s libdeflate %s GPM %s" NL,
71 nc->tcache.caps.colors, clreol,
72#else
73 fbuf_printf(f, "%u colors" NL "%s%s%s (%s)" NL "%sterminfo %s zlib %s GPM %s" NL,
74 nc->tcache.caps.colors, clreol,
75#endif
76#ifdef __clang__
77 "", // name is contained in __VERSION__
78#else
79#ifdef __GNUC__
80 "gcc-",
81#else
82#error "Unknown compiler"
83#endif
84#endif
85 __VERSION__,
86#ifdef __BYTE_ORDER__
87#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
88 "LE",
89#else
90 "BE",
91#endif
92#else
93#error "No __BYTE_ORDER__ definition"
94#endif
95 clreol, ncver,
96#ifdef USE_DEFLATE
97 LIBDEFLATE_VERSION_STRING,
98#else
99 ZLIB_VERSION,
100#endif
101 gpm_version());
102 fbuf_puts(f, clreol); // for ncvisual banner
104 init_banner_warnings(nc, f, clreol);
105 const char* esc;
106 if( (esc = get_escape(&nc->tcache, ESCAPE_SGR0)) ||
107 (esc = get_escape(&nc->tcache, ESCAPE_OP))){
108 fbuf_emit(f, esc);
109 }
110 }
111 return 0;
112}
113
int init_banner(const notcurses *nc, fbuf *f)
Definition banner.c:27
free(duplicated)
const char * gpm_version(void)
Definition gpm.c:95
int term_fg_rgb8(const tinfo *ti, fbuf *f, unsigned r, unsigned g, unsigned b)
Definition render.c:743
void ncvisual_printbanner(fbuf *f)
Definition visual.c:30
const char * notcurses_version(void)
Definition notcurses.c:182
#define NCOPTION_SUPPRESS_BANNERS
Definition notcurses.h:1015
Definition fbuf.h:25
unsigned colors
Definition notcurses.h:1637
unsigned lenx
Definition internal.h:86
unsigned leny
Definition internal.h:86
uint64_t flags
Definition internal.h:369
tinfo tcache
Definition internal.h:360
ncplane * stdplane
Definition internal.h:333
unsigned cellpxx
Definition termdesc.h:117
const char * termname
Definition termdesc.h:176
nccapabilities caps
Definition termdesc.h:111
char * termversion
Definition termdesc.h:177
unsigned cellpxy
Definition termdesc.h:116
return NULL
Definition termdesc.h:229
@ ESCAPE_OP
Definition termdesc.h:50
@ ESCAPE_SETAF
Definition termdesc.h:48
@ ESCAPE_HPA
Definition termdesc.h:46
@ ESCAPE_EL
Definition termdesc.h:67
@ ESCAPE_SGR0
Definition termdesc.h:53
char * notcurses_osversion(void)
Definition util.c:82