mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
move cursor controls into escblock #1525
This commit is contained in:
parent
92873d6b6e
commit
d613ed0784
@ -107,10 +107,11 @@ int ncdirect_cursor_up(ncdirect* nc, int num){
|
||||
if(num == 0){
|
||||
return 0;
|
||||
}
|
||||
if(!nc->tcache.cuu){
|
||||
return -1;
|
||||
const char* cuu = get_escape(&nc->tcache, ESCAPE_CUU);
|
||||
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){
|
||||
@ -120,10 +121,11 @@ int ncdirect_cursor_left(ncdirect* nc, int num){
|
||||
if(num == 0){
|
||||
return 0;
|
||||
}
|
||||
if(!nc->tcache.cub){
|
||||
return -1;
|
||||
const char* cub = get_escape(&nc->tcache, ESCAPE_CUB);
|
||||
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){
|
||||
@ -133,10 +135,11 @@ int ncdirect_cursor_right(ncdirect* nc, int num){
|
||||
if(num == 0){
|
||||
return 0;
|
||||
}
|
||||
if(!nc->tcache.cuf){ // FIXME fall back to cuf1
|
||||
return -1;
|
||||
const char* cuf = get_escape(&nc->tcache, ESCAPE_CUF);
|
||||
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
|
||||
@ -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
|
||||
// instead of ctermfd. since we always talk directly to the terminal, we need
|
||||
// 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;
|
||||
}
|
||||
int movex;
|
||||
int movey;
|
||||
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;
|
||||
}
|
||||
if(tty_emit(tiparm(n->tcache.cub, 1), n->ctermfd)){
|
||||
if(tty_emit(tiparm(cub, 1), n->ctermfd)){
|
||||
return -1;
|
||||
}
|
||||
movex = 1;
|
||||
movey = -1;
|
||||
}else{
|
||||
if(tty_emit(tiparm(n->tcache.cuu, 1), n->ctermfd)){
|
||||
if(tty_emit(tiparm(cuu, 1), n->ctermfd)){
|
||||
return -1;
|
||||
}
|
||||
if(tty_emit(tiparm(n->tcache.cuf, 1), n->ctermfd)){
|
||||
if(tty_emit(tiparm(cuf, 1), n->ctermfd)){
|
||||
return -1;
|
||||
}
|
||||
movex = -1;
|
||||
@ -308,10 +316,10 @@ detect_cursor_inversion(ncdirect* n, int rows, int cols, int* y, int* x){
|
||||
*y = newy;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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
|
||||
return 0;
|
||||
}
|
||||
if(x == nc->rstate.x + 1 && nc->tcache.cuf1){
|
||||
ret = term_emit(nc->tcache.cuf1, out, false);
|
||||
const char* cuf1 = get_escape(&nc->tcache, ESCAPE_CUF1);
|
||||
if(x == nc->rstate.x + 1 && cuf1){
|
||||
ret = term_emit(cuf1, out, false);
|
||||
}else{
|
||||
ret = term_emit(tiparm(hpa, x), out, false);
|
||||
}
|
||||
|
@ -39,6 +39,11 @@ typedef enum {
|
||||
ESCAPE_OC, // "oc" restore original colors
|
||||
ESCAPE_SITM, // "sitm" start 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_e;
|
||||
|
||||
@ -51,11 +56,6 @@ typedef struct tinfo {
|
||||
uint16_t escindices[ESCAPE_MAX]; // table of 1-biased indices into esctable
|
||||
char* esctable; // packed table of escape sequences
|
||||
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* struck; // NCSTYLE_STRUCK
|
||||
char* struckoff;// NCSTYLE_STRUCK (disable)
|
||||
|
@ -208,6 +208,11 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
|
||||
{ ESCAPE_SGR0, "sgr0", },
|
||||
{ ESCAPE_SITM, "sitm", },
|
||||
{ ESCAPE_RITM, "ritm", },
|
||||
{ ESCAPE_CUD, "cud", },
|
||||
{ ESCAPE_CUU, "cuu", },
|
||||
{ ESCAPE_CUF, "cuf", },
|
||||
{ ESCAPE_CUF1, "cuf1", },
|
||||
{ ESCAPE_CUB, "cub", },
|
||||
{ ESCAPE_MAX, NULL, },
|
||||
};
|
||||
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->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->rc, "rc"); // pop ("restore") cursor
|
||||
// we don't actually use the bold capability -- we use sgr exclusively.
|
||||
|
Loading…
x
Reference in New Issue
Block a user