tester: better terminal restoration #240

pull/531/head
nick black 5 years ago
parent fe8034b5e0
commit 6304bc73e3
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -98,6 +98,22 @@ TEST_CASE("FdsAndSubprocs") {
lock.unlock();
}
SUBCASE("SubprocDestroyOffline") {
char * const argv[] = { strdup("/bin/cat"), strdup("/etc/sysctl.conf"), NULL, };
REQUIRE(!outofline_cancelled);
ncsubproc_options opts{};
auto ncsubp = ncsubproc_createvp(n_, &opts, argv[0], argv, testfdcb, testfdeof);
REQUIRE(ncsubp);
std::unique_lock<std::mutex> lck(lock);
CHECK(0 == notcurses_render(nc_));
while(!outofline_cancelled){
cond.wait(lck);
}
CHECK(0 == ncsubproc_destroy(ncsubp));
CHECK(0 == notcurses_render(nc_));
lock.unlock();
}
CHECK(0 == notcurses_stop(nc_));
CHECK(0 == fclose(outfp_));
}

@ -1,9 +1,12 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include <term.h>
#include <fcntl.h>
#include <clocale>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <limits.h>
#include <termios.h>
#include <langinfo.h>
#include "version.h"
#include "main.h"
@ -44,16 +47,24 @@ handle_opts(const char** argv){
}
// reset the terminal in the event of early exit (notcurses_init() presumably
// ran, but we don't have the notcurses struct with which to run
// notcurses_stop()). so just whip up a new one, and free it immediately.
// ran, but we don't have the notcurses struct to destroy. so just do it raw.
static void
reset_terminal(){
// FIXME much more robust to just use termios here
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
auto nc = notcurses_init(&nopts, NULL);
if(nc){
notcurses_stop(nc);
int fd = open("/dev/tty", O_RDWR|O_CLOEXEC);
if(fd >= 0){
struct termios tios;
if(tcgetattr(fd, &tios) == 0){
tios.c_iflag |= INLCR;
tios.c_lflag |= ISIG | ICANON | ECHO;
tcsetattr(fd, TCSADRAIN, &tios);
}
char* str = tigetstr("sgr0");
if(str){
printf("%s", str);
free(str);
}
fflush(stdout);
close(fd);
}
}
@ -82,7 +93,6 @@ int main(int argc, const char **argv){
}
doctest::Context context;
// defaults
context.setOption("order-by", "name"); // sort the test cases by their name
context.applyCommandLine(argc, argv);

Loading…
Cancel
Save