Skip to content

Commit

Permalink
always obliterate query spillage #2019
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Aug 3, 2021
1 parent c7738c7 commit 57ebf73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/lib/direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,11 +864,21 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
goto err;
}
shortname_term = termname();
int cursor_y = -1;
int cursor_x = -1;
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8,
1, flags & NCDIRECT_OPTION_INHIBIT_CBREAK,
TERMINAL_UNKNOWN, NULL, NULL, NULL)){
TERMINAL_UNKNOWN, &cursor_y, &cursor_x, NULL)){
goto err;
}
if(cursor_y >= 0){
// the u7 led the queries so that we would get a cursor position
// unaffected by any query spill (unconsumed control sequences). move
// us back to that location, in case there was any such spillage.
if(ncdirect_cursor_move_yx(ret, cursor_y, cursor_x)){
goto err;
}
}
if(ncvisual_init(loglevel)){
goto err;
}
Expand Down
18 changes: 11 additions & 7 deletions src/lib/notcurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,28 +1136,32 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
const char* shortname_term = termname(); // longname() is also available
ret->rstate.logendy = -1;
ret->rstate.logendx = -1;
ret->rstate.x = ret->rstate.y = -1;
ret->suppress_banner = opts->flags & NCOPTION_SUPPRESS_BANNERS;
int fakecursory, fakecursorx;
int* cursory = opts->flags & NCOPTION_PRESERVE_CURSOR ?
&ret->rstate.logendy : &fakecursory;
int* cursorx = opts->flags & NCOPTION_PRESERVE_CURSOR ?
&ret->rstate.logendx : &fakecursorx;
if(interrogate_terminfo(&ret->tcache, ret->ttyfd, shortname_term, utf8,
opts->flags & NCOPTION_NO_ALTERNATE_SCREEN, 0,
opts->flags & NCOPTION_NO_FONT_CHANGES,
opts->flags & NCOPTION_PRESERVE_CURSOR ? &ret->rstate.logendy : NULL,
opts->flags & NCOPTION_PRESERVE_CURSOR ? &ret->rstate.logendx : NULL,
&ret->stats)){
cursory, cursorx, &ret->stats)){
goto err;
}
ret->rstate.x = ret->rstate.y = -1;
if(opts->flags & NCOPTION_PRESERVE_CURSOR){
if((opts->flags & NCOPTION_PRESERVE_CURSOR) || !ret->suppress_banner){
// the u7 led the queries so that we would get a cursor position
// unaffected by any query spill (unconsumed control sequences). move
// us back to that location, in case there was any such spillage.
if(goto_location(ret, ret->ttyfp, ret->rstate.logendy, ret->rstate.logendx)){
if(goto_location(ret, ret->ttyfp, *cursory, *cursorx)){
goto err;
}
}
int dimy, dimx;
if(update_term_dimensions(ret->ttyfd, &dimy, &dimx, &ret->tcache,
ret->margin_b)){
goto err;
}
ret->suppress_banner = opts->flags & NCOPTION_SUPPRESS_BANNERS;
if(ncvisual_init(ret->loglevel)){
goto err;
}
Expand Down

0 comments on commit 57ebf73

Please sign in to comment.