From 2eb3bc1f8854cb7e20e6628556df31cf48d9c4ee Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 2 Mar 2021 01:55:52 -0500 Subject: [PATCH] get cell size in pixels, include in banner #1368 --- TERMINALS.md | 4 ++-- src/lib/direct.cpp | 4 ++-- src/lib/internal.h | 9 +++++++-- src/lib/notcurses.c | 36 ++++++++++++++++++++++++------------ src/lib/render.c | 2 +- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/TERMINALS.md b/TERMINALS.md index 224d990ee..4d21bd737 100644 --- a/TERMINALS.md +++ b/TERMINALS.md @@ -18,14 +18,14 @@ relies on the font. Patches to correct/complete this table are very welcome! | Terminal | Pixel `TIOCGWINSZ` | `ccc` | Blocks | Recommended environment | Notes | | --------------- | ------------------ | ----- | ------------------------------- | ----- | | Alacritty | ✅ | ✅ |❌ |`TERM=alacritty` `COLORTERM=24bit` | | -| FBterm | | ? |? |`TERM=fbterm` | 256 colors, no RGB color. | +| FBterm | ❌ | ? |? |`TERM=fbterm` | 256 colors, no RGB color. | | Gnome Terminal | | ❌ |✅ |`TERM=gnome` `COLORTERM=24bit` | `ccc` support *is* available when run with `vte-256color`. | | Guake | | ? |? | | | | ITerm2 | | ? |? | | | | Kitty | ✅ | ✅ |✅ |`TERM=xterm-kitty` | | | kmscon | | ? |? |`TERM=xterm-256color` | No RGB color AFAICT, nor any distinct terminfo entry. | | Konsole | ❌ | ❌ |? |`TERM=konsole-direct` | | -| Linux console | | ✅ |see [below](#the-linux-console) |`TERM=linux` `COLORTERM=24bit` | 8 (512 glyph fonts) or 16 (256 glyph fonts) colors max, but RGB values are downsampled to a 256-index palette. See below. | +| Linux console | ❌ | ✅ |see [below](#the-linux-console) |`TERM=linux` `COLORTERM=24bit` | 8 (512 glyph fonts) or 16 (256 glyph fonts) colors max, but RGB values are downsampled to a 256-index palette. See below. | | mlterm | ✅ | ❌ |? |`TERM=mlterm-256color` | Do not set `COLORTERM`. `mlterm-direct` gives strange results. | | PuTTY | | ❌ |❌ |`TERM=putty-256color` `COLORTERM=24bit` | | | rxvt | | ? |? | | | diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index c12093617..607c628e7 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -86,7 +86,7 @@ int ncdirect_clear(ncdirect* nc){ int ncdirect_dim_x(const ncdirect* nc){ int x; if(nc->ctermfd >= 0){ - if(update_term_dimensions(nc->ctermfd, nullptr, &x) == 0){ + if(update_term_dimensions(nc->ctermfd, nullptr, &x, NULL) == 0){ return x; } }else{ @@ -98,7 +98,7 @@ int ncdirect_dim_x(const ncdirect* nc){ int ncdirect_dim_y(const ncdirect* nc){ int y; if(nc->ctermfd >= 0){ - if(update_term_dimensions(nc->ctermfd, &y, nullptr) == 0){ + if(update_term_dimensions(nc->ctermfd, &y, nullptr, NULL) == 0){ return y; } }else{ diff --git a/src/lib/internal.h b/src/lib/internal.h index 2a61458c8..5b25bbe56 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -279,6 +279,11 @@ typedef struct tinfo { bool AMflag; // "AM" flag for automatic movement to next line bool utf8; // are we using utf-8 encoding, as hoped? + // we use the cell's size in pixels for pixel blitting. this information can + // be acquired on all terminals with pixel support. + int cellpixy; // cell pixel height, might be 0 + int cellpixx; // cell pixel width, might be 0 + // kitty interprets an RGB background that matches the default background // color *as* the default background, meaning it'll be translucent if // background_opaque is in use. detect this, and avoid the default if so. @@ -355,7 +360,7 @@ typedef struct notcurses { int cursory; // desired cursor placement according to user. int cursorx; // -1 is don't-care, otherwise moved here after each render. - pthread_mutex_t statlock; + pthread_mutex_t statlock; // FIXME align on cacheline ncstats stats; // some statistics across the lifetime of the notcurses ctx ncstats stashed_stats; // retain across a notcurses_stats_reset(), to print in closing banner @@ -685,7 +690,7 @@ int ncplane_resize_internal(ncplane* n, int keepy, int keepx, int keepleny, int keeplenx, int yoff, int xoff, int ylen, int xlen); -int update_term_dimensions(int fd, int* rows, int* cols); +int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache); ALLOC static inline void* memdup(const void* src, size_t len){ diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 8f811aa41..fba367da1 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -180,7 +180,7 @@ void ncplane_dim_yx(const ncplane* n, int* rows, int* cols){ // anyone calling this needs ensure the ncplane's framebuffer is updated // to reflect changes in geometry. also called at startup for standard plane. -int update_term_dimensions(int fd, int* rows, int* cols){ +int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache){ // if we're not a real tty, we presumably haven't changed geometry, return if(fd < 0){ *rows = DEFAULT_ROWS; @@ -204,6 +204,10 @@ int update_term_dimensions(int fd, int* rows, int* cols){ if(cols){ *cols = ws.ws_col; } + if(tcache){ + tcache->cellpixy = ws.ws_row ? ws.ws_ypixel / ws.ws_row : 0; + tcache->cellpixx = ws.ws_col ? ws.ws_xpixel / ws.ws_col : 0; + } return 0; } @@ -812,12 +816,20 @@ init_banner(const notcurses* nc){ term_fg_palindex(nc, stdout, nc->tcache.colors <= 256 ? 50 % nc->tcache.colors : 0x20e080); printf("\n notcurses %s by nick black et al", notcurses_version()); term_fg_palindex(nc, stdout, nc->tcache.colors <= 256 ? 12 % nc->tcache.colors : 0x2080e0); - printf("\n %d rows %d cols (%sB) %zuB cells %d colors%s\n" - " compiled with gcc-%s, %s-endian\n" + if(nc->tcache.cellpixy && nc->tcache.cellpixx){ + printf("\n %d rows (%dpx) %d cols (%dpx) (%sB) %zuB cells %d colors%s\n", + nc->stdplane->leny, nc->tcache.cellpixy, + nc->stdplane->lenx, nc->tcache.cellpixx, + bprefix(nc->stats.fbbytes, 1, prefixbuf, 0), sizeof(nccell), + nc->tcache.colors, nc->tcache.RGBflag ? "+RGB" : ""); + }else{ + printf("\n %d rows %d cols (%sB) %zuB cells %d colors%s\n", + nc->stdplane->leny, nc->stdplane->lenx, + bprefix(nc->stats.fbbytes, 1, prefixbuf, 0), sizeof(nccell), + nc->tcache.colors, nc->tcache.RGBflag ? "+RGB" : ""); + } + printf(" compiled with gcc-%s, %s-endian\n" " terminfo from %s\n", - nc->stdplane->leny, nc->stdplane->lenx, - bprefix(nc->stats.fbbytes, 1, prefixbuf, 0), sizeof(nccell), - nc->tcache.colors, nc->tcache.RGBflag ? "+RGB" : "", __VERSION__, #ifdef __BYTE_ORDER__ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ @@ -1047,21 +1059,21 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ fprintf(stderr, "Terminfo error %d (see terminfo(3ncurses))\n", termerr); goto err; } + const char* shortname_term = termname(); + const char* longname_term = longname(); + if(interrogate_terminfo(&ret->tcache, shortname_term, utf8)){ + goto err; + } int dimy, dimx; - if(update_term_dimensions(ret->ttyfd, &dimy, &dimx)){ + if(update_term_dimensions(ret->ttyfd, &dimy, &dimx, &ret->tcache)){ goto err; } ret->suppress_banner = opts->flags & NCOPTION_SUPPRESS_BANNERS; - char* shortname_term = termname(); - char* longname_term = longname(); if(!ret->suppress_banner){ fprintf(stderr, "Term: %dx%d %s (%s)\n", dimy, dimx, shortname_term ? shortname_term : "?", longname_term ? longname_term : "?"); } - if(interrogate_terminfo(&ret->tcache, shortname_term, utf8)){ - goto err; - } if(ncinputlayer_init(&ret->input, stdin)){ goto err; } diff --git a/src/lib/render.c b/src/lib/render.c index 17fb5a3a4..ae02bd438 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -23,7 +23,7 @@ notcurses_resize_internal(ncplane* pp, int* restrict rows, int* restrict cols){ int oldcols = pile->dimx; *rows = oldrows; *cols = oldcols; - if(update_term_dimensions(n->ttyfd, rows, cols)){ + if(update_term_dimensions(n->ttyfd, rows, cols, &n->tcache)){ return -1; } *rows -= n->margin_t + n->margin_b;