diff --git a/src/lib/debug.c b/src/lib/debug.c index 8a1849775..7133b1472 100644 --- a/src/lib/debug.c +++ b/src/lib/debug.c @@ -44,7 +44,9 @@ tinfo_debug_caps(const tinfo* ti, FILE* debugfp, int rows, int cols, fprintf(debugfp, "%sbackground isn't interpreted as transparent\n", indent); } fprintf(debugfp, "%scup: %c vpa: %c hpa: %c\n", - indent, capyn(get_escape(ti, ESCAPE_CUP)), capyn(ti->vpa), capyn(ti->hpa)); + indent, capyn(get_escape(ti, ESCAPE_CUP)), + capyn(get_escape(ti, ESCAPE_VPA)), + capyn(get_escape(ti, ESCAPE_HPA))); } void notcurses_debug_caps(const notcurses* nc, FILE* debugfp){ diff --git a/src/lib/direct.c b/src/lib/direct.c index 514f3a0a0..17bdea348 100644 --- a/src/lib/direct.c +++ b/src/lib/direct.c @@ -211,9 +211,11 @@ int ncdirect_cursor_disable(ncdirect* nc){ // tests under TERM=vt100. if we need to truly rigourize things, we could // cub/cub1 the width or cuu/cuu1 the height, then cuf/cub back? FIXME int ncdirect_cursor_move_yx(ncdirect* n, int y, int x){ + const char* hpa = get_escape(&n->tcache, ESCAPE_HPA); + const char* vpa = get_escape(&n->tcache, ESCAPE_VPA); if(y == -1){ // keep row the same, horizontal move only - if(n->tcache.hpa){ - return term_emit(tiparm(n->tcache.hpa, x), n->ttyfp, false); + if(hpa){ + return term_emit(tiparm(hpa, x), n->ttyfp, false); }else if(n->ctermfd >= 0){ if(cursor_yx_get(n->ctermfd, &y, NULL)){ return -1; @@ -222,8 +224,8 @@ int ncdirect_cursor_move_yx(ncdirect* n, int y, int x){ y = 0; } }else if(x == -1){ // keep column the same, vertical move only - if(!n->tcache.vpa){ - return term_emit(tiparm(n->tcache.vpa, y), n->ttyfp, false); + if(!vpa){ + return term_emit(tiparm(vpa, y), n->ttyfp, false); }else if(n->ctermfd >= 0){ if(cursor_yx_get(n->ctermfd, NULL, &x)){ return -1; @@ -235,9 +237,9 @@ int ncdirect_cursor_move_yx(ncdirect* n, int y, int x){ const char* cup = get_escape(&n->tcache, ESCAPE_CUP); if(cup){ return term_emit(tiparm(cup, y, x), n->ttyfp, false); - }else if(n->tcache.vpa && n->tcache.hpa){ - if(term_emit(tiparm(n->tcache.hpa, x), n->ttyfp, false) == 0 && - term_emit(tiparm(n->tcache.vpa, y), n->ttyfp, false) == 0){ + }else if(vpa && hpa){ + if(term_emit(tiparm(hpa, x), n->ttyfp, false) == 0 && + term_emit(tiparm(vpa, y), n->ttyfp, false) == 0){ return 0; } } diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 8f75d91b0..1512a34f6 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -809,7 +809,7 @@ init_banner_warnings(const notcurses* nc, FILE* out){ if(!notcurses_canutf8(nc)){ fprintf(out, "\n Warning! Encoding is not UTF-8; output may be degraded.\n"); } - if(!nc->tcache.hpa){ + if(!get_escape(&nc->tcache, ESCAPE_HPA)){ fprintf(out, "\n Warning! No absolute horizontal placement.\n"); } if(nc->tcache.sgr0){ @@ -1189,9 +1189,11 @@ int notcurses_stop(notcurses* nc){ // if we were not using the alternate screen, our cursor's wherever we last // wrote. move it to the bottom left of the screen. if(!nc->tcache.smcup){ - tty_emit(tiparm(nc->tcache.hpa, 0), nc->ttyfd); + // if ldimy is 0, we've not yet written anything; leave it untouched if(nc->lfdimy){ - tty_emit(tiparm(nc->tcache.vpa, nc->lfdimy + nc->margin_t - 1), nc->ttyfd); + int targy = nc->lfdimy + nc->margin_t - 1; + // cup is required, no need to test for existence + tty_emit(tiparm(get_escape(&nc->tcache, ESCAPE_CUP), targy, 0), nc->ttyfd); } } if(nc->ttyfd >= 0){ diff --git a/src/lib/render.c b/src/lib/render.c index 467140de2..3efc632f5 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -811,14 +811,15 @@ goto_location(notcurses* nc, FILE* out, int y, int x){ // if we don't have hpa, force a cup even if we're only 1 char away. the only // terminal i know supporting cup sans hpa is vt100, and vt100 can suck it. // you can't use cuf for backwards moves anyway; again, vt100 can suck it. - if(nc->rstate.y == y && nc->tcache.hpa && !nc->rstate.hardcursorpos){ // only need move x + const char* hpa = get_escape(&nc->tcache, ESCAPE_HPA); + if(nc->rstate.y == y && hpa && !nc->rstate.hardcursorpos){ // only need move x if(nc->rstate.x == x){ // needn't move shit return 0; } if(x == nc->rstate.x + 1 && nc->tcache.cuf1){ ret = term_emit(nc->tcache.cuf1, out, false); }else{ - ret = term_emit(tiparm(nc->tcache.hpa, x), out, false); + ret = term_emit(tiparm(hpa, x), out, false); } }else{ // cup is required, no need to verify existence diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index 780449a41..ac63779cb 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -45,8 +45,6 @@ typedef enum { typedef struct tinfo { uint16_t escindices[ESCAPE_MAX]; // table of 1-biased indices into esctable char* esctable; // packed table of escape sequences - char* hpa; // horizontal position adjusment (move cursor on row) - char* vpa; // vertical position adjustment (move cursor on column) char* setaf; // set foreground color (ANSI) char* setab; // set background color (ANSI) char* op; // set foreground and background color to default @@ -138,7 +136,7 @@ typedef struct tinfo { } tinfo; // retrieve the terminfo(5)-style escape 'e' from tdesc (NULL if undefined). -static inline const char* +static inline __attribute__ ((pure)) const char* get_escape(const tinfo* tdesc, escape_e e){ unsigned idx = tdesc->escindices[e]; if(idx){ diff --git a/src/lib/terminfo.c b/src/lib/terminfo.c index ffad3cbcc..d6bfeb990 100644 --- a/src/lib/terminfo.c +++ b/src/lib/terminfo.c @@ -196,6 +196,8 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, const char* tinfo; } strtdescs[] = { { ESCAPE_CUP, "cup", }, + { ESCAPE_HPA, "hpa", }, + { ESCAPE_VPA, "vpa", }, { ESCAPE_MAX, NULL, }, }; size_t tablelen = 0; @@ -248,8 +250,6 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, terminfostr(&ti->clearscr, "clear");// clear screen, home cursor terminfostr(&ti->cuu, "cuu"); // move N up terminfostr(&ti->cud, "cud"); // move N down - terminfostr(&ti->hpa, "hpa"); // set horizontal position - terminfostr(&ti->vpa, "vpa"); // set verical position terminfostr(&ti->cuf, "cuf"); // n non-destructive spaces terminfostr(&ti->cub, "cub"); // n non-destructive backspaces terminfostr(&ti->cuf1, "cuf1"); // non-destructive space