Clear screen if we want smcup but it's not available #817

This commit is contained in:
nick black 2020-07-22 17:53:46 -04:00
parent 0bd73e2f1f
commit 6d2ba86acc
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 12 additions and 6 deletions

View File

@ -322,8 +322,6 @@ int main(void){
if(!nc.mouse_enable()){ if(!nc.mouse_enable()){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// clear the screen in the absence of smcup mode
nc.refresh(nullptr, nullptr);
int ret = input_demo(&nc); int ret = input_demo(&nc);
if(!nc.stop() || ret){ if(!nc.stop() || ret){
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -922,9 +922,18 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
init_banner(ret); init_banner(ret);
// flush on the switch to alternate screen, lest initial output be swept away // flush on the switch to alternate screen, lest initial output be swept away
if(ret->ttyfd >= 0){ if(ret->ttyfd >= 0){
if(ret->tcache.smcup && tty_emit("smcup", ret->tcache.smcup, ret->ttyfd)){ if(ret->tcache.smcup){
free_plane(ret->top); if(tty_emit("smcup", ret->tcache.smcup, ret->ttyfd)){
goto err; free_plane(ret->top);
goto err;
}
}else{
// if they expected the alternate screen, but we didn't have one to
// offer, at least clear the screen. try using "clear"; if that doesn't
// fly, use notcurses_refresh() to force a clearing via iterated writes.
if(tty_emit("clear", ret->tcache.clearscr, ret->ttyfd)){
notcurses_refresh(ret, NULL, NULL);
}
} }
} }
return ret; return ret;

View File

@ -35,7 +35,6 @@ int main(void) {
ncopts.flags = NCOPTION_INHIBIT_SETLOCALE; ncopts.flags = NCOPTION_INHIBIT_SETLOCALE;
ncpp::NotCurses nc(ncopts); ncpp::NotCurses nc(ncopts);
{ {
nc.refresh(nullptr, nullptr); // clear screen if smcup+background are unavailable
Tetris t{nc, gameover}; Tetris t{nc, gameover};
std::thread tid(&Tetris::Ticker, &t); std::thread tid(&Tetris::Ticker, &t);
if(IOLoop(nc, t, gameover)){ if(IOLoop(nc, t, gameover)){