use tty_emit() in place of term_emit() for tty-specific escapes #773

pull/808/head
nick black 4 years ago
parent f2b48ab6f7
commit 431d4a449d
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -300,7 +300,7 @@ typedef struct notcurses {
tinfo tcache; // terminfo cache tinfo tcache; // terminfo cache
FILE* ttyfp; // FILE* for controlling tty FILE* ttyfp; // FILE* for writing rasterized data
int ttyfd; // file descriptor for controlling tty int ttyfd; // file descriptor for controlling tty
FILE* ttyinfp; // FILE* for processing input FILE* ttyinfp; // FILE* for processing input
FILE* renderfp; // debugging FILE* to which renderings are written FILE* renderfp; // debugging FILE* to which renderings are written

@ -49,11 +49,13 @@ static int
notcurses_stop_minimal(notcurses* nc){ notcurses_stop_minimal(notcurses* nc){
int ret = 0; int ret = 0;
drop_signals(nc); drop_signals(nc);
if(nc->tcache.rmcup && term_emit("rmcup", nc->tcache.rmcup, nc->ttyfp, true)){ if(nc->ttyfd >= 0){
ret = -1; if(nc->tcache.rmcup && tty_emit("rmcup", nc->tcache.rmcup, nc->ttyfd)){
} ret = -1;
if(nc->tcache.cnorm && term_emit("cnorm", nc->tcache.cnorm, nc->ttyfp, true)){ }
ret = -1; if(nc->tcache.cnorm && tty_emit("cnorm", nc->tcache.cnorm, nc->ttyfd)){
ret = -1;
}
} }
if(nc->tcache.op && term_emit("op", nc->tcache.op, nc->ttyfp, true)){ if(nc->tcache.op && term_emit("op", nc->tcache.op, nc->ttyfp, true)){
ret = -1; ret = -1;
@ -894,15 +896,17 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
if((ret->stdscr = create_initial_ncplane(ret, dimy, dimx)) == NULL){ if((ret->stdscr = create_initial_ncplane(ret, dimy, dimx)) == NULL){
goto err; goto err;
} }
if(ret->tcache.smkx && term_emit("smkx", ret->tcache.smkx, ret->ttyfp, false)){ if(ret->ttyfd >= 0){
free_plane(ret->top); if(ret->tcache.smkx && tty_emit("smkx", ret->tcache.smkx, ret->ttyfd)){
goto err;
}
if(!(opts->flags & NCOPTION_RETAIN_CURSOR)){
if(ret->tcache.civis && term_emit("civis", ret->tcache.civis, ret->ttyfp, true)){
free_plane(ret->top); free_plane(ret->top);
goto err; goto err;
} }
if(!(opts->flags & NCOPTION_RETAIN_CURSOR)){
if(ret->tcache.civis && tty_emit("civis", ret->tcache.civis, ret->ttyfd)){
free_plane(ret->top);
goto err;
}
}
} }
if((ret->rstate.mstreamfp = open_memstream(&ret->rstate.mstream, &ret->rstate.mstrsize)) == NULL){ if((ret->rstate.mstreamfp = open_memstream(&ret->rstate.mstream, &ret->rstate.mstrsize)) == NULL){
free_plane(ret->top); free_plane(ret->top);
@ -911,9 +915,11 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
ret->rstate.x = ret->rstate.y = -1; ret->rstate.x = ret->rstate.y = -1;
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->tcache.smcup && term_emit("smcup", ret->tcache.smcup, ret->ttyfp, true)){ if(ret->ttyfd >= 0){
free_plane(ret->top); if(ret->tcache.smcup && tty_emit("smcup", ret->tcache.smcup, ret->ttyfd)){
goto err; free_plane(ret->top);
goto err;
}
} }
return ret; return ret;
@ -1874,14 +1880,18 @@ void ncplane_erase(ncplane* n){
} }
void notcurses_cursor_enable(notcurses* nc){ void notcurses_cursor_enable(notcurses* nc){
if(nc->tcache.cnorm){ if(nc->ttyfd >= 0){
term_emit("cnorm", nc->tcache.cnorm, nc->ttyfp, true); if(nc->tcache.cnorm){
tty_emit("cnorm", nc->tcache.cnorm, nc->ttyfd);
}
} }
} }
void notcurses_cursor_disable(notcurses* nc){ void notcurses_cursor_disable(notcurses* nc){
if(nc->tcache.civis){ if(nc->ttyfd >= 0){
term_emit("civis", nc->tcache.civis, nc->ttyfp, true); if(nc->tcache.civis){
tty_emit("civis", nc->tcache.civis, nc->ttyfd);
}
} }
} }
@ -1898,17 +1908,23 @@ ncplane* ncplane_below(ncplane* n){
#define SET_FOCUS_EVENT_MOUSE "1004" #define SET_FOCUS_EVENT_MOUSE "1004"
#define SET_SGR_MODE_MOUSE "1006" #define SET_SGR_MODE_MOUSE "1006"
int notcurses_mouse_enable(notcurses* n){ int notcurses_mouse_enable(notcurses* n){
return term_emit("mouse", ESC "[?" SET_BTN_EVENT_MOUSE ";" if(n->ttyfd >= 0){
/*SET_FOCUS_EVENT_MOUSE ";" */SET_SGR_MODE_MOUSE "h", return tty_emit("mouse", ESC "[?" SET_BTN_EVENT_MOUSE ";"
n->ttyfp, true); /*SET_FOCUS_EVENT_MOUSE ";" */SET_SGR_MODE_MOUSE "h",
n->ttyfd);
}
return 0;
} }
// this seems to work (note difference in suffix, 'l' vs 'h'), but what about // this seems to work (note difference in suffix, 'l' vs 'h'), but what about
// the sequences 1000 etc? // the sequences 1000 etc?
int notcurses_mouse_disable(notcurses* n){ int notcurses_mouse_disable(notcurses* n){
return term_emit("mouse", ESC "[?" SET_BTN_EVENT_MOUSE ";" if(n->ttyfd >= 0){
/*SET_FOCUS_EVENT_MOUSE ";" */SET_SGR_MODE_MOUSE "l", return tty_emit("mouse", ESC "[?" SET_BTN_EVENT_MOUSE ";"
n->ttyfp, true); /*SET_FOCUS_EVENT_MOUSE ";" */SET_SGR_MODE_MOUSE "l",
n->ttyfd);
}
return 0;
} }
bool notcurses_canutf8(const notcurses* nc){ bool notcurses_canutf8(const notcurses* nc){

Loading…
Cancel
Save