# # # patch "asciik.cc" # from [ffa88051ab21603eb1c334cee164c2bcf6d31987] # to [0577329efafa54a142b40f2d8b599f911e0f4fd7] # ============================================================ --- asciik.cc ffa88051ab21603eb1c334cee164c2bcf6d31987 +++ asciik.cc 0577329efafa54a142b40f2d8b599f911e0f4fd7 @@ -111,6 +111,8 @@ Loop: #include #include #include +#include +#include //#include // tuples are faster than std::pair on copy constructors, but we're only using // std::pair so it probably doesn't matter much @@ -126,6 +128,8 @@ using std::vector; using std::pair; using std::set; using std::vector; +using boost::algorithm::split; +using boost::algorithm::is_any_of; static revision_id ghost; // valid but empty revision_id to be used as ghost value @@ -153,8 +157,10 @@ asciik::draw(const size_t curr_items, co const size_t curr_loc, const set > & links, const set & curr_ghosts, const string & annotation) const { - string line(curr_items * 2 - 1, ' '); - string interline(max(curr_items, next_items) * 2 - 1, ' '); + size_t line_len = max(curr_items, next_items) * 2; + string line(line_len, ' '); // actual len: curr_items * 2 - 1 + string interline(line_len, ' '); // actual len: max(curr_items, next_items) * 2 - 1 + string interline2(line_len, ' '); // first draw the flow-through bars in the line for (size_t i = 0; i < curr_items; ++i) @@ -202,20 +208,34 @@ asciik::draw(const size_t curr_items, co for (size_t l = start; l < end; ++l) line[l] = '-'; } + // prepare the proper continuation line + interline2[j * 2] = '|'; } // add any dots (must do this in a second pass, so that if there are // cases like: // | ·-----·-o // |/| | |/| - // where we want to make sure the second dot overwrites the first --· + // where we want to make sure the second dot overwrites the first --. for (set::const_iterator dot = dots.begin(); dot != dots.end(); ++dot) line[*dot] = '·'; //TODO: what about this special char? should it be UTF-8? // and add the main attraction (may overwrite a '·'). line[curr_loc * 2] = 'o'; - cout << line << " " << annotation << '\n'; - cout << interline << '\n'; + // split a multi-line annotation + vector lines; + split(lines, annotation, is_any_of("\n\r")); + int num_lines = lines.size(); + if (num_lines < 1) + lines.push_back(string("")); + if (num_lines < 2) + lines.push_back(string("")); + + // prints it out + cout << F("%-8s %s") % line % lines[0] << '\n'; + cout << F("%-8s %s") % interline % lines[1] << '\n'; + for (int i = 2; i < num_lines; ++i) + cout << F("%-8s %s") % interline2 % lines[i] << '\n'; } bool @@ -359,6 +379,6 @@ CMD(asciik, N_("tree"), N_("SELECTOR"), set parents; app.db.get_revision_parents(*rev, parents); parents.erase(ghost); // remove the fake parent that root nodes have - graph.print(*rev, parents, rev->inner()()); + graph.print(*rev, parents, rev->inner()() + "\nline 2\nline 3\nline 4"); } }