Skip to content

Commit

Permalink
transition to alternate screen in interrogate_terminfo() #2131
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Sep 2, 2021
1 parent 75ed067 commit c7bb420
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
27 changes: 8 additions & 19 deletions src/lib/notcurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,26 +1229,15 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
if(set_fd_nonblocking(ret->tcache.input.infd, 1, &ret->stdio_blocking_save)){
goto err;
}
// if not connected to an actual terminal, we're not going to try entering
// the alternate screen; we're not even going to bother clearing the screen.
if(ret->tcache.ttyfd >= 0){
if(!(opts->flags & NCOPTION_NO_ALTERNATE_SCREEN)){
const char* smcup = get_escape(&ret->tcache, ESCAPE_SMCUP);
if(smcup){
if(enter_alternate_screen(ret->ttyfp, &ret->tcache, false)){
free_plane(ret->stdplane);
goto err;
}
}
// perform an explicit clear since the alternate screen was requested
// (smcup *might* clear, but who knows? and it might not have been
// available in any case).
if(clear_and_home(ret, &ret->tcache, &ret->rstate.f)){
goto err;
}
// no need to reestablish a preserved cursor -- that only affects the
// standard plane, not the physical cursor that was just disrupted.
if(!(opts->flags & NCOPTION_NO_ALTERNATE_SCREEN)){
// perform an explicit clear since the alternate screen was requested
// (smcup *might* clear, but who knows? and it might not have been
// available in any case).
if(clear_and_home(ret, &ret->tcache, &ret->rstate.f)){
goto err;
}
// no need to reestablish a preserved cursor -- that only affects the
// standard plane, not the physical cursor that was just disrupted.
}
// the sprite clear ought take place within the alternate screen, if it's
// being used.
Expand Down
33 changes: 28 additions & 5 deletions src/lib/termdesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,31 @@ init_terminfo_esc(tinfo* ti, const char* name, escape_e idx,
GEOMCELL \
PRIDEVATTR

// enter the alternate screen (smcup). we could technically get this from
// terminfo, but everyone who supports it supports it the same way, and we
// need to send it before our other directives if we're going to use it.
#define SMCUP "\x1b[?1049h"

// we send an XTSMGRAPHICS to set up 256 color registers (the most we can
// currently take advantage of; we need at least 64 to use sixel at all).
// maybe that works, maybe it doesn't. then query both color registers
// and geometry. send XTGETTCAP for terminal name. if 'minimal' is set, don't
// send any identification queries (we've already identified the terminal).
static int
send_initial_queries(int fd, bool minimal){
send_initial_queries(int fd, bool minimal, bool noaltscreen){
const char *queries;
if(minimal){
queries = DSRCPR DIRECTIVES;
if(noaltscreen){
if(minimal){
queries = DSRCPR DIRECTIVES;
}else{
queries = DSRCPR IDQUERIES DIRECTIVES;
}
}else{
queries = DSRCPR IDQUERIES DIRECTIVES;
if(minimal){
queries = SMCUP DSRCPR DIRECTIVES;
}else{
queries = SMCUP DSRCPR IDQUERIES DIRECTIVES;
}
}
size_t len = strlen(queries);
loginfo("sending %lluB queries\n", (unsigned long long)len);
Expand Down Expand Up @@ -751,10 +764,11 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut
free(ti->tpreserved);
return -1;
}
// FIXME need to enter alternate screen here
// if we already know our terminal (e.g. on the linux console), there's no
// need to send the identification queries. the controls are sufficient.
bool minimal = (ti->qterm != TERMINAL_UNKNOWN);
if(send_initial_queries(ti->ttyfd, minimal)){
if(send_initial_queries(ti->ttyfd, minimal, noaltscreen)){
free(ti->tpreserved);
goto err;
}
Expand Down Expand Up @@ -859,6 +873,15 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut
init_terminfo_esc(ti, "rmcup", ESCAPE_RMCUP, &tablelen, &tableused)){
goto err;
}
const char* smcup = get_escape(ti, ESCAPE_SMCUP);
if(smcup){
ti->in_alt_screen = 1;
// if we're not using the standard smcup, our initial hardcoded use of it
// presumably had no effect; warn the user.
if(strcmp(smcup, SMCUP)){
logwarn("warning: non-standard smcup!\n");
}
}
}else{
ti->escindices[ESCAPE_SMCUP] = 0;
ti->escindices[ESCAPE_RMCUP] = 0;
Expand Down

0 comments on commit c7bb420

Please sign in to comment.