blob: 8d70ea00350a1fe47508ecffbe75bb378efa20fb [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//
David Neto9fc86582016-09-01 15:33:59 -04003// 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
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01006//
David Neto9fc86582016-09-01 15:33:59 -04007// http://www.apache.org/licenses/LICENSE-2.0
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01008//
David Neto9fc86582016-09-01 15:33:59 -04009// 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.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010014
15#include "print.h"
16
rdbddf4de62017-05-28 23:19:58 +020017#if defined(SPIRV_ANDROID) || defined(SPIRV_LINUX) || defined(SPIRV_MAC) || defined(SPIRV_FREEBSD)
David Neto01656362015-11-20 10:44:41 -050018namespace libspirv {
19
Andrew Woloszyn4c657bf2016-03-18 14:13:16 -040020clr::reset::operator const char*() { return "\x1b[0m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010021
Andrew Woloszyn4c657bf2016-03-18 14:13:16 -040022clr::grey::operator const char*() { return "\x1b[1;30m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010023
Andrew Woloszyn4c657bf2016-03-18 14:13:16 -040024clr::red::operator const char*() { return "\x1b[31m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010025
Andrew Woloszyn4c657bf2016-03-18 14:13:16 -040026clr::green::operator const char*() { return "\x1b[32m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010027
Andrew Woloszyn4c657bf2016-03-18 14:13:16 -040028clr::yellow::operator const char*() { return "\x1b[33m"; }
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010029
Andrew Woloszyn4c657bf2016-03-18 14:13:16 -040030clr::blue::operator const char*() { return "\x1b[34m"; }
David Neto01656362015-11-20 10:44:41 -050031
32} // namespace libspirv
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010033#elif defined(SPIRV_WINDOWS)
David Neto7c58c1d2016-02-29 01:01:04 -050034#include <windows.h>
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010035
David Neto01656362015-11-20 10:44:41 -050036namespace libspirv {
37
Lukas Hermanns4fe8e382017-08-20 14:11:50 +020038static void SetConsoleForegroundColorPrimary(HANDLE hConsole, WORD color)
39{
40 // Get screen buffer information from console handle
41 CONSOLE_SCREEN_BUFFER_INFO bufInfo;
42 GetConsoleScreenBufferInfo(hConsole, &bufInfo);
43
44 // Get background color
45 color |= (bufInfo.wAttributes & 0xfff0);
46
47 // Set foreground color
48 SetConsoleTextAttribute(hConsole, color);
49}
50
51static void SetConsoleForegroundColor(WORD color)
52{
53 SetConsoleForegroundColorPrimary(GetStdHandle(STD_OUTPUT_HANDLE), color);
54 SetConsoleForegroundColorPrimary(GetStdHandle(STD_ERROR_HANDLE), color);
55}
56
Lei Zhang1a0334e2015-11-02 09:41:20 -050057clr::reset::operator const char*() {
Lukas Hermanns4fe8e382017-08-20 14:11:50 +020058 SetConsoleForegroundColor(0xf);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010059 return "";
60}
61
Lei Zhang1a0334e2015-11-02 09:41:20 -050062clr::grey::operator const char*() {
Lukas Hermanns4fe8e382017-08-20 14:11:50 +020063 SetConsoleForegroundColor(FOREGROUND_INTENSITY);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010064 return "";
65}
66
Lei Zhang1a0334e2015-11-02 09:41:20 -050067clr::red::operator const char*() {
Lukas Hermanns4fe8e382017-08-20 14:11:50 +020068 SetConsoleForegroundColor(FOREGROUND_RED);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010069 return "";
70}
71
Lei Zhang1a0334e2015-11-02 09:41:20 -050072clr::green::operator const char*() {
Lukas Hermanns4fe8e382017-08-20 14:11:50 +020073 SetConsoleForegroundColor(FOREGROUND_GREEN);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010074 return "";
75}
76
Lei Zhang1a0334e2015-11-02 09:41:20 -050077clr::yellow::operator const char*() {
Lukas Hermanns4fe8e382017-08-20 14:11:50 +020078 SetConsoleForegroundColor(FOREGROUND_RED | FOREGROUND_GREEN);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010079 return "";
80}
81
Lei Zhang1a0334e2015-11-02 09:41:20 -050082clr::blue::operator const char*() {
David Neto01677582017-08-24 10:34:00 -040083 // Blue all by itself is hard to see against a black background (the
84 // default on command shell), or a medium blue background (the default
85 // on PowerShell). So increase its intensity.
86 SetConsoleForegroundColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010087 return "";
88}
David Neto01656362015-11-20 10:44:41 -050089
90} // namespace libspirv
Ben Vanik01c8d7a2015-11-22 08:32:53 -080091#else
92namespace libspirv {
93
94clr::reset::operator const char*() { return ""; }
95
96clr::grey::operator const char*() { return ""; }
97
98clr::red::operator const char*() { return ""; }
99
100clr::green::operator const char*() { return ""; }
101
102clr::yellow::operator const char*() { return ""; }
103
104clr::blue::operator const char*() { return ""; }
105
106} // namespace libspirv
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100107#endif