is_test_tty: check for /dev/tty #1668

pull/1670/head
nick black 3 years ago committed by Nick Black
parent a903f32cd6
commit 0b197fe19b

@ -1293,9 +1293,6 @@ void nclog(const char* fmt, ...);
bool is_linux_console(const notcurses* nc, unsigned no_font_changes); 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 // logging
#define logerror(nc, fmt, ...) do{ \ #define logerror(nc, fmt, ...) do{ \
if(nc){ if((nc)->loglevel >= NCLOGLEVEL_ERROR){ \ if(nc){ if((nc)->loglevel >= NCLOGLEVEL_ERROR){ \

@ -105,7 +105,7 @@ TEST_CASE("DirectMode") {
} }
SUBCASE("CursorPostGlyphRender") { SUBCASE("CursorPostGlyphRender") {
if(is_test_tty(stdout)){ if(is_test_tty()){
auto dirf = ncdirectf_from_file(nc_, find_data("worldmap.png")); auto dirf = ncdirectf_from_file(nc_, find_data("worldmap.png"));
REQUIRE(nullptr != dirf); REQUIRE(nullptr != dirf);
auto ncdv = ncdirectf_render(nc_, dirf, NCBLIT_1x1, NCSCALE_NONE, 0, 0); auto ncdv = ncdirectf_render(nc_, dirf, NCBLIT_1x1, NCSCALE_NONE, 0, 0);
@ -124,7 +124,7 @@ TEST_CASE("DirectMode") {
} }
SUBCASE("CursorPostSprixel") { SUBCASE("CursorPostSprixel") {
if(is_test_tty(stdout)){ if(is_test_tty()){
if(ncdirect_check_pixel_support(nc_) > 0){ if(ncdirect_check_pixel_support(nc_) > 0){
auto dirf = ncdirectf_from_file(nc_, find_data("worldmap.png")); auto dirf = ncdirectf_from_file(nc_, find_data("worldmap.png"));
REQUIRE(nullptr != dirf); REQUIRE(nullptr != dirf);

@ -31,15 +31,14 @@ auto find_data(const char* datum) -> char* {
return strdup(p.c_str()); return strdup(p.c_str());
} }
auto is_test_tty(FILE* fp) -> bool { auto is_test_tty() -> bool {
int fd = fileno(fp); int fd = open("/dev/tty", O_RDWR);
if(fd >= 0){ if(fd < 0){
if(isatty(fd)){
return true;
}
}
return false; return false;
} }
close(fd);
return true;
}
static void static void
handle_opts(const char** argv){ handle_opts(const char** argv){

@ -10,7 +10,7 @@
#include <ncpp/_exceptions.hh> #include <ncpp/_exceptions.hh>
#include "internal.h" #include "internal.h"
auto is_test_tty(FILE* fp) -> bool; auto is_test_tty() -> bool;
auto find_data(const char* datum) -> char*; auto find_data(const char* datum) -> char*;
auto testing_notcurses() -> struct notcurses*; auto testing_notcurses() -> struct notcurses*;
auto ncreel_validate(const ncreel* n) -> bool; auto ncreel_validate(const ncreel* n) -> bool;

Loading…
Cancel
Save