Skip to content

Commit 39afe42

Browse files
committed
Only enable colors on terminals
1 parent b9b97b5 commit 39afe42

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

include/formatters/formatters_base.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
/** @file */
22
#pragma once
33

4+
#include <cstdio>
45
#include <iostream>
56
#include <string>
67

7-
#include "term_colors.hpp"
8-
8+
extern "C" {
9+
#ifdef _WIN32
10+
#include <io.h>
11+
#else
12+
#include <unistd.h>
13+
#endif
14+
}
915

1016
namespace CppSpec {
1117
class Description;
1218
class ItBase;
1319

20+
inline bool is_terminal() {
21+
return _isatty(_fileno(stdout)) != 0;
22+
}
1423
namespace Formatters {
1524

1625
class BaseFormatter {
@@ -21,7 +30,7 @@ class BaseFormatter {
2130
bool color_output;
2231

2332
public:
24-
explicit BaseFormatter(std::ostream &out_stream = std::cout, bool color = true)
33+
explicit BaseFormatter(std::ostream &out_stream = std::cout, bool color = is_terminal())
2534
: out_stream(out_stream), color_output(color) {}
2635
BaseFormatter(const BaseFormatter &) = default;
2736
BaseFormatter(const BaseFormatter &copy, std::ostream &out_stream)

include/formatters/progress.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string>
77

88
#include "verbose.hpp"
9+
#include "term_colors.hpp"
910

1011
namespace CppSpec::Formatters {
1112

include/formatters/tap.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "class_description.hpp"
88
#include "formatters_base.hpp"
9+
#include "term_colors.hpp"
910

1011
namespace CppSpec::Formatters {
1112

include/formatters/verbose.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "class_description.hpp"
99
#include "formatters_base.hpp"
1010
#include "it_base.hpp"
11+
#include "term_colors.hpp"
1112

1213
namespace CppSpec::Formatters {
1314

0 commit comments

Comments
 (0)