add color highlighting during token post-processing

This commit is contained in:
2026-10-12 21:59:50 +03:00
parent d97160e6ed
commit a94e584f35
3 changed files with 45 additions and 6 deletions
+29
View File
@@ -397,4 +397,33 @@ void print_math_vector(const std::vector<Expression::Token>& tv)
}
}
void print_math_vector(const std::vector<Expression::Token>& tv, const std::vector<int>& highlight_locations)
{
int i, l, h, hl;
for (i = 0, l = tv.size() - 1, h = 0, hl = highlight_locations.size(); i < l; i++)
{
if (h < hl && highlight_locations[h] == i)
{
std::cout << "\033[31m" << *tv[i].to_math_str() << "\033[0m";
h++;
}
else
{
std::cout << *tv[i].to_math_str();;
}
}
if (tv.size())
{
if (highlight_locations[highlight_locations.size()-1] == tv.size() - 1)
{
std::cout << "\033[31m" << *tv[tv.size() - 1].to_math_str() << "\033[0m\n";
}
else
{
std::cout << *tv[tv.size() - 1].to_math_str() << "\n";
}
}
}
}