/* Given a string and list of colors of the same size, return the string with ANSI escape sequences representing the colors. */ static std::string ansi_colorize(const wcstring &text, const std::vector<highlight_spec_t> &colors) { assert(colors.size() == text.size()); assert(output_receiver.empty()); int (*saved)(char) = output_get_writer(); output_set_writer(write_to_output_receiver); highlight_spec_t last_color = highlight_spec_normal; for (size_t i=0; i < text.size(); i++) { highlight_spec_t color = colors.at(i); if (color != last_color) { set_color(highlight_get_color(color, false), rgb_color_t::normal()); last_color = color; } writech(text.at(i)); } output_set_writer(saved); std::string result; result.swap(output_receiver); return result; }
/// Set the pen color for the terminal. static void s_set_color(screen_t *s, const environment_t &vars, highlight_spec_t c) { UNUSED(s); s->outp().set_color(highlight_get_color(c, false), highlight_get_color(c, true)); }