add color highlighting during token post-processing
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user