mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
get cell size in pixels, include in banner #1368
This commit is contained in:
parent
f86b4cdc8c
commit
2eb3bc1f88
@ -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 | | ? |? | | |
|
||||
|
@ -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{
|
||||
|
@ -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){
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user