mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
clamp sixel height in update_term_dimensions() so ncdirect gets it #1789
This commit is contained in:
parent
50a304bada
commit
534000cadb
2
NEWS.md
2
NEWS.md
@ -23,6 +23,8 @@ rearrangements of Notcurses.
|
||||
* Filled out the complete set of `ncdirect_can*()` capability functions,
|
||||
which now match the `notcurses_can*()` API. Added
|
||||
`ncdirect_canget_cursor()` to check if the cursor can be located.
|
||||
* `ncdirect_dim_y()` and `ncdirect_dim_x()` no longer accept a
|
||||
`const ncdirect*`, since they update the term parameters. Sorry!
|
||||
|
||||
* 2.3.4 (2021-06-12)
|
||||
* Added the flag `NCVISUAL_OPTION_NOINTERPOLATE` to use non-interpolative
|
||||
|
@ -172,10 +172,8 @@ ncdirect_bg_default(struct ncdirect* nc){
|
||||
}
|
||||
|
||||
// Get the current number of columns/rows.
|
||||
API int ncdirect_dim_x(const struct ncdirect* nc)
|
||||
__attribute__ ((nonnull (1)));
|
||||
API int ncdirect_dim_y(const struct ncdirect* nc)
|
||||
__attribute__ ((nonnull (1)));
|
||||
API int ncdirect_dim_x(struct ncdirect* nc) __attribute__ ((nonnull (1)));
|
||||
API int ncdirect_dim_y(struct ncdirect* nc) __attribute__ ((nonnull (1)));
|
||||
|
||||
// Returns a 16-bit bitmask of supported curses-style attributes
|
||||
// (NCSTYLE_UNDERLINE, NCSTYLE_BOLD, etc.) The attribute is only
|
||||
|
@ -180,10 +180,10 @@ int ncdirect_clear(ncdirect* nc){
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ncdirect_dim_x(const ncdirect* nc){
|
||||
int ncdirect_dim_x(ncdirect* nc){
|
||||
int x;
|
||||
if(nc->ctermfd >= 0){
|
||||
if(update_term_dimensions(nc->ctermfd, NULL, &x, NULL) == 0){
|
||||
if(update_term_dimensions(nc->ctermfd, NULL, &x, &nc->tcache, 0) == 0){
|
||||
return x;
|
||||
}
|
||||
}else{
|
||||
@ -192,10 +192,10 @@ int ncdirect_dim_x(const ncdirect* nc){
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ncdirect_dim_y(const ncdirect* nc){
|
||||
int ncdirect_dim_y(ncdirect* nc){
|
||||
int y;
|
||||
if(nc->ctermfd >= 0){
|
||||
if(update_term_dimensions(nc->ctermfd, &y, NULL, NULL) == 0){
|
||||
if(update_term_dimensions(nc->ctermfd, &y, NULL, &nc->tcache, 0) == 0){
|
||||
return y;
|
||||
}
|
||||
}else{
|
||||
@ -447,7 +447,7 @@ int ncdirect_cursor_pop(ncdirect* n){
|
||||
}
|
||||
|
||||
static inline int
|
||||
ncdirect_align(const struct ncdirect* n, ncalign_e align, int c){
|
||||
ncdirect_align(struct ncdirect* n, ncalign_e align, int c){
|
||||
if(align == NCALIGN_LEFT){
|
||||
return 0;
|
||||
}
|
||||
@ -821,7 +821,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
|
||||
if(ncvisual_init(NCLOGLEVEL_SILENT)){
|
||||
goto err;
|
||||
}
|
||||
update_term_dimensions(ret->ctermfd, NULL, NULL, &ret->tcache);
|
||||
update_term_dimensions(ret->ctermfd, NULL, NULL, &ret->tcache, 0);
|
||||
ncdirect_set_styles(ret, 0);
|
||||
return ret;
|
||||
|
||||
|
@ -1041,7 +1041,8 @@ 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, tinfo* tcache);
|
||||
int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache,
|
||||
int margin_b);
|
||||
|
||||
ALLOC static inline void*
|
||||
memdup(const void* src, size_t len){
|
||||
|
@ -216,7 +216,8 @@ 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, tinfo* tcache){
|
||||
int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache,
|
||||
int margin_b){
|
||||
// if we're not a real tty, we presumably haven't changed geometry, return
|
||||
if(fd < 0){
|
||||
if(rows){
|
||||
@ -242,9 +243,11 @@ int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache){
|
||||
fd, ws.ws_row, ws.ws_col);
|
||||
return -1;
|
||||
}
|
||||
if(rows){
|
||||
*rows = ws.ws_row;
|
||||
int rowsafe;
|
||||
if(rows == NULL){
|
||||
rows = &rowsafe;
|
||||
}
|
||||
*rows = ws.ws_row;
|
||||
if(cols){
|
||||
*cols = ws.ws_col;
|
||||
}
|
||||
@ -252,6 +255,16 @@ int update_term_dimensions(int fd, int* rows, int* cols, tinfo* 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;
|
||||
}
|
||||
if(tcache->sixel_maxy_pristine){
|
||||
tcache->sixel_maxy = tcache->sixel_maxy_pristine;
|
||||
int sixelrows = *rows - 1;
|
||||
// if the bottom margin is at least one row, we can draw into the last
|
||||
// row of our visible area. we must leave the true bottom row alone.
|
||||
if(margin_b){
|
||||
++sixelrows;
|
||||
}
|
||||
tcache->sixel_maxy = sixelrows * tcache->cellpixy;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1075,7 +1088,8 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
|
||||
goto err;
|
||||
}
|
||||
int dimy, dimx;
|
||||
if(update_term_dimensions(ret->ttyfd, &dimy, &dimx, &ret->tcache)){
|
||||
if(update_term_dimensions(ret->ttyfd, &dimy, &dimx, &ret->tcache,
|
||||
ret->margin_b)){
|
||||
goto err;
|
||||
}
|
||||
ret->suppress_banner = opts->flags & NCOPTION_SUPPRESS_BANNERS;
|
||||
|
@ -23,23 +23,13 @@ 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, &n->tcache)){
|
||||
if(update_term_dimensions(n->ttyfd, rows, cols, &n->tcache, n->margin_b)){
|
||||
return -1;
|
||||
}
|
||||
*rows -= n->margin_t + n->margin_b;
|
||||
if(*rows <= 0){
|
||||
*rows = 1;
|
||||
}
|
||||
if(n->tcache.sixel_maxy_pristine){
|
||||
n->tcache.sixel_maxy = n->tcache.sixel_maxy_pristine;
|
||||
int sixelrows = *rows - 1;
|
||||
// if the bottom margin is at least one row, we can draw into the last
|
||||
// row of our visible area. we must leave the true bottom row alone.
|
||||
if(n->margin_b){
|
||||
++sixelrows;
|
||||
}
|
||||
n->tcache.sixel_maxy = sixelrows * n->tcache.cellpixy;
|
||||
}
|
||||
*cols -= n->margin_l + n->margin_r;
|
||||
if(*cols <= 0){
|
||||
*cols = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user