Pop keyboard stack if we crash in initialization

if we crash while detecting kitty keyboard support, we
currently don't pop the keyboard state. since we set our
desired state before detecting support, this could leave
the terminal in an invalid state. now, we initialize
kbdlevel to UINT_MAX before detection, so that in a crash,
the pop always happens. we reset it at the end of
interrogation, assuming we didn't load it from a query
response. the downside is that a terminal which doesn't
consume this sequence will get hit with it in a crash, but
we're already crashing, so who cares? leaving the terminal
in an invalid state, however, is very annoying.
pull/2263/head
nick black 3 years ago committed by nick black
parent 5b5e97033d
commit 69c2ae3ba0

@ -117,6 +117,7 @@ notcurses_stop_minimal(void* vnc){
}
}
}
logdebug("reset terminal, returning %d\n", ret);
return ret;
}

@ -775,6 +775,7 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut
*cursor_x = *cursor_y = -1;
memset(ti, 0, sizeof(*ti));
ti->bg_collides_default = 0xfe000000;
ti->kbdlevel = UINT_MAX; // see comment in tinfo definition
ti->qterm = TERMINAL_UNKNOWN;
// we don't need a controlling tty for everything we do; allow a failure here
ti->ttyfd = get_tty_fd(out);
@ -1026,6 +1027,8 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut
goto err;
}
}
}else{
ti->kbdlevel = 0; // confirmed no support, don't bother popping
}
if(*cursor_x >= 0 && *cursor_y >= 0){
if(add_u7_escape(ti, &tablelen, &tableused)){

@ -186,6 +186,12 @@ typedef struct tinfo {
HANDLE outhandle;
#endif
// kitty keyboard protocol level. we initialize this to UINT_MAX, in case we
// crash while running the initialization automata (in that case, we want to
// pop the keyboard support level, which we normally do only if we detected
// actual support. at that point, we obviously haven't detected anything).
// after getting the initialization package back, if it's still UINT_MAX, we
// set it back to 0, since we know at that point that there's no support.
unsigned kbdlevel; // kitty keyboard support level
bool bce; // is the bce property advertised?
bool in_alt_screen; // are we in the alternate screen?

Loading…
Cancel
Save