civis and cnorm go into escape table #1525

pull/1693/head
nick black 3 years ago committed by Nick Black
parent 3f26ff2464
commit 91d8529f0f

@ -192,17 +192,19 @@ int ncdirect_dim_y(const ncdirect* nc){
}
int ncdirect_cursor_enable(ncdirect* nc){
if(!nc->tcache.cnorm){
return -1;
const char* cnorm = get_escape(&nc->tcache, ESCAPE_CNORM);
if(cnorm){
return term_emit(cnorm, nc->ttyfp, true);
}
return term_emit(nc->tcache.cnorm, nc->ttyfp, true);
return -1;
}
int ncdirect_cursor_disable(ncdirect* nc){
if(!nc->tcache.civis){
return -1;
const char* cinvis = get_escape(&nc->tcache, ESCAPE_CIVIS);
if(cinvis){
return term_emit(cinvis, nc->ttyfp, true);
}
return term_emit(nc->tcache.civis, nc->ttyfp, true);
return -1;
}
// if we're lacking hpa/vpa, *and* -1 is passed for one of x/y, *and* we've
@ -707,7 +709,8 @@ ncdirect_stop_minimal(void* vnc){
if(nc->tcache.pixel_shutdown){
ret |= nc->tcache.pixel_shutdown(nc->ctermfd);
}
if(nc->tcache.cnorm && tty_emit(nc->tcache.cnorm, nc->ctermfd)){
const char* cnorm = get_escape(&nc->tcache, ESCAPE_CNORM);
if(cnorm && tty_emit(cnorm, nc->ctermfd)){
ret = -1;
}
ret |= tcsetattr(nc->ctermfd, TCSANOW, &nc->tpreserved);

@ -79,7 +79,8 @@ notcurses_stop_minimal(void* vnc){
if(nc->tcache.rmkx && tty_emit(nc->tcache.rmkx, nc->ttyfd)){
ret = -1;
}
if(nc->tcache.cnorm && tty_emit(nc->tcache.cnorm, nc->ttyfd)){
const char* cnorm = get_escape(&nc->tcache, ESCAPE_CNORM);
if(cnorm && tty_emit(cnorm, nc->ttyfd)){
ret = -1;
}
ret |= tcsetattr(nc->ttyfd, TCSANOW, &nc->tpreserved);
@ -1091,7 +1092,8 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
free_plane(ret->stdplane);
goto err;
}
if(ret->tcache.civis && tty_emit(ret->tcache.civis, ret->ttyfd)){
const char* cinvis = get_escape(&ret->tcache, ESCAPE_CIVIS);
if(cinvis && tty_emit(cinvis, ret->ttyfd)){
free_plane(ret->stdplane);
goto err;
}

@ -1484,7 +1484,8 @@ int notcurses_cursor_enable(notcurses* nc, int y, int x){
if(nc->cursory == y && nc->cursorx == x){
return 0;
}
if(nc->ttyfd < 0 || !nc->tcache.cnorm){
const char* cnorm = get_escape(&nc->tcache, ESCAPE_CNORM);
if(nc->ttyfd < 0 || !cnorm){
return -1;
}
// updates nc->rstate.cursor{y,x}
@ -1497,7 +1498,7 @@ int notcurses_cursor_enable(notcurses* nc, int y, int x){
nc->cursorx = x;
return 0;
}
if(tty_emit(nc->tcache.cnorm, nc->ttyfd) || fflush(nc->ttyfp) == EOF){
if(tty_emit(cnorm, nc->ttyfd) || fflush(nc->ttyfp) == EOF){
return -1;
}
nc->cursory = y;
@ -1511,8 +1512,9 @@ int notcurses_cursor_disable(notcurses* nc){
return -1;
}
if(nc->ttyfd >= 0){
if(nc->tcache.civis){
if(!tty_emit(nc->tcache.civis, nc->ttyfd) && !fflush(nc->ttyfp)){
const char* cinvis = get_escape(&nc->tcache, ESCAPE_CIVIS);
if(cinvis){
if(!tty_emit(cinvis, nc->ttyfd) && !fflush(nc->ttyfp)){
nc->cursory = -1;
nc->cursorx = -1;
return 0;

@ -49,8 +49,6 @@ typedef struct tinfo {
char* esctable; // packed table of escape sequences
char* sgr; // set many graphics properties at once
char* sgr0; // restore default presentation properties
char* civis; // hide cursor
char* cnorm; // restore cursor to default state
unsigned colors;// number of colors terminfo reported usable for this screen
char* cuu; // move N cells up
char* cub; // move N cells left

@ -202,6 +202,8 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
{ ESCAPE_SETAF, "setaf", },
{ ESCAPE_SETAB, "setab", },
{ ESCAPE_OP, "op", },
{ ESCAPE_CNORM, "cnorm", },
{ ESCAPE_CIVIS, "civis", },
{ ESCAPE_MAX, NULL, },
};
size_t tablelen = 0;
@ -232,11 +234,14 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
goto err;
}
ti->BCEflag = tigetflag("bce") == 1;
terminfostr(&ti->civis, "civis"); // cursor invisible
if(ti->civis == NULL){
terminfostr(&ti->civis, "chts");// hard-to-see cursor
if(get_escape(ti, ESCAPE_CIVIS) == NULL){
char* chts;
if(terminfostr(&chts, "chts") == 0){
if(grow_esc_table(ti, chts, ESCAPE_CIVIS, &tablelen, &tableused)){
goto err;
}
}
}
terminfostr(&ti->cnorm, "cnorm"); // cursor normal (undo civis/cvvis)
terminfostr(&ti->standout, "smso"); // begin standout mode
terminfostr(&ti->uline, "smul"); // begin underline mode
terminfostr(&ti->reverse, "rev"); // begin reverse video mode

@ -831,7 +831,7 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
bargs.u.pixel.spx = n->sprite;
// FIXME only set this if cursor is indeed hidden
if(nc->tcache.sprixel_cursor_hack){
bargs.u.pixel.cursor_hack = nc->tcache.civis;
bargs.u.pixel.cursor_hack = get_escape(&nc->tcache, ESCAPE_CIVIS);
}else{
bargs.u.pixel.cursor_hack = NULL;
}

Loading…
Cancel
Save