summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDavid Neto <dneto@google.com>2017-08-28 10:30:58 -0400
committerDavid Neto <dneto@google.com>2017-08-28 19:14:48 -0400
commit1687bd32357154c2508701f8b5d9a26b4a3858cb (patch)
treee1a0cb368062204492d775bc757c6275b1c6a771 /tools
parentd41a52415aa1786ef0c90cf345f863392fedb69f (diff)
downloadSPIRV-Tools-1687bd32357154c2508701f8b5d9a26b4a3858cb.tar.gz
SPIRV-Tools-1687bd32357154c2508701f8b5d9a26b4a3858cb.tar.bz2
SPIRV-Tools-1687bd32357154c2508701f8b5d9a26b4a3858cb.zip
Disassembler: Print colour codes only when writing to a terminal
Diffstat (limited to 'tools')
-rw-r--r--tools/dis/dis.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/tools/dis/dis.cpp b/tools/dis/dis.cpp
index 226f733a..9c14b07a 100644
--- a/tools/dis/dis.cpp
+++ b/tools/dis/dis.cpp
@@ -12,6 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+#include <stdio.h> // Need fileno
+#include <unistd.h>
+#endif
+
#include <cstdio>
#include <cstring>
#include <string>
@@ -39,7 +44,8 @@ Options:
not specified, or if the filename is "-".
--no-color Don't print in color.
- The default when output goes to a file.
+ The default when output goes to something other than a
+ terminal (e.g. a file, a pipe, or a shell redirection).
--no-indent Don't indent instructions.
@@ -142,7 +148,11 @@ int main(int argc, char** argv) {
if (!outFile || (0 == strcmp("-", outFile))) {
// Print to standard output.
options |= SPV_BINARY_TO_TEXT_OPTION_PRINT;
- if (allow_color) {
+ bool output_is_tty = true;
+#if defined(_POSIX_VERSION)
+ output_is_tty = isatty(fileno(stdout));
+#endif
+ if (allow_color && output_is_tty) {
options |= SPV_BINARY_TO_TEXT_OPTION_COLOR;
}
}