implement NCOPTION_PRESERVE_CURSOR #1823

pull/1838/head
nick black 3 years ago committed by Nick Black
parent 9f92986a6b
commit e734409187

@ -825,7 +825,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
shortname_term = termname();
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8,
1, flags & NCDIRECT_OPTION_INHIBIT_CBREAK,
TERMINAL_UNKNOWN)){
TERMINAL_UNKNOWN, NULL, NULL)){
goto err;
}
if(ncvisual_init(NCLOGLEVEL_SILENT)){

@ -884,6 +884,9 @@ pump_control_read(query_state* inits, unsigned char c){
inits->state = STATE_SDA;
}else if(isdigit(c)){
inits->numeric = 0;
if(ruts_numeric(&inits->numeric, c)){
return -1;
}
inits->state = STATE_CURSOR;
}else if(c >= 0x40 && c <= 0x7E){
inits->state = STATE_NULL;
@ -891,7 +894,7 @@ pump_control_read(query_state* inits, unsigned char c){
break;
case STATE_CURSOR:
if(isdigit(c)){
if(ruts_hex(&inits->numeric, c)){
if(ruts_numeric(&inits->numeric, c)){
return -1;
}
}else if(c == ';'){
@ -904,7 +907,7 @@ pump_control_read(query_state* inits, unsigned char c){
break;
case STATE_CURSOR_COL:
if(isdigit(c)){
if(ruts_hex(&inits->numeric, c)){
if(ruts_numeric(&inits->numeric, c)){
return -1;
}
}else if(c == 'R'){
@ -1231,8 +1234,12 @@ int ncinputlayer_init(tinfo* tcache, FILE* infp, queried_terminals_e* detected,
tcache->termversion = inits.version;
*detected = inits.qterm;
*appsync = inits.appsync;
*cursor_x = inits.cursor_x;
*cursor_y = inits.cursor_y;
if(cursor_x){
*cursor_x = inits.cursor_x - 1;
}
if(cursor_y){
*cursor_y = inits.cursor_y - 1;
}
}
}
return 0;

@ -1097,9 +1097,12 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
}
const char* shortname_term = termname();
// const char* longname_term = longname();
int cursor_y, cursor_x;
if(interrogate_terminfo(&ret->tcache, ret->ttyfd, shortname_term, utf8,
opts->flags & NCOPTION_NO_ALTERNATE_SCREEN, 0,
detected_term)){
detected_term,
opts->flags & NCOPTION_PRESERVE_CURSOR ? &cursor_y : NULL,
opts->flags & NCOPTION_PRESERVE_CURSOR ? &cursor_x : NULL)){
goto err;
}
int dimy, dimx;
@ -1119,6 +1122,9 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
fprintf(stderr, "Couldn't create the initial plane (bad margins?)\n");
goto err;
}
if(cursor_y >= 0 && cursor_x >= 0){
ncplane_cursor_move_yx(ret->stdplane, cursor_y, cursor_x);
}
if(ret->ttyfd >= 0){
reset_term_attributes(&ret->tcache, ret->ttyfp);
if(!(opts->flags & NCOPTION_NO_CLEAR_BITMAPS)){

@ -334,7 +334,8 @@ apply_term_heuristics(tinfo* ti, const char* termname, int fd,
// full round trip before getting the reply, which is likely to pace init.
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
unsigned noaltscreen, unsigned nocbreak,
queried_terminals_e qterm){
queried_terminals_e qterm,
int* cursor_y, int* cursor_x){
memset(ti, 0, sizeof(*ti));
if(fd >= 0){
if(qterm == TERMINAL_UNKNOWN){
@ -504,9 +505,10 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
}
}
unsigned appsync_advertised;
int cursor_x = -1;
int cursor_y = -1;
if(ncinputlayer_init(ti, stdin, &qterm, &appsync_advertised, &cursor_y, &cursor_x)){
if(cursor_x && cursor_y){
*cursor_x = *cursor_y = 0;
}
if(ncinputlayer_init(ti, stdin, &qterm, &appsync_advertised, cursor_y, cursor_x)){
goto err;
}
if(nocbreak){
@ -517,11 +519,12 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
}
}
}
if(cursor_x >= 0 && cursor_y >= 0){
if(add_u7_escape(ti, &tablelen, &tableused)){
return -1;
if(cursor_x && cursor_y){
if(*cursor_x >= 0 && *cursor_y >= 0){
if(add_u7_escape(ti, &tablelen, &tableused)){
return -1;
}
}
// FIXME set cursor up
}
if(appsync_advertised){
if(add_appsync_escapes(ti, &tablelen, &tableused)){

@ -185,7 +185,8 @@ term_supported_styles(const tinfo* ti){
// TERMINAL_UNKNOWN.
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
unsigned noaltscreen, unsigned nocbreak,
queried_terminals_e qterm);
queried_terminals_e qterm,
int* cursor_y, int* cursor_x);
void free_terminfo_cache(tinfo* ti);

Loading…
Cancel
Save