1fd4e5da5Sopenharmony_ci// Copyright (c) 2015-2016 The Khronos Group Inc. 2fd4e5da5Sopenharmony_ci// 3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 6fd4e5da5Sopenharmony_ci// 7fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8fd4e5da5Sopenharmony_ci// 9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 13fd4e5da5Sopenharmony_ci// limitations under the License. 14fd4e5da5Sopenharmony_ci 15fd4e5da5Sopenharmony_ci#include "source/print.h" 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci#if defined(SPIRV_ANDROID) || defined(SPIRV_LINUX) || defined(SPIRV_MAC) || \ 18fd4e5da5Sopenharmony_ci defined(SPIRV_IOS) || defined(SPIRV_TVOS) || defined(SPIRV_FREEBSD) || \ 19fd4e5da5Sopenharmony_ci defined(SPIRV_OPENBSD) || defined(SPIRV_EMSCRIPTEN) || \ 20fd4e5da5Sopenharmony_ci defined(SPIRV_FUCHSIA) || defined(SPIRV_GNU) || defined(SPIRV_QNX) 21fd4e5da5Sopenharmony_cinamespace spvtools { 22fd4e5da5Sopenharmony_ci 23fd4e5da5Sopenharmony_ciclr::reset::operator const char*() { return "\x1b[0m"; } 24fd4e5da5Sopenharmony_ci 25fd4e5da5Sopenharmony_ciclr::grey::operator const char*() { return "\x1b[1;30m"; } 26fd4e5da5Sopenharmony_ci 27fd4e5da5Sopenharmony_ciclr::red::operator const char*() { return "\x1b[31m"; } 28fd4e5da5Sopenharmony_ci 29fd4e5da5Sopenharmony_ciclr::green::operator const char*() { return "\x1b[32m"; } 30fd4e5da5Sopenharmony_ci 31fd4e5da5Sopenharmony_ciclr::yellow::operator const char*() { return "\x1b[33m"; } 32fd4e5da5Sopenharmony_ci 33fd4e5da5Sopenharmony_ciclr::blue::operator const char*() { return "\x1b[34m"; } 34fd4e5da5Sopenharmony_ci 35fd4e5da5Sopenharmony_ci} // namespace spvtools 36fd4e5da5Sopenharmony_ci#elif defined(SPIRV_WINDOWS) 37fd4e5da5Sopenharmony_ci#include <windows.h> 38fd4e5da5Sopenharmony_ci 39fd4e5da5Sopenharmony_cinamespace spvtools { 40fd4e5da5Sopenharmony_ci 41fd4e5da5Sopenharmony_cistatic void SetConsoleForegroundColorPrimary(HANDLE hConsole, WORD color) { 42fd4e5da5Sopenharmony_ci // Get screen buffer information from console handle 43fd4e5da5Sopenharmony_ci CONSOLE_SCREEN_BUFFER_INFO bufInfo; 44fd4e5da5Sopenharmony_ci GetConsoleScreenBufferInfo(hConsole, &bufInfo); 45fd4e5da5Sopenharmony_ci 46fd4e5da5Sopenharmony_ci // Get background color 47fd4e5da5Sopenharmony_ci color = WORD(color | (bufInfo.wAttributes & 0xfff0)); 48fd4e5da5Sopenharmony_ci 49fd4e5da5Sopenharmony_ci // Set foreground color 50fd4e5da5Sopenharmony_ci SetConsoleTextAttribute(hConsole, color); 51fd4e5da5Sopenharmony_ci} 52fd4e5da5Sopenharmony_ci 53fd4e5da5Sopenharmony_cistatic void SetConsoleForegroundColor(WORD color) { 54fd4e5da5Sopenharmony_ci SetConsoleForegroundColorPrimary(GetStdHandle(STD_OUTPUT_HANDLE), color); 55fd4e5da5Sopenharmony_ci SetConsoleForegroundColorPrimary(GetStdHandle(STD_ERROR_HANDLE), color); 56fd4e5da5Sopenharmony_ci} 57fd4e5da5Sopenharmony_ci 58fd4e5da5Sopenharmony_ciclr::reset::operator const char*() { 59fd4e5da5Sopenharmony_ci if (isPrint) { 60fd4e5da5Sopenharmony_ci SetConsoleForegroundColor(0xf); 61fd4e5da5Sopenharmony_ci return ""; 62fd4e5da5Sopenharmony_ci } 63fd4e5da5Sopenharmony_ci return "\x1b[0m"; 64fd4e5da5Sopenharmony_ci} 65fd4e5da5Sopenharmony_ci 66fd4e5da5Sopenharmony_ciclr::grey::operator const char*() { 67fd4e5da5Sopenharmony_ci if (isPrint) { 68fd4e5da5Sopenharmony_ci SetConsoleForegroundColor(FOREGROUND_INTENSITY); 69fd4e5da5Sopenharmony_ci return ""; 70fd4e5da5Sopenharmony_ci } 71fd4e5da5Sopenharmony_ci return "\x1b[1;30m"; 72fd4e5da5Sopenharmony_ci} 73fd4e5da5Sopenharmony_ci 74fd4e5da5Sopenharmony_ciclr::red::operator const char*() { 75fd4e5da5Sopenharmony_ci if (isPrint) { 76fd4e5da5Sopenharmony_ci SetConsoleForegroundColor(FOREGROUND_RED); 77fd4e5da5Sopenharmony_ci return ""; 78fd4e5da5Sopenharmony_ci } 79fd4e5da5Sopenharmony_ci return "\x1b[31m"; 80fd4e5da5Sopenharmony_ci} 81fd4e5da5Sopenharmony_ci 82fd4e5da5Sopenharmony_ciclr::green::operator const char*() { 83fd4e5da5Sopenharmony_ci if (isPrint) { 84fd4e5da5Sopenharmony_ci SetConsoleForegroundColor(FOREGROUND_GREEN); 85fd4e5da5Sopenharmony_ci return ""; 86fd4e5da5Sopenharmony_ci } 87fd4e5da5Sopenharmony_ci return "\x1b[32m"; 88fd4e5da5Sopenharmony_ci} 89fd4e5da5Sopenharmony_ci 90fd4e5da5Sopenharmony_ciclr::yellow::operator const char*() { 91fd4e5da5Sopenharmony_ci if (isPrint) { 92fd4e5da5Sopenharmony_ci SetConsoleForegroundColor(FOREGROUND_RED | FOREGROUND_GREEN); 93fd4e5da5Sopenharmony_ci return ""; 94fd4e5da5Sopenharmony_ci } 95fd4e5da5Sopenharmony_ci return "\x1b[33m"; 96fd4e5da5Sopenharmony_ci} 97fd4e5da5Sopenharmony_ci 98fd4e5da5Sopenharmony_ciclr::blue::operator const char*() { 99fd4e5da5Sopenharmony_ci // Blue all by itself is hard to see against a black background (the 100fd4e5da5Sopenharmony_ci // default on command shell), or a medium blue background (the default 101fd4e5da5Sopenharmony_ci // on PowerShell). So increase its intensity. 102fd4e5da5Sopenharmony_ci 103fd4e5da5Sopenharmony_ci if (isPrint) { 104fd4e5da5Sopenharmony_ci SetConsoleForegroundColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY); 105fd4e5da5Sopenharmony_ci return ""; 106fd4e5da5Sopenharmony_ci } 107fd4e5da5Sopenharmony_ci return "\x1b[94m"; 108fd4e5da5Sopenharmony_ci} 109fd4e5da5Sopenharmony_ci 110fd4e5da5Sopenharmony_ci} // namespace spvtools 111fd4e5da5Sopenharmony_ci#else 112fd4e5da5Sopenharmony_cinamespace spvtools { 113fd4e5da5Sopenharmony_ci 114fd4e5da5Sopenharmony_ciclr::reset::operator const char*() { return ""; } 115fd4e5da5Sopenharmony_ci 116fd4e5da5Sopenharmony_ciclr::grey::operator const char*() { return ""; } 117fd4e5da5Sopenharmony_ci 118fd4e5da5Sopenharmony_ciclr::red::operator const char*() { return ""; } 119fd4e5da5Sopenharmony_ci 120fd4e5da5Sopenharmony_ciclr::green::operator const char*() { return ""; } 121fd4e5da5Sopenharmony_ci 122fd4e5da5Sopenharmony_ciclr::yellow::operator const char*() { return ""; } 123fd4e5da5Sopenharmony_ci 124fd4e5da5Sopenharmony_ciclr::blue::operator const char*() { return ""; } 125fd4e5da5Sopenharmony_ci 126fd4e5da5Sopenharmony_ci} // namespace spvtools 127fd4e5da5Sopenharmony_ci#endif 128