forked from adnanaziz/EPIJudge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c08756
commit 07ddf29
Showing
266 changed files
with
1,208 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// @library | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <iostream> | ||
|
||
#ifdef _WINDOWS | ||
#define NOMINMAX | ||
#include <Windows.h> | ||
#endif | ||
|
||
#include "platform.h" | ||
|
||
enum class ConsoleColor { FG_RED, FG_GREEN, FG_BLUE, FG_DEFAULT }; | ||
|
||
short GetColorCodeWin(ConsoleColor color) { | ||
switch (color) { | ||
case ConsoleColor::FG_RED: | ||
return 4 | 8; | ||
case ConsoleColor::FG_GREEN: | ||
return 2 | 8; | ||
case ConsoleColor::FG_BLUE: | ||
return 1 | 8; | ||
case ConsoleColor::FG_DEFAULT: | ||
return 7; | ||
} | ||
} | ||
|
||
const char* GetColorCodeUnix(ConsoleColor color) { | ||
switch (color) { | ||
case ConsoleColor::FG_RED: | ||
return "\033[31m"; | ||
case ConsoleColor::FG_GREEN: | ||
return "\033[32m"; | ||
case ConsoleColor::FG_BLUE: | ||
return "\033[34m"; | ||
case ConsoleColor::FG_DEFAULT: | ||
return "\033[39m"; | ||
} | ||
} | ||
|
||
template <typename T> | ||
void PrintStdOutColored(ConsoleColor color, const T& value) { | ||
if (!platform::UseColorOutput()) { | ||
std::cout << value; | ||
return; | ||
} | ||
#ifdef _WINDOWS | ||
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); | ||
CONSOLE_SCREEN_BUFFER_INFO buffer_info; | ||
GetConsoleScreenBufferInfo(stdout_handle, &buffer_info); | ||
const WORD old_color_attrs = buffer_info.wAttributes; | ||
fflush(stdout); | ||
|
||
SetConsoleTextAttribute(stdout_handle, GetColorCodeWin(color)); | ||
|
||
std::cout << value; | ||
fflush(stdout); | ||
|
||
SetConsoleTextAttribute(stdout_handle, old_color_attrs); | ||
#else | ||
std::cout << GetColorCodeUnix(color) << value | ||
<< GetColorCodeUnix(ConsoleColor::FG_DEFAULT); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,13 @@ | ||
// @library | ||
#pragma once | ||
|
||
#include <ostream> | ||
#include "platform.h" | ||
|
||
//We can't detect STACK_OVERFLOW in C++ | ||
enum TestResult { PASSED, FAILED, TIMEOUT, UNKNOWN_EXCEPTION, /*STACK_OVERFLOW*/ }; | ||
|
||
namespace console_color { | ||
const char* FG_RED = "\033[31m"; | ||
const char* FG_GREEN = "\033[32m"; | ||
const char* FG_BLUE = "\033[34m"; | ||
const char* FG_DEFAULT = "\033[39m"; | ||
}; // namespace console_color | ||
|
||
bool UseTtyOutput() { | ||
static int cached = platform::IsATty(platform::StdOutFd()); | ||
return static_cast<bool>(cached); | ||
} | ||
|
||
inline bool PlatformSupportsColor() { | ||
#ifdef _WINDOWS | ||
return false; // Windows doesn't support coloring through escape codes | ||
#else | ||
return true; | ||
#endif | ||
} | ||
|
||
std::string Colored(std::string text, const char* color) { | ||
if (UseTtyOutput() && PlatformSupportsColor()) { | ||
return color + std::move(text) + console_color::FG_DEFAULT; | ||
} else { | ||
return std::move(text); | ||
} | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& out, const TestResult& tr) { | ||
switch (tr) { | ||
case PASSED: | ||
return out << Colored("PASSED", console_color::FG_GREEN); | ||
case FAILED: | ||
return out << Colored("FAILED", console_color::FG_RED); | ||
case TIMEOUT: | ||
return out << Colored("TIMEOUT", console_color::FG_BLUE); | ||
case UNKNOWN_EXCEPTION: | ||
return out << Colored("UNHANDLED EXCEPTION", console_color::FG_RED); | ||
default: | ||
throw std::runtime_error("Unknown TestResult"); | ||
} | ||
} | ||
#include "console_color.h" | ||
|
||
// We may not detect STACK_OVERFLOW in C++ (Java and Python detect that). | ||
enum TestResult { | ||
PASSED, | ||
FAILED, | ||
TIMEOUT, | ||
UNKNOWN_EXCEPTION, | ||
/*STACK_OVERFLOW*/ | ||
}; |
Oops, something went wrong.