|
|
|
@ -819,6 +819,28 @@ get_tty_fd(notcurses* nc, FILE* ttyfp){
|
|
|
|
|
return fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cbreak_mode(int ttyfd, struct termios* tpreserved){
|
|
|
|
|
if(tcgetattr(ttyfd, tpreserved)){
|
|
|
|
|
fprintf(stderr, "Couldn't preserve terminal state for %d (%s)\n", ttyfd, strerror(errno));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// assume it's not a true terminal (e.g. we might be redirected to a file)
|
|
|
|
|
struct termios modtermios;
|
|
|
|
|
memcpy(&modtermios, tpreserved, sizeof(modtermios));
|
|
|
|
|
// see termios(3). disabling ECHO and ICANON means input will not be echoed
|
|
|
|
|
// to the screen, input is made available without enter-based buffering, and
|
|
|
|
|
// line editing is disabled. since we have not gone into raw mode, ctrl+c
|
|
|
|
|
// etc. still have their typical effects. ICRNL maps return to 13 (Ctrl+M)
|
|
|
|
|
// instead of 10 (Ctrl+J).
|
|
|
|
|
modtermios.c_lflag &= (~ECHO & ~ICANON);
|
|
|
|
|
modtermios.c_iflag &= (~ICRNL);
|
|
|
|
|
if(tcsetattr(ttyfd, TCSANOW, &modtermios)){
|
|
|
|
|
fprintf(stderr, "Error disabling echo / canonical on %d (%s)\n", ttyfd, strerror(errno));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
|
|
|
|
|
notcurses_options defaultopts;
|
|
|
|
|
memset(&defaultopts, 0, sizeof(defaultopts));
|
|
|
|
@ -893,27 +915,9 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
|
|
|
|
|
is_linux_console(ret, !!(opts->flags & NCOPTION_NO_FONT_CHANGES));
|
|
|
|
|
notcurses_mouse_disable(ret);
|
|
|
|
|
if(ret->ttyfd >= 0){
|
|
|
|
|
if(tcgetattr(ret->ttyfd, &ret->tpreserved)){
|
|
|
|
|
logerror(ret, "Couldn't preserve terminal state for %d (%s)\n", ret->ttyfd, strerror(errno));
|
|
|
|
|
if(cbreak_mode(ret->ttyfd, &ret->tpreserved)){
|
|
|
|
|
free(ret);
|
|
|
|
|
return NULL;
|
|
|
|
|
// assume it's not a true terminal (e.g. we might be redirected to a file)
|
|
|
|
|
}else{
|
|
|
|
|
struct termios modtermios;
|
|
|
|
|
memcpy(&modtermios, &ret->tpreserved, sizeof(modtermios));
|
|
|
|
|
// see termios(3). disabling ECHO and ICANON means input will not be echoed
|
|
|
|
|
// to the screen, input is made available without enter-based buffering, and
|
|
|
|
|
// line editing is disabled. since we have not gone into raw mode, ctrl+c
|
|
|
|
|
// etc. still have their typical effects. ICRNL maps return to 13 (Ctrl+M)
|
|
|
|
|
// instead of 10 (Ctrl+J).
|
|
|
|
|
modtermios.c_lflag &= (~ECHO & ~ICANON);
|
|
|
|
|
modtermios.c_iflag &= (~ICRNL);
|
|
|
|
|
if(tcsetattr(ret->ttyfd, TCSANOW, &modtermios)){
|
|
|
|
|
fprintf(stderr, "Error disabling echo / canonical on %d (%s)\n",
|
|
|
|
|
ret->ttyfd, strerror(errno));
|
|
|
|
|
free(ret);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(setup_signals(ret,
|
|
|
|
|