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
|
|
|
|
|
|
|
#include "print.h"
|
|
|
|
|
2017-05-29 00:19:58 +03:00
|
|
|
#if defined(SPIRV_ANDROID) || defined(SPIRV_LINUX) || defined(SPIRV_MAC) || defined(SPIRV_FREEBSD)
|
2015-11-20 18:44:41 +03:00
|
|
|
namespace libspirv {
|
|
|
|
|
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
|
|
|
|
|
|
|
} // namespace libspirv
|
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
|
|
|
|
2015-11-20 18:44:41 +03:00
|
|
|
namespace libspirv {
|
|
|
|
|
2017-08-20 15:11:50 +03:00
|
|
|
static void SetConsoleForegroundColorPrimary(HANDLE hConsole, WORD color)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
static void SetConsoleForegroundColor(WORD color)
|
|
|
|
{
|
|
|
|
SetConsoleForegroundColorPrimary(GetStdHandle(STD_OUTPUT_HANDLE), color);
|
|
|
|
SetConsoleForegroundColorPrimary(GetStdHandle(STD_ERROR_HANDLE), color);
|
|
|
|
}
|
|
|
|
|
|
|
|
clr::reset::operator const char*() {
|
|
|
|
SetConsoleForegroundColor(0xf);
|
2015-05-22 20:26:19 +03:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::grey::operator const char*() {
|
2017-08-20 15:11:50 +03:00
|
|
|
SetConsoleForegroundColor(FOREGROUND_INTENSITY);
|
2015-05-22 20:26:19 +03:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::red::operator const char*() {
|
2017-08-20 15:11:50 +03:00
|
|
|
SetConsoleForegroundColor(FOREGROUND_RED);
|
2015-05-22 20:26:19 +03:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::green::operator const char*() {
|
2017-08-20 15:11:50 +03:00
|
|
|
SetConsoleForegroundColor(FOREGROUND_GREEN);
|
2015-05-22 20:26:19 +03:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:41:20 +03:00
|
|
|
clr::yellow::operator const char*() {
|
2017-08-20 15:11:50 +03:00
|
|
|
SetConsoleForegroundColor(FOREGROUND_RED | FOREGROUND_GREEN);
|
2015-05-22 20:26:19 +03:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
SetConsoleForegroundColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
2015-05-22 20:26:19 +03:00
|
|
|
return "";
|
|
|
|
}
|
2015-11-20 18:44:41 +03:00
|
|
|
|
2015-11-22 19:32:53 +03:00
|
|
|
} // namespace libspirv
|
|
|
|
#else
|
|
|
|
namespace libspirv {
|
|
|
|
|
|
|
|
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 ""; }
|
|
|
|
|
2015-11-20 18:44:41 +03:00
|
|
|
} // namespace libspirv
|
2015-05-22 20:26:19 +03:00
|
|
|
#endif
|