• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015-2016 The Khronos Group Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "print.h"
16 
17 #if defined(SPIRV_ANDROID) || defined(SPIRV_LINUX) || defined(SPIRV_MAC) || defined(SPIRV_FREEBSD)
18 namespace libspirv {
19 
operator const char*()20 clr::reset::operator const char*() { return "\x1b[0m"; }
21 
operator const char*()22 clr::grey::operator const char*() { return "\x1b[1;30m"; }
23 
operator const char*()24 clr::red::operator const char*() { return "\x1b[31m"; }
25 
operator const char*()26 clr::green::operator const char*() { return "\x1b[32m"; }
27 
operator const char*()28 clr::yellow::operator const char*() { return "\x1b[33m"; }
29 
operator const char*()30 clr::blue::operator const char*() { return "\x1b[34m"; }
31 
32 }  // namespace libspirv
33 #elif defined(SPIRV_WINDOWS)
34 #include <windows.h>
35 
36 namespace libspirv {
37 
operator const char*()38 clr::reset::operator const char*() {
39   const DWORD color = 0Xf;
40   HANDLE hConsole;
41   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
42   SetConsoleTextAttribute(hConsole, color);
43   hConsole = GetStdHandle(STD_ERROR_HANDLE);
44   SetConsoleTextAttribute(hConsole, color);
45   return "";
46 }
47 
operator const char*()48 clr::grey::operator const char*() {
49   const DWORD color = 0x8;
50   HANDLE hConsole;
51   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
52   SetConsoleTextAttribute(hConsole, color);
53   hConsole = GetStdHandle(STD_ERROR_HANDLE);
54   SetConsoleTextAttribute(hConsole, color);
55   return "";
56 }
57 
operator const char*()58 clr::red::operator const char*() {
59   const DWORD color = 0x4;
60   HANDLE hConsole;
61   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
62   SetConsoleTextAttribute(hConsole, color);
63   hConsole = GetStdHandle(STD_ERROR_HANDLE);
64   SetConsoleTextAttribute(hConsole, color);
65   return "";
66 }
67 
operator const char*()68 clr::green::operator const char*() {
69   const DWORD color = 0x2;
70   HANDLE hConsole;
71   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
72   SetConsoleTextAttribute(hConsole, color);
73   hConsole = GetStdHandle(STD_ERROR_HANDLE);
74   SetConsoleTextAttribute(hConsole, color);
75   return "";
76 }
77 
operator const char*()78 clr::yellow::operator const char*() {
79   const DWORD color = 0x6;
80   HANDLE hConsole;
81   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
82   SetConsoleTextAttribute(hConsole, color);
83   hConsole = GetStdHandle(STD_ERROR_HANDLE);
84   SetConsoleTextAttribute(hConsole, color);
85   return "";
86 }
87 
operator const char*()88 clr::blue::operator const char*() {
89   const DWORD color = 0x1;
90   HANDLE hConsole;
91   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
92   SetConsoleTextAttribute(hConsole, color);
93   hConsole = GetStdHandle(STD_ERROR_HANDLE);
94   SetConsoleTextAttribute(hConsole, color);
95   return "";
96 }
97 
98 }  // namespace libspirv
99 #else
100 namespace libspirv {
101 
operator const char*()102 clr::reset::operator const char*() { return ""; }
103 
operator const char*()104 clr::grey::operator const char*() { return ""; }
105 
operator const char*()106 clr::red::operator const char*() { return ""; }
107 
operator const char*()108 clr::green::operator const char*() { return ""; }
109 
operator const char*()110 clr::yellow::operator const char*() { return ""; }
111 
operator const char*()112 clr::blue::operator const char*() { return ""; }
113 
114 }  // namespace libspirv
115 #endif
116