blob: d157d1dbada9178bd001a5362f43d643eecbd935 [file] [log] [blame]
Dejan Mircevskib6fe02f2016-01-07 13:44:22 -05001// Copyright (c) 2015-2016 The Khronos Group Inc.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01002//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and/or associated documentation files (the
5// "Materials"), to deal in the Materials without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Materials, and to
8// permit persons to whom the Materials are furnished to do so, subject to
9// the following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Materials.
13//
14// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
15// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
16// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
17// https://www.khronos.org/registry/
18//
19// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
26
27#include "print.h"
28
29#if defined(SPIRV_LINUX) || defined(SPIRV_MAC)
David Neto01656362015-11-20 10:44:41 -050030namespace libspirv {
31
Lei Zhang1a0334e2015-11-02 09:41:20 -050032clr::reset::operator const char*() { return "\e[0m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010033
Lei Zhang1a0334e2015-11-02 09:41:20 -050034clr::grey::operator const char*() { return "\e[1;30m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010035
Lei Zhang1a0334e2015-11-02 09:41:20 -050036clr::red::operator const char*() { return "\e[31m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010037
Lei Zhang1a0334e2015-11-02 09:41:20 -050038clr::green::operator const char*() { return "\e[32m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010039
Lei Zhang1a0334e2015-11-02 09:41:20 -050040clr::yellow::operator const char*() { return "\e[33m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010041
Lei Zhang1a0334e2015-11-02 09:41:20 -050042clr::blue::operator const char*() { return "\e[34m"; }
David Neto01656362015-11-20 10:44:41 -050043
44} // namespace libspirv
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010045#elif defined(SPIRV_WINDOWS)
46#include <Windows.h>
47
David Neto01656362015-11-20 10:44:41 -050048namespace libspirv {
49
Lei Zhang1a0334e2015-11-02 09:41:20 -050050clr::reset::operator const char*() {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010051 const DWORD color = 0Xf;
52 HANDLE hConsole;
53 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
54 SetConsoleTextAttribute(hConsole, color);
55 hConsole = GetStdHandle(STD_ERROR_HANDLE);
56 SetConsoleTextAttribute(hConsole, color);
57 return "";
58}
59
Lei Zhang1a0334e2015-11-02 09:41:20 -050060clr::grey::operator const char*() {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010061 const DWORD color = 0x8;
62 HANDLE hConsole;
63 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
64 SetConsoleTextAttribute(hConsole, color);
65 hConsole = GetStdHandle(STD_ERROR_HANDLE);
66 SetConsoleTextAttribute(hConsole, color);
67 return "";
68}
69
Lei Zhang1a0334e2015-11-02 09:41:20 -050070clr::red::operator const char*() {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010071 const DWORD color = 0x4;
72 HANDLE hConsole;
73 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
74 SetConsoleTextAttribute(hConsole, color);
75 hConsole = GetStdHandle(STD_ERROR_HANDLE);
76 SetConsoleTextAttribute(hConsole, color);
77 return "";
78}
79
Lei Zhang1a0334e2015-11-02 09:41:20 -050080clr::green::operator const char*() {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010081 const DWORD color = 0x2;
82 HANDLE hConsole;
83 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
84 SetConsoleTextAttribute(hConsole, color);
85 hConsole = GetStdHandle(STD_ERROR_HANDLE);
86 SetConsoleTextAttribute(hConsole, color);
87 return "";
88}
89
Lei Zhang1a0334e2015-11-02 09:41:20 -050090clr::yellow::operator const char*() {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010091 const DWORD color = 0x6;
92 HANDLE hConsole;
93 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
94 SetConsoleTextAttribute(hConsole, color);
95 hConsole = GetStdHandle(STD_ERROR_HANDLE);
96 SetConsoleTextAttribute(hConsole, color);
97 return "";
98}
99
Lei Zhang1a0334e2015-11-02 09:41:20 -0500100clr::blue::operator const char*() {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100101 const DWORD color = 0x1;
102 HANDLE hConsole;
103 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
104 SetConsoleTextAttribute(hConsole, color);
105 hConsole = GetStdHandle(STD_ERROR_HANDLE);
106 SetConsoleTextAttribute(hConsole, color);
107 return "";
108}
David Neto01656362015-11-20 10:44:41 -0500109
110} // namespace libspirv
Ben Vanik01c8d7a2015-11-22 08:32:53 -0800111#else
112namespace libspirv {
113
114clr::reset::operator const char*() { return ""; }
115
116clr::grey::operator const char*() { return ""; }
117
118clr::red::operator const char*() { return ""; }
119
120clr::green::operator const char*() { return ""; }
121
122clr::yellow::operator const char*() { return ""; }
123
124clr::blue::operator const char*() { return ""; }
125
126} // namespace libspirv
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100127#endif