Skip to content

Commit

Permalink
Assume . if either stdin/on isatty() (fix #1028)
Browse files Browse the repository at this point in the history
And move the #define of isatty on Windows up.
  • Loading branch information
nicowilliams committed Dec 2, 2015
1 parent 0d177d2 commit 5fe0536
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
#include <wtypes.h>
#endif

#if !defined(HAVE_ISATTY) && defined(HAVE__ISATTY)
#undef isatty
#define isatty _isatty
#endif

#if defined(HAVE_ISATTY) || defined(HAVE__ISATTY)
#define USE_ISATTY
#endif

#include "compile.h"
#include "jv.h"
#include "jq.h"
Expand Down Expand Up @@ -423,14 +432,16 @@ int main(int argc, char* argv[]) {
}
}

if (isatty(fileno(stdout))) {
#ifdef USE_ISATTY
if (isatty(STDOUT_FILENO)) {
dumpopts |= JV_PRINT_ISATTY;
#ifndef WIN32
/* Disable color by default on Windows builds as Windows
terminals tend not to display it correctly */
dumpopts |= JV_PRINT_COLOR;
#endif
}
#endif
if (options & SORTED_OUTPUT) dumpopts |= JV_PRINT_SORTED;
if (options & ASCII_OUTPUT) dumpopts |= JV_PRINT_ASCII;
if (options & COLOR_OUTPUT) dumpopts |= JV_PRINT_COLOR;
Expand All @@ -457,14 +468,8 @@ int main(int argc, char* argv[]) {
else
jq_set_attr(jq, jv_string("VERSION_DIR"), jv_string_fmt("%.*s-master", (int)(strchr(JQ_VERSION, '-') - JQ_VERSION), JQ_VERSION));

#if (!defined(WIN32) && defined(HAVE_ISATTY)) || defined(HAVE__ISATTY)

#if defined(HAVE__ISATTY) && defined(isatty)
#undef isatty
#define isatty _isatty
#endif

if (!program && isatty(STDOUT_FILENO) && !isatty(STDIN_FILENO))
#ifdef USE_ISATTY
if (!program && (!isatty(STDOUT_FILENO) || !isatty(STDIN_FILENO)))
program = ".";
#endif

Expand Down

0 comments on commit 5fe0536

Please sign in to comment.