move cursor controls into escblock #1525

pull/1693/head
nick black 3 years ago committed by Nick Black
parent 92873d6b6e
commit d613ed0784

@ -107,10 +107,11 @@ int ncdirect_cursor_up(ncdirect* nc, int num){
if(num == 0){ if(num == 0){
return 0; return 0;
} }
if(!nc->tcache.cuu){ const char* cuu = get_escape(&nc->tcache, ESCAPE_CUU);
return -1; if(cuu){
return term_emit(tiparm(cuu, num), nc->ttyfp, false);
} }
return term_emit(tiparm(nc->tcache.cuu, num), nc->ttyfp, false); return -1;
} }
int ncdirect_cursor_left(ncdirect* nc, int num){ int ncdirect_cursor_left(ncdirect* nc, int num){
@ -120,10 +121,11 @@ int ncdirect_cursor_left(ncdirect* nc, int num){
if(num == 0){ if(num == 0){
return 0; return 0;
} }
if(!nc->tcache.cub){ const char* cub = get_escape(&nc->tcache, ESCAPE_CUB);
return -1; if(cub){
return term_emit(tiparm(cub, num), nc->ttyfp, false);
} }
return term_emit(tiparm(nc->tcache.cub, num), nc->ttyfp, false); return -1;
} }
int ncdirect_cursor_right(ncdirect* nc, int num){ int ncdirect_cursor_right(ncdirect* nc, int num){
@ -133,10 +135,11 @@ int ncdirect_cursor_right(ncdirect* nc, int num){
if(num == 0){ if(num == 0){
return 0; return 0;
} }
if(!nc->tcache.cuf){ // FIXME fall back to cuf1 const char* cuf = get_escape(&nc->tcache, ESCAPE_CUF);
return -1; if(cuf){
return term_emit(tiparm(cuf, num), nc->ttyfp, false);
} }
return term_emit(tiparm(nc->tcache.cuf, num), nc->ttyfp, false); return -1; // FIXME fall back to cuf1?
} }
// if we're on the last line, we need some scrolling action. rather than // if we're on the last line, we need some scrolling action. rather than
@ -274,25 +277,30 @@ detect_cursor_inversion(ncdirect* n, int rows, int cols, int* y, int* x){
// do not use normal ncdirect_cursor_*() commands, because those go to ttyfp // do not use normal ncdirect_cursor_*() commands, because those go to ttyfp
// instead of ctermfd. since we always talk directly to the terminal, we need // instead of ctermfd. since we always talk directly to the terminal, we need
// to move the cursor directly via the terminal. // to move the cursor directly via the terminal.
if(!n->tcache.cud || !n->tcache.cub || !n->tcache.cuf || !n->tcache.cuu){ const char* cuu = get_escape(&n->tcache, ESCAPE_CUU);
const char* cuf = get_escape(&n->tcache, ESCAPE_CUF);
const char* cub = get_escape(&n->tcache, ESCAPE_CUB);
// FIXME do we want to use cud here, or \v like above?
const char* cud = get_escape(&n->tcache, ESCAPE_CUD);
if(!cud || !cub || !cuf || !cuu){
return -1; return -1;
} }
int movex; int movex;
int movey; int movey;
if(*x == cols && *y == 1){ if(*x == cols && *y == 1){
if(tty_emit(tiparm(n->tcache.cud, 1), n->ctermfd)){ if(tty_emit(tiparm(cud, 1), n->ctermfd)){
return -1; return -1;
} }
if(tty_emit(tiparm(n->tcache.cub, 1), n->ctermfd)){ if(tty_emit(tiparm(cub, 1), n->ctermfd)){
return -1; return -1;
} }
movex = 1; movex = 1;
movey = -1; movey = -1;
}else{ }else{
if(tty_emit(tiparm(n->tcache.cuu, 1), n->ctermfd)){ if(tty_emit(tiparm(cuu, 1), n->ctermfd)){
return -1; return -1;
} }
if(tty_emit(tiparm(n->tcache.cuf, 1), n->ctermfd)){ if(tty_emit(tiparm(cuf, 1), n->ctermfd)){
return -1; return -1;
} }
movex = -1; movex = -1;
@ -308,10 +316,10 @@ detect_cursor_inversion(ncdirect* n, int rows, int cols, int* y, int* x){
*y = newy; *y = newy;
newy = 1; newy = 1;
} }
if(tty_emit(tiparm(movex == 1 ? n->tcache.cuf : n->tcache.cub, 1), n->ctermfd)){ if(tty_emit(tiparm(movex == 1 ? cuf : cub, 1), n->ctermfd)){
return -1; return -1;
} }
if(tty_emit(tiparm(movey == 1 ? n->tcache.cud : n->tcache.cuu, 1), n->ctermfd)){ if(tty_emit(tiparm(movey == 1 ? cud : cuu, 1), n->ctermfd)){
return -1; return -1;
} }
if(*y == newy && *x == newx){ if(*y == newy && *x == newx){

@ -817,8 +817,9 @@ goto_location(notcurses* nc, FILE* out, int y, int x){
if(nc->rstate.x == x){ // needn't move shit if(nc->rstate.x == x){ // needn't move shit
return 0; return 0;
} }
if(x == nc->rstate.x + 1 && nc->tcache.cuf1){ const char* cuf1 = get_escape(&nc->tcache, ESCAPE_CUF1);
ret = term_emit(nc->tcache.cuf1, out, false); if(x == nc->rstate.x + 1 && cuf1){
ret = term_emit(cuf1, out, false);
}else{ }else{
ret = term_emit(tiparm(hpa, x), out, false); ret = term_emit(tiparm(hpa, x), out, false);
} }

@ -39,6 +39,11 @@ typedef enum {
ESCAPE_OC, // "oc" restore original colors ESCAPE_OC, // "oc" restore original colors
ESCAPE_SITM, // "sitm" start italics ESCAPE_SITM, // "sitm" start italics
ESCAPE_RITM, // "ritm" end italics ESCAPE_RITM, // "ritm" end italics
ESCAPE_CUU, // "cuu" move n cells up
ESCAPE_CUB, // "cub" move n cells back (left)
ESCAPE_CUF, // "cuf" move n cells forward (right)
ESCAPE_CUD, // "cud" move n cells down
ESCAPE_CUF1, // "cuf1" move 1 cell forward (right)
ESCAPE_MAX ESCAPE_MAX
} escape_e; } escape_e;
@ -51,11 +56,6 @@ typedef struct tinfo {
uint16_t escindices[ESCAPE_MAX]; // table of 1-biased indices into esctable uint16_t escindices[ESCAPE_MAX]; // table of 1-biased indices into esctable
char* esctable; // packed table of escape sequences char* esctable; // packed table of escape sequences
unsigned colors;// number of colors terminfo reported usable for this screen unsigned colors;// number of colors terminfo reported usable for this screen
char* cuu; // move N cells up
char* cub; // move N cells left
char* cuf; // move N cells right
char* cud; // move N cells down
char* cuf1; // move 1 cell right
char* home; // home cursor char* home; // home cursor
char* struck; // NCSTYLE_STRUCK char* struck; // NCSTYLE_STRUCK
char* struckoff;// NCSTYLE_STRUCK (disable) char* struckoff;// NCSTYLE_STRUCK (disable)

@ -208,6 +208,11 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
{ ESCAPE_SGR0, "sgr0", }, { ESCAPE_SGR0, "sgr0", },
{ ESCAPE_SITM, "sitm", }, { ESCAPE_SITM, "sitm", },
{ ESCAPE_RITM, "ritm", }, { ESCAPE_RITM, "ritm", },
{ ESCAPE_CUD, "cud", },
{ ESCAPE_CUU, "cuu", },
{ ESCAPE_CUF, "cuf", },
{ ESCAPE_CUF1, "cuf1", },
{ ESCAPE_CUB, "cub", },
{ ESCAPE_MAX, NULL, }, { ESCAPE_MAX, NULL, },
}; };
size_t tablelen = 0; size_t tablelen = 0;
@ -248,11 +253,6 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
} }
terminfostr(&ti->home, "home"); // home the cursor terminfostr(&ti->home, "home"); // home the cursor
terminfostr(&ti->clearscr, "clear");// clear screen, home cursor terminfostr(&ti->clearscr, "clear");// clear screen, home cursor
terminfostr(&ti->cuu, "cuu"); // move N up
terminfostr(&ti->cud, "cud"); // move N down
terminfostr(&ti->cuf, "cuf"); // n non-destructive spaces
terminfostr(&ti->cub, "cub"); // n non-destructive backspaces
terminfostr(&ti->cuf1, "cuf1"); // non-destructive space
terminfostr(&ti->sc, "sc"); // push ("save") cursor terminfostr(&ti->sc, "sc"); // push ("save") cursor
terminfostr(&ti->rc, "rc"); // pop ("restore") cursor terminfostr(&ti->rc, "rc"); // pop ("restore") cursor
// we don't actually use the bold capability -- we use sgr exclusively. // we don't actually use the bold capability -- we use sgr exclusively.

Loading…
Cancel
Save