unify preserved termios between direct/rendered mode

pull/1693/head
nick black 3 years ago
parent 73913c3f1a
commit d902dae60b
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -724,7 +724,7 @@ ncdirect_stop_minimal(void* vnc){
if(cnorm && tty_emit(cnorm, nc->ctermfd)){
ret = -1;
}
ret |= tcsetattr(nc->ctermfd, TCSANOW, &nc->tpreserved);
ret |= tcsetattr(nc->ctermfd, TCSANOW, &nc->tcache.tpreserved);
ret |= close(nc->ctermfd);
}
ret |= ncdirect_flush(nc);
@ -761,12 +761,12 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
}
// we don't need a controlling tty for everything we do; allow a failure here
if((ret->ctermfd = get_tty_fd(NULL, ret->ttyfp)) >= 0){
if(tcgetattr(ret->ctermfd, &ret->tpreserved)){
if(tcgetattr(ret->ctermfd, &ret->tcache.tpreserved)){
fprintf(stderr, "Couldn't preserve terminal state for %d (%s)\n", ret->ctermfd, strerror(errno));
goto err;
}
if(!(flags & NCDIRECT_OPTION_INHIBIT_CBREAK)){
if(cbreak_mode(ret->ctermfd, &ret->tpreserved)){
if(cbreak_mode(ret->ctermfd, &ret->tcache.tpreserved)){
goto err;
}
}
@ -793,7 +793,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
err:
if(ret->ctermfd >= 0){
tcsetattr(ret->ctermfd, TCSANOW, &ret->tpreserved);
tcsetattr(ret->ctermfd, TCSANOW, &ret->tcache.tpreserved);
}
drop_signals(ret);
free(ret);

@ -19,7 +19,6 @@ extern "C" {
#include <signal.h>
#include <wctype.h>
#include <pthread.h>
#include <termios.h>
#include <stdbool.h>
#include <unictype.h>
#include <langinfo.h>
@ -423,7 +422,6 @@ typedef struct ncdirect {
uint64_t channels; // current channels
uint16_t stylemask; // current styles
ncinputlayer input; // input layer; we're in cbreak mode
struct termios tpreserved; // terminal state upon entry
// some terminals (e.g. kmscon) return cursor coordinates inverted from the
// typical order. we detect it the first time ncdirect_cursor_yx() is called.
bool detected_cursor_inversion; // have we performed inversion testing?
@ -506,7 +504,6 @@ typedef struct notcurses {
ncinputlayer input; // input layer; we're in cbreak mode
FILE* renderfp; // debugging FILE* to which renderings are written
tinfo tcache; // terminfo cache
struct termios tpreserved; // terminal state upon entry
pthread_mutex_t pilelock; // guards pile list, locks resize in render
bool suppress_banner; // from notcurses_options

@ -84,7 +84,7 @@ notcurses_stop_minimal(void* vnc){
if(cnorm && tty_emit(cnorm, nc->ttyfd)){
ret = -1;
}
ret |= tcsetattr(nc->ttyfd, TCSANOW, &nc->tpreserved);
ret |= tcsetattr(nc->ttyfd, TCSANOW, &nc->tcache.tpreserved);
}
return ret;
}
@ -1022,12 +1022,12 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
ret->ttyfd = get_tty_fd(ret, ret->ttyfp);
is_linux_console(ret, !!(opts->flags & NCOPTION_NO_FONT_CHANGES));
if(ret->ttyfd >= 0){
if(tcgetattr(ret->ttyfd, &ret->tpreserved)){
if(tcgetattr(ret->ttyfd, &ret->tcache.tpreserved)){
fprintf(stderr, "Couldn't preserve terminal state for %d (%s)\n", ret->ttyfd, strerror(errno));
free(ret);
return NULL;
}
if(cbreak_mode(ret->ttyfd, &ret->tpreserved)){
if(cbreak_mode(ret->ttyfd, &ret->tcache.tpreserved)){
free(ret);
return NULL;
}
@ -1138,7 +1138,7 @@ err:
fclose(ret->rstate.mstreamfp);
}
free(ret->rstate.mstream);
tcsetattr(ret->ttyfd, TCSANOW, &ret->tpreserved);
tcsetattr(ret->ttyfd, TCSANOW, &ret->tcache.tpreserved);
drop_signals(ret);
pthread_mutex_destroy(&ret->statlock);
pthread_mutex_destroy(&ret->pilelock);

@ -8,6 +8,7 @@ extern "C" {
// internal header, not installed
#include <stdbool.h>
#include <termios.h>
struct ncpile;
struct sprixel;
@ -125,6 +126,8 @@ typedef struct tinfo {
// mlterm resets the cursor (i.e. makes it visible) any time you print
// a sprixel. we work around this spiritedly unorthodox decision.
bool sprixel_cursor_hack; // do sprixels reset the cursor? (mlterm)
struct termios tpreserved; // terminal state upon entry
} tinfo;
// retrieve the terminfo(5)-style escape 'e' from tdesc (NULL if undefined).

Loading…
Cancel
Save