CommonSyntaxTest: Fix info messages being colored as errors

This commit is contained in:
Kamil Śliwak 2023-09-28 18:30:26 +02:00
parent 81b5387a9f
commit 7857562a3b
2 changed files with 15 additions and 3 deletions

View File

@ -52,6 +52,7 @@ static constexpr char const* BLUE_BACKGROUND = "\033[44m";
static constexpr char const* MAGENTA_BACKGROUND = "\033[45m";
static constexpr char const* CYAN_BACKGROUND = "\033[46m";
static constexpr char const* WHITE_BACKGROUND = "\033[47m";
static constexpr char const* GRAY_BACKGROUND = "\033[100m";
// 256-bit-colors (incomplete set)
static constexpr char const* RED_BACKGROUND_256 = "\033[48;5;160m";

View File

@ -114,11 +114,18 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
{
assert(static_cast<size_t>(error.locationStart) <= source.length());
assert(static_cast<size_t>(error.locationEnd) <= source.length());
bool isWarning = (error.type == Error::Type::Warning);
for (int i = error.locationStart; i < error.locationEnd; i++)
if (isWarning)
if (error.type == Error::Type::Info)
{
if (sourceFormatting[static_cast<size_t>(i)] == util::formatting::RESET)
sourceFormatting[static_cast<size_t>(i)] = util::formatting::GRAY_BACKGROUND;
}
else if (error.type == Error::Type::Warning)
{
if (
sourceFormatting[static_cast<size_t>(i)] == util::formatting::RESET ||
sourceFormatting[static_cast<size_t>(i)] == util::formatting::GRAY_BACKGROUND
)
sourceFormatting[static_cast<size_t>(i)] = util::formatting::ORANGE_BACKGROUND_256;
}
else
@ -192,7 +199,11 @@ void CommonSyntaxTest::printErrorList(
for (auto const& error: _errorList)
{
{
util::AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == Error::Type::Warning) ? YELLOW : RED});
util::AnsiColorized scope(
_stream,
_formatted,
{BOLD, error.type == Error::Type::Info ? WHITE : (error.type == Error::Type::Warning ? YELLOW : RED)}
);
_stream << _linePrefix << Error::formatErrorType(error.type);
if (error.errorId.has_value())
_stream << ' ' << error.errorId->error;