2016-01-07 21:44:22 +03:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-05-22 20:26:19 +03:00
|
|
|
//
|
2016-09-01 22:33:59 +03: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 20:26:19 +03:00
|
|
|
//
|
2016-09-01 22:33:59 +03:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-05-22 20:26:19 +03:00
|
|
|
//
|
2016-09-01 22:33:59 +03: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 20:26:19 +03:00
|
|
|
|
2018-08-03 22:06:09 +03:00
|
|
|
#include "source/print.h"
|
2015-05-22 20:26:19 +03:00
|
|
|
|
2017-11-08 20:40:02 +03:00
|
|
|
#if defined(SPIRV_ANDROID) || defined(SPIRV_LINUX) || defined(SPIRV_MAC) || \
|
2021-06-29 22:14:38 +03:00
|
|
|
defined(SPIRV_IOS) || defined(SPIRV_TVOS) || defined(SPIRV_FREEBSD) || \
|
2022-09-02 22:30:09 +03:00
|
|
|
defined(SPIRV_OPENBSD) || defined(SPIRV_EMSCRIPTEN) || \
|
|
|
|
defined(SPIRV_FUCHSIA) || defined(SPIRV_GNU)
|
2018-07-07 16:38:00 +03:00
|
|
|
namespace spvtools {
|
2015-11-20 18:44:41 +03:00
|
|
|
|
2016-03-18 21:13:16 +03:00
|
|
|
clr::reset::operator const char*() { return "\x1b[0m"; }
|
2015-05-22 20:26:19 +03:00
|
|
|
|
2016-03-18 21:13:16 +03:00
|
|
|
clr::grey::operator const char*() { return "\x1b[1;30m"; }
|
2015-05-22 20:26:19 +03:00
|
|
|
|
2016-03-18 21:13:16 +03:00
|
|
|
clr::red::operator const char*() { return "\x1b[31m"; }
|
2015-05-22 20:26:19 +03:00
|
|
|
|
2016-03-18 21:13:16 +03:00
|
|
|
clr::green::operator const char*() { return "\x1b[32m"; }
|
2015-05-22 20:26:19 +03:00
|
|
|
|
2016-03-18 21:13:16 +03:00
|
|
|
clr::yellow::operator const char*() { return "\x1b[33m"; }
|
2015-05-22 20:26:19 +03:00
|
|
|
|
2016-03-18 21:13:16 +03:00
|
|
|
clr::blue::operator const char*() { return "\x1b[34m"; }
|
2015-11-20 18:44:41 +03:00
|
|
|
|
2018-07-07 16:38:00 +03:00
|
|
|
} // namespace spvtools
|
2015-05-22 20:26:19 +03:00
|
|
|
#elif defined(SPIRV_WINDOWS)
|
2016-02-29 09:01:04 +03:00
|
|
|
#include <windows.h>
|
2015-05-22 20:26:19 +03:00
|
|
|
|
2018-07-07 16:38:00 +03:00
|
|
|
namespace spvtools {
|
2015-11-20 18:44:41 +03:00
|
|
|
|
2017-11-08 20:40:02 +03:00
|
|
|
static void SetConsoleForegroundColorPrimary(HANDLE hConsole, WORD color) {
|
2017-08-20 15:11:50 +03:00
|
|
|
// Get screen buffer information from console handle
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO bufInfo;
|
|
|
|
GetConsoleScreenBufferInfo(hConsole, &bufInfo);
|
|
|
|
|
|
|
|
// Get background color
|
2017-08-29 01:36:52 +03:00
|
|
|
color = WORD(color | (bufInfo.wAttributes & 0xfff0));
|
2017-08-20 15:11:50 +03:00
|
|
|
|
|
|
|
// Set foreground color
|
2015-05-22 20:26:19 +03:00
|
|
|
SetConsoleTextAttribute(hConsole, color);
|
2017-08-20 15:11:50 +03:00
|
|
|
}
|
|
|
|
|
2017-11-08 20:40:02 +03:00
|
|
|
static void SetConsoleForegroundColor(WORD color) {
|
2017-08-20 15:11:50 +03:00
|
|
|
SetConsoleForegroundColorPrimary(GetStdHandle(STD_OUTPUT_HANDLE), color);
|
|
|
|
SetConsoleForegroundColorPrimary(GetStdHandle(STD_ERROR_HANDLE), color);
|
|
|
|
}
|
|
|
|
|
|
|
|
clr::reset::operator const char*() {
|
2017-12-01 00:35:22 +03:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(0xf);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[0m";
|
2015-05-22 20:26:19 +03:00
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::grey::operator const char*() {
|
2017-12-01 00:35:22 +03:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_INTENSITY);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[1;30m";
|
2015-05-22 20:26:19 +03:00
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::red::operator const char*() {
|
2017-12-01 00:35:22 +03:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_RED);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[31m";
|
2015-05-22 20:26:19 +03:00
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::green::operator const char*() {
|
2017-12-01 00:35:22 +03:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_GREEN);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[32m";
|
2015-05-22 20:26:19 +03:00
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::yellow::operator const char*() {
|
2017-12-01 00:35:22 +03:00
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_RED | FOREGROUND_GREEN);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[33m";
|
2015-05-22 20:26:19 +03:00
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::blue::operator const char*() {
|
2017-08-24 17:34:00 +03: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-12-01 00:35:22 +03:00
|
|
|
|
|
|
|
if (isPrint) {
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return "\x1b[94m";
|
2015-05-22 20:26:19 +03:00
|
|
|
}
|
2015-11-20 18:44:41 +03:00
|
|
|
|
2018-07-07 16:38:00 +03:00
|
|
|
} // namespace spvtools
|
2015-11-22 19:32:53 +03:00
|
|
|
#else
|
2018-07-07 16:38:00 +03:00
|
|
|
namespace spvtools {
|
2015-11-22 19:32:53 +03: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 16:38:00 +03:00
|
|
|
} // namespace spvtools
|
2015-05-22 20:26:19 +03:00
|
|
|
#endif
|