Skip to content

Commit

Permalink
clamp sixel height in update_term_dimensions() so ncdirect gets it #1789
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Jun 19, 2021
1 parent 50a304b commit 534000c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions include/notcurses/direct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/lib/direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/lib/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
22 changes: 18 additions & 4 deletions src/lib/notcurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -242,16 +243,28 @@ 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;
}
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;
}
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;
}

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 1 addition & 11 deletions src/lib/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 534000c

Please sign in to comment.