# # # patch "cmd_diff_log.cc" # from [d5c3600e2eeb7a74ac2c9f73c6cd75cd220c2b2f] # to [8973e7888b10fe49220e4a10fd65b57b24df422a] # # patch "color.cc" # from [045ae12ed4b5738fee9e7e68973f35329f03b40d] # to [4d0a092e949c93999cecdb5496f777ff5bf0e185] # # patch "color.hh" # from [0dc771680ae06dc7399a1641bbcf97552502fce4] # to [0cb980b88480766e3b2cc9ce19270d69e08c71fc] # # patch "diff_patch.cc" # from [02df140f859d8df26fb3e0948045f0b78b84fd86] # to [74853ed2b2a56a169102a4716916451813ac6da3] # ============================================================ --- cmd_diff_log.cc d5c3600e2eeb7a74ac2c9f73c6cd75cd220c2b2f +++ cmd_diff_log.cc 8973e7888b10fe49220e4a10fd65b57b24df422a @@ -232,7 +232,7 @@ dump_diffs(cset const & cs, bool limit_paths = false) { // 60 is somewhat arbitrary, but less than 80 - string patch_sep = string(color::comment) + string(60, '=') + string(color::std); + string patch_sep(60, '='); for (map::const_iterator i = cs.files_added.begin(); @@ -241,7 +241,7 @@ dump_diffs(cset const & cs, if (limit_paths && paths.find(i->first) == paths.end()) continue; - output << patch_sep << '\n'; + output << color::comment << patch_sep << color::std << '\n'; data unpacked; vector lines; @@ -287,7 +287,7 @@ dump_diffs(cset const & cs, file_data f_old; data data_old, data_new; - output << patch_sep << '\n'; + output << color::comment << patch_sep << color::std << '\n'; app.db.get_file_version(delta_entry_src(i), f_old); data_old = f_old.inner(); ============================================================ --- color.cc 045ae12ed4b5738fee9e7e68973f35329f03b40d +++ color.cc 4d0a092e949c93999cecdb5496f777ff5bf0e185 @@ -1,19 +1,33 @@ -namespace color { +#include "color.hh" -const char * std = "\033[0m"; -const char * strong = "\033[1m"; +color::color(const char * str): code(str) { } +//{ +// code = std::string("\033[") + std::string(str) + std::string("m"); +//} -const char * blue = "\033[31m"; -const char * green = "\033[32m"; -const char * yellow = "\033[33m"; -const char * red = "\033[34m"; -const char * purple = "\033[35m"; -const char * cyan = "\033[36m"; -const char * gray = "\033[37m"; +const color color::std ("0"); +const color color::strong("1"); +const color color::blue ("31"); +const color color::green ("32"); +const color color::yellow("33"); +const color color::red ("34"); +const color color::purple("35"); +const color color::cyan ("36"); +const color color::gray ("37"); -const char * diff_add = blue; -const char * diff_del = red; -const char * diff_conflict = purple; -const char * comment = gray; +const color color::diff_add = blue; +const color color::diff_del = red; +const color color::diff_conflict = purple; +const color color::comment = gray; +std::string +color::toString() const +{ + return std::string("\033[") + code + std::string("m"); } + +std::ostream& +operator <<(std::ostream & os, const color & col) +{ + return os << col.toString(); +} ============================================================ --- color.hh 0dc771680ae06dc7399a1641bbcf97552502fce4 +++ color.hh 0cb980b88480766e3b2cc9ce19270d69e08c71fc @@ -1,11 +1,19 @@ -namespace color { +#include +#include -extern const char * std; -extern const char * strong; +class color { -extern const char * diff_add; -extern const char * diff_del; -extern const char * diff_conflict; -extern const char * comment; +private: + const std::string code; + color(const char * str); +public: + static const color std, strong, blue, green, yellow, red, purple, cyan, gray; + static const color diff_add; + static const color diff_del; + static const color diff_conflict; + static const color comment; + + std::string toString() const; + friend std::ostream & operator <<(std::ostream & os, const color & col); +}; -} ============================================================ --- diff_patch.cc 02df140f859d8df26fb3e0948045f0b78b84fd86 +++ diff_patch.cc 74853ed2b2a56a169102a4716916451813ac6da3 @@ -930,13 +930,13 @@ void unidiff_hunk_writer::insert_at(size void unidiff_hunk_writer::insert_at(size_t b_pos) { b_len++; - hunk.push_back(string(color::diff_add) + string("+") + b[b_pos] + string(color::std)); + hunk.push_back(color::diff_add.toString() + string("+") + b[b_pos] + color::std.toString()); } void unidiff_hunk_writer::delete_at(size_t a_pos) { a_len++; - hunk.push_back(string(color::diff_del) + string("-") + a[a_pos] + string(color::std)); + hunk.push_back(color::diff_del.toString() + string("-") + a[a_pos] + color::std.toString()); } void unidiff_hunk_writer::flush_hunk(size_t pos) @@ -983,7 +983,7 @@ void unidiff_hunk_writer::flush_hunk(siz } find_encloser(a_begin + first_mod, encloser); - ost << " @@" << encloser << '\n' << color::std; + ost << " @@" << encloser << color::std << '\n'; } copy(hunk.begin(), hunk.end(), ostream_iterator(ost, "\n")); } @@ -1154,22 +1154,22 @@ void cxtdiff_hunk_writer::flush_pending_ // if we have just insertions to flush, prefix them with "+"; if // just deletions, prefix with "-"; if both, prefix with "!" if (inserts.empty() && !deletes.empty()) - prefix = string(color::diff_del) + string("-"); + prefix = color::diff_del.toString() + string("-"); else if (deletes.empty() && !inserts.empty()) - prefix = string(color::diff_add) + string("+"); + prefix = color::diff_add.toString() + string("+"); else - prefix = string(color::diff_conflict) + string("!"); + prefix = color::diff_conflict.toString() + string("!"); for (vector::const_iterator i = deletes.begin(); i != deletes.end(); ++i) { - from_file.push_back(prefix + string(" ") + a[*i] + string(color::std)); + from_file.push_back(prefix + string(" ") + a[*i] + color::std.toString()); a_len++; } for (vector::const_iterator i = inserts.begin(); i != inserts.end(); ++i) { - to_file.push_back(prefix + string(" ") + b[*i] + string(color::std)); + to_file.push_back(prefix + string(" ") + b[*i] + color::std.toString()); b_len++; }