mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
move sc, rc, clear, and home to esctable #1525
This commit is contained in:
parent
567a1796a5
commit
59ddd3b0aa
@ -164,10 +164,11 @@ int ncdirect_cursor_down(ncdirect* nc, int num){
|
||||
}
|
||||
|
||||
int ncdirect_clear(ncdirect* nc){
|
||||
if(!nc->tcache.clearscr){
|
||||
return -1; // FIXME scroll output off the screen
|
||||
const char* clearscr = get_escape(&nc->tcache, ESCAPE_CLEAR);
|
||||
if(clearscr){
|
||||
return term_emit(clearscr, nc->ttyfp, true);
|
||||
}
|
||||
return term_emit(nc->tcache.clearscr, nc->ttyfp, true);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ncdirect_dim_x(const ncdirect* nc){
|
||||
@ -415,17 +416,19 @@ int ncdirect_cursor_yx(ncdirect* n, int* y, int* x){
|
||||
}
|
||||
|
||||
int ncdirect_cursor_push(ncdirect* n){
|
||||
if(n->tcache.sc == NULL){
|
||||
return -1;
|
||||
const char* sc = get_escape(&n->tcache, ESCAPE_SC);
|
||||
if(sc){
|
||||
return term_emit(sc, n->ttyfp, false);
|
||||
}
|
||||
return term_emit(n->tcache.sc, n->ttyfp, false);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ncdirect_cursor_pop(ncdirect* n){
|
||||
if(n->tcache.rc == NULL){
|
||||
return -1;
|
||||
const char* rc = get_escape(&n->tcache, ESCAPE_RC);
|
||||
if(rc){
|
||||
return term_emit(rc, n->ttyfp, false);
|
||||
}
|
||||
return term_emit(n->tcache.rc, n->ttyfp, false);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int
|
||||
|
@ -1108,6 +1108,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
|
||||
ret->rstate.x = ret->rstate.y = -1;
|
||||
init_banner(ret, shortname_term);
|
||||
// flush on the switch to alternate screen, lest initial output be swept away
|
||||
const char* clearscr = get_escape(&ret->tcache, ESCAPE_CLEAR);
|
||||
if(ret->ttyfd >= 0){
|
||||
const char* smcup = get_escape(&ret->tcache, ESCAPE_SMCUP);
|
||||
if(smcup){
|
||||
@ -1116,14 +1117,14 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
|
||||
goto err;
|
||||
}
|
||||
// explicit clear even though smcup *might* clear
|
||||
if(tty_emit(ret->tcache.clearscr, ret->ttyfd)){
|
||||
if(!clearscr || tty_emit(clearscr, ret->ttyfd)){
|
||||
notcurses_refresh(ret, NULL, NULL);
|
||||
}
|
||||
}else if(!(opts->flags & NCOPTION_NO_ALTERNATE_SCREEN)){
|
||||
// if they expected the alternate screen, but we didn't have one to
|
||||
// offer, at least clear the screen. try using "clear"; if that doesn't
|
||||
// fly, use notcurses_refresh() to force a clearing via iterated writes.
|
||||
if(tty_emit(ret->tcache.clearscr, ret->ttyfd)){
|
||||
if(!clearscr || tty_emit(clearscr, ret->ttyfd)){
|
||||
notcurses_refresh(ret, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -1191,14 +1191,16 @@ notcurses_rasterize(notcurses* nc, ncpile* p, FILE* out){
|
||||
static int
|
||||
home_cursor(notcurses* nc, bool flush){
|
||||
int ret = -1;
|
||||
if(nc->tcache.home){
|
||||
ret = term_emit(nc->tcache.home, nc->ttyfp, flush);
|
||||
const char* home = get_escape(&nc->tcache, ESCAPE_HOME);
|
||||
if(home){
|
||||
ret = term_emit(home, nc->ttyfp, flush);
|
||||
}else{
|
||||
const char* cup = get_escape(&nc->tcache, ESCAPE_CUP);
|
||||
const char* clearscr = get_escape(&nc->tcache, ESCAPE_CLEAR);
|
||||
if(cup){
|
||||
ret = term_emit(tiparm(cup, 1, 1), nc->ttyfp, flush);
|
||||
}else if(nc->tcache.clearscr){
|
||||
ret = term_emit(nc->tcache.clearscr, nc->ttyfp, flush);
|
||||
}else if(clearscr){
|
||||
ret = term_emit(clearscr, nc->ttyfp, flush);
|
||||
}
|
||||
}
|
||||
if(ret >= 0){
|
||||
|
@ -231,6 +231,10 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
|
||||
{ ESCAPE_RMKX, "rmkx", },
|
||||
{ ESCAPE_SMXX, "smxx", },
|
||||
{ ESCAPE_RMXX, "rmxx", },
|
||||
{ ESCAPE_SC, "sc", },
|
||||
{ ESCAPE_RC, "rc", },
|
||||
{ ESCAPE_CLEAR, "clear", },
|
||||
{ ESCAPE_HOME, "home", },
|
||||
{ ESCAPE_MAX, NULL, },
|
||||
};
|
||||
size_t tablelen = 0;
|
||||
@ -269,10 +273,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->sc, "sc"); // push ("save") cursor
|
||||
terminfostr(&ti->rc, "rc"); // pop ("restore") cursor
|
||||
// we don't actually use the bold capability -- we use sgr exclusively.
|
||||
// but we use the presence of the bold capability to determine whether
|
||||
// we think sgr supports bold, which...might be valid? i'm unsure. futher,
|
||||
|
@ -50,6 +50,10 @@ typedef enum {
|
||||
ESCAPE_RMCUP, // "rmcup" leave alternate screen
|
||||
ESCAPE_SMXX, // "smxx" start struckout
|
||||
ESCAPE_RMXX, // "rmxx" end struckout
|
||||
ESCAPE_SC, // "sc" push the cursor onto the stack
|
||||
ESCAPE_RC, // "rc" pop the cursor off the stack
|
||||
ESCAPE_CLEAR, // "clear" clear screen and home cursor
|
||||
ESCAPE_HOME, // "home" home cursor
|
||||
ESCAPE_MAX
|
||||
} escape_e;
|
||||
|
||||
@ -62,11 +66,7 @@ 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* home; // home cursor
|
||||
char* initc; // set a palette entry's RGB value
|
||||
char* clearscr; // erase screen and home cursor
|
||||
char* sc; // push the cursor location onto the stack
|
||||
char* rc; // pop the cursor location off the stack
|
||||
char* getm; // get mouse events
|
||||
// we use the cell's size in pixels for pixel blitting. this information can
|
||||
// be acquired on all terminals with pixel support.
|
||||
|
Loading…
x
Reference in New Issue
Block a user