2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "source/print.h"
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2017-11-08 17:40:02 +00:00
|
|
|
#if defined(SPIRV_ANDROID) || defined(SPIRV_LINUX) || defined(SPIRV_MAC) || \
|
2019-11-26 21:22:59 +00:00
|
|
|
defined(SPIRV_IOS) || defined(SPIRV_FREEBSD) || \
|
|
|
|
defined(SPIRV_EMSCRIPTEN) || defined(SPIRV_FUCHSIA)
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2015-11-20 15:44:41 +00:00
|
|
|
|
2016-03-18 18:13:16 +00:00
|
|
|
clr::reset::operator const char*() { return "\x1b[0m"; }
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-03-18 18:13:16 +00:00
|
|
|
clr::grey::operator const char*() { return "\x1b[1;30m"; }
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-03-18 18:13:16 +00:00
|
|
|
clr::red::operator const char*() { return "\x1b[31m"; }
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-03-18 18:13:16 +00:00
|
|
|
clr::green::operator const char*() { return "\x1b[32m"; }
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-03-18 18:13:16 +00:00
|
|
|
clr::yellow::operator const char*() { return "\x1b[33m"; }
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-03-18 18:13:16 +00:00
|
|
|
clr::blue::operator const char*() { return "\x1b[34m"; }
|
2015-11-20 15:44:41 +00:00
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
} // namespace spvtools
|
2015-05-22 17:26:19 +00:00
|
|
|
#elif defined(SPIRV_WINDOWS)
|
2016-02-29 06:01:04 +00:00
|
|
|
#include <windows.h>
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2015-11-20 15:44:41 +00:00
|
|
|
|
2017-11-08 17:40:02 +00:00
|
|
|
static void SetConsoleForegroundColorPrimary(HANDLE hConsole, WORD color) {
|
2017-08-20 12:11:50 +00:00
|
|
|
// Get screen buffer information from console handle
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO bufInfo;
|
|
|
|
GetConsoleScreenBufferInfo(hConsole, &bufInfo);
|
|
|
|
|
|
|
|
// Get background color
|
2017-08-28 22:36:52 +00:00
|
|
|
color = WORD(color | (bufInfo.wAttributes & 0xfff0));
|
2017-08-20 12:11:50 +00:00
|
|
|
|
|
|
|
// Set foreground color
|
2015-05-22 17:26:19 +00:00
|
|
|
SetConsoleTextAttribute(hConsole, color);
|
2017-08-20 12:11:50 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 17:40:02 +00:00
|
|
|
static void SetConsoleForegroundColor(WORD color) {
|
2017-08-20 12:11:50 +00:00
|
|
|
SetConsoleForegroundColorPrimary(GetStdHandle(STD_OUTPUT_HANDLE), color);
|
|
|
|
SetConsoleForegroundColorPrimary(GetStdHandle(STD_ERROR_HANDLE), color);
|
|
|
|
}
|
|
|
|
|
|
|
|
clr::reset::operator const char*() {
|
2017-11-30 21:35:22 +00:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(0xf);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[0m";
|
2015-05-22 17:26:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 14:41:20 +00:00
|
|
|
clr::grey::operator const char*() {
|
2017-11-30 21:35:22 +00:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_INTENSITY);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[1;30m";
|
2015-05-22 17:26:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 14:41:20 +00:00
|
|
|
clr::red::operator const char*() {
|
2017-11-30 21:35:22 +00:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_RED);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[31m";
|
2015-05-22 17:26:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 14:41:20 +00:00
|
|
|
clr::green::operator const char*() {
|
2017-11-30 21:35:22 +00:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_GREEN);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[32m";
|
2015-05-22 17:26:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 14:41:20 +00:00
|
|
|
clr::yellow::operator const char*() {
|
2017-11-30 21:35:22 +00:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_RED | FOREGROUND_GREEN);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[33m";
|
2015-05-22 17:26:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 14:41:20 +00:00
|
|
|
clr::blue::operator const char*() {
|
2017-08-24 14:34:00 +00:00
|
|
|
// Blue all by itself is hard to see against a black background (the
|
|
|
|
// default on command shell), or a medium blue background (the default
|
|
|
|
// on PowerShell). So increase its intensity.
|
2017-11-30 21:35:22 +00:00
|
|
|
|
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[94m";
|
2015-05-22 17:26:19 +00:00
|
|
|
}
|
2015-11-20 15:44:41 +00:00
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
} // namespace spvtools
|
2015-11-22 16:32:53 +00:00
|
|
|
#else
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2015-11-22 16:32:53 +00:00
|
|
|
|
|
|
|
clr::reset::operator const char*() { return ""; }
|
|
|
|
|
|
|
|
clr::grey::operator const char*() { return ""; }
|
|
|
|
|
|
|
|
clr::red::operator const char*() { return ""; }
|
|
|
|
|
|
|
|
clr::green::operator const char*() { return ""; }
|
|
|
|
|
|
|
|
clr::yellow::operator const char*() { return ""; }
|
|
|
|
|
|
|
|
clr::blue::operator const char*() { return ""; }
|
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
} // namespace spvtools
|
2015-05-22 17:26:19 +00:00
|
|
|
#endif
|