Skip to content

Commit

Permalink
Remove duplicate is_tty check
Browse files Browse the repository at this point in the history
  • Loading branch information
janweinstock committed Mar 12, 2024
1 parent 52f1400 commit 49b7fd0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 16 deletions.
2 changes: 0 additions & 2 deletions include/mwr/core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ size_t fd_seek_end(int fd, off_t pos);
int fd_dup(int fd);
int fd_pipe(int fds[2]);

bool fd_isatty(int fd);

double timestamp();
u64 timestamp_ms();
u64 timestamp_us();
Expand Down
10 changes: 1 addition & 9 deletions src/mwr/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ size_t fd_read(int fd, void* buffer, size_t buflen) {
size_t numread = 0;

#ifdef MWR_MSVC
if (fd == STDIN_FDNO && fd_isatty(fd))
if (fd == STDIN_FDNO && _isatty(fd))
return msvc_read_console(ptr, buflen);
#endif

Expand Down Expand Up @@ -623,14 +623,6 @@ int fd_pipe(int fds[2]) {
#endif
}

bool fd_isatty(int fd) {
#ifdef MWR_MSVC
return _isatty(fd);
#else
return isatty(fd);
#endif
}

using timestamp_clock = chrono::steady_clock;
static auto g_start = timestamp_clock::now();

Expand Down
6 changes: 3 additions & 3 deletions src/mwr/logging/publishers/terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace mwr {
namespace publishers {

static bool supports_colors(bool use_cerr) {
int fd = use_cerr ? mwr::STDERR_FDNO : mwr::STDOUT_FDNO;
if (!mwr::fd_isatty(fd))
int fd = use_cerr ? STDERR_FDNO : STDOUT_FDNO;
if (!is_tty(fd))
return false;

auto env = mwr::getenv("TERM");
auto env = getenv("TERM");
if (!env)
return false;

Expand Down
2 changes: 0 additions & 2 deletions test/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ TEST(utils, fd_io) {
ASSERT_EQ(fd_read(fd, buffer, n), n);
EXPECT_STREQ(text, buffer);

EXPECT_FALSE(fd_isatty(fd));

fd_close(fd);
std::filesystem::remove_all("testfile");
}
Expand Down

0 comments on commit 49b7fd0

Please sign in to comment.