From 0b197fe19b5e9cfc83bdc4298b5e8ac41dd474c6 Mon Sep 17 00:00:00 2001 From: nick black Date: Mon, 17 May 2021 19:15:43 -0400 Subject: [PATCH] is_test_tty: check for /dev/tty #1668 --- src/lib/internal.h | 3 --- src/tests/direct.cpp | 4 ++-- src/tests/main.cpp | 13 ++++++------- src/tests/main.h | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index 4184fc5f4..3b5f7c8b2 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -1293,9 +1293,6 @@ void nclog(const char* fmt, ...); bool is_linux_console(const notcurses* nc, unsigned no_font_changes); -// get a file descriptor for the controlling tty device, -1 on error -int get_controlling_tty(FILE* fp); - // logging #define logerror(nc, fmt, ...) do{ \ if(nc){ if((nc)->loglevel >= NCLOGLEVEL_ERROR){ \ diff --git a/src/tests/direct.cpp b/src/tests/direct.cpp index 49dcc3db1..771474d02 100644 --- a/src/tests/direct.cpp +++ b/src/tests/direct.cpp @@ -105,7 +105,7 @@ TEST_CASE("DirectMode") { } SUBCASE("CursorPostGlyphRender") { - if(is_test_tty(stdout)){ + if(is_test_tty()){ auto dirf = ncdirectf_from_file(nc_, find_data("worldmap.png")); REQUIRE(nullptr != dirf); auto ncdv = ncdirectf_render(nc_, dirf, NCBLIT_1x1, NCSCALE_NONE, 0, 0); @@ -124,7 +124,7 @@ TEST_CASE("DirectMode") { } SUBCASE("CursorPostSprixel") { - if(is_test_tty(stdout)){ + if(is_test_tty()){ if(ncdirect_check_pixel_support(nc_) > 0){ auto dirf = ncdirectf_from_file(nc_, find_data("worldmap.png")); REQUIRE(nullptr != dirf); diff --git a/src/tests/main.cpp b/src/tests/main.cpp index 5cc0eb42a..8c69606ff 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -31,14 +31,13 @@ auto find_data(const char* datum) -> char* { return strdup(p.c_str()); } -auto is_test_tty(FILE* fp) -> bool { - int fd = fileno(fp); - if(fd >= 0){ - if(isatty(fd)){ - return true; - } +auto is_test_tty() -> bool { + int fd = open("/dev/tty", O_RDWR); + if(fd < 0){ + return false; } - return false; + close(fd); + return true; } static void diff --git a/src/tests/main.h b/src/tests/main.h index 01a697847..a8eec2b66 100644 --- a/src/tests/main.h +++ b/src/tests/main.h @@ -10,7 +10,7 @@ #include #include "internal.h" -auto is_test_tty(FILE* fp) -> bool; +auto is_test_tty() -> bool; auto find_data(const char* datum) -> char*; auto testing_notcurses() -> struct notcurses*; auto ncreel_validate(const ncreel* n) -> bool;