From 1f3bb2eda188f04271d318c36b57f69fd61552ef Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 7 Mar 2017 10:21:33 -0800 Subject: 3763 --- 100trace_browser.cc | 1 - html/100trace_browser.cc.html | 503 +++++++++++++++++++++--------------------- 2 files changed, 251 insertions(+), 253 deletions(-) diff --git a/100trace_browser.cc b/100trace_browser.cc index 4577c8a1..13083f10 100644 --- a/100trace_browser.cc +++ b/100trace_browser.cc @@ -39,7 +39,6 @@ //: `M`: Move cursor to center line on screen. //: `L`: Move cursor to bottom line on screen. -//: browse the trace we just created :(before "End Primitive Recipe Declarations") _BROWSE_TRACE, :(before "End Primitive Recipe Numbers") diff --git a/html/100trace_browser.cc.html b/html/100trace_browser.cc.html index 22b280a4..ea42981c 100644 --- a/html/100trace_browser.cc.html +++ b/html/100trace_browser.cc.html @@ -98,258 +98,257 @@ if ('onhashchange' in window) { 39 //: `M`: Move cursor to center line on screen. 40 //: `L`: Move cursor to bottom line on screen. 41 - 42 //: browse the trace we just created - 43 :(before "End Primitive Recipe Declarations") - 44 _BROWSE_TRACE, - 45 :(before "End Primitive Recipe Numbers") - 46 put(Recipe_ordinal, "$browse-trace", _BROWSE_TRACE); - 47 :(before "End Primitive Recipe Checks") - 48 case _BROWSE_TRACE: { - 49 break; - 50 } - 51 :(before "End Primitive Recipe Implementations") - 52 case _BROWSE_TRACE: { - 53 start_trace_browser(); - 54 break; - 55 } - 56 - 57 //: browse a trace loaded from a file - 58 :(after "Commandline Parsing") - 59 if (argc == 3 && is_equal(argv[1], "browse-trace")) { - 60 load_trace(argv[2]); - 61 start_trace_browser(); - 62 return 0; - 63 } - 64 - 65 :(before "End Globals") - 66 set<int> Visible; - 67 int Top_of_screen = 0; - 68 int Last_printed_row = 0; - 69 map<int, int> Trace_index; // screen row -> trace index - 70 - 71 :(code) - 72 void start_trace_browser() { - 73 if (!Trace_stream) return; - 74 cerr << "computing min depth to display\n"; - 75 int min_depth = 9999; - 76 for (int i = 0; i < SIZE(Trace_stream->past_lines); ++i) { - 77 ¦ trace_line& curr_line = Trace_stream->past_lines.at(i); - 78 ¦ if (curr_line.depth < min_depth) min_depth = curr_line.depth; - 79 } - 80 cerr << "min depth is " << min_depth << '\n'; - 81 cerr << "computing lines to display\n"; - 82 for (int i = 0; i < SIZE(Trace_stream->past_lines); ++i) { - 83 ¦ if (Trace_stream->past_lines.at(i).depth == min_depth) - 84 ¦ ¦ Visible.insert(i); - 85 } - 86 tb_init(); - 87 Display_row = Display_column = 0; - 88 tb_event event; - 89 Top_of_screen = 0; - 90 refresh_screen_rows(); - 91 while (true) { - 92 ¦ render(); - 93 ¦ do { - 94 ¦ ¦ tb_poll_event(&event); - 95 ¦ } while (event.type != TB_EVENT_KEY); - 96 ¦ int key = event.key ? event.key : event.ch; - 97 ¦ if (key == 'q' || key == 'Q' || key == TB_KEY_CTRL_C) break; - 98 ¦ if (key == 'j' || key == TB_KEY_ARROW_DOWN) { - 99 ¦ ¦ // move cursor one line down -100 ¦ ¦ if (Display_row < Last_printed_row) ++Display_row; -101 ¦ } -102 ¦ if (key == 'k' || key == TB_KEY_ARROW_UP) { -103 ¦ ¦ // move cursor one line up -104 ¦ ¦ if (Display_row > 0) --Display_row; -105 ¦ } -106 ¦ if (key == 'H') { -107 ¦ ¦ // move cursor to top of screen -108 ¦ ¦ Display_row = 0; -109 ¦ } -110 ¦ if (key == 'M') { -111 ¦ ¦ // move cursor to center of screen -112 ¦ ¦ Display_row = tb_height()/2; -113 ¦ } -114 ¦ if (key == 'L') { -115 ¦ ¦ // move cursor to bottom of screen -116 ¦ ¦ Display_row = tb_height()-1; -117 ¦ } -118 ¦ if (key == 'J' || key == TB_KEY_PGDN || key == TB_KEY_CTRL_F) { -119 ¦ ¦ // page-down -120 ¦ ¦ if (Trace_index.find(tb_height()-1) != Trace_index.end()) { -121 ¦ ¦ ¦ Top_of_screen = get(Trace_index, tb_height()-1) + 1; -122 ¦ ¦ ¦ refresh_screen_rows(); -123 ¦ ¦ } -124 ¦ } -125 ¦ if (key == 'K' || key == TB_KEY_PGUP || key == TB_KEY_CTRL_B) { -126 ¦ ¦ // page-up is more convoluted -127 ¦ ¦ for (int screen_row = tb_height(); screen_row > 0 && Top_of_screen > 0; --screen_row) { -128 ¦ ¦ ¦ --Top_of_screen; -129 ¦ ¦ ¦ if (Top_of_screen <= 0) break; -130 ¦ ¦ ¦ while (Top_of_screen > 0 && !contains_key(Visible, Top_of_screen)) -131 ¦ ¦ ¦ ¦ --Top_of_screen; -132 ¦ ¦ } -133 ¦ ¦ if (Top_of_screen >= 0) -134 ¦ ¦ ¦ refresh_screen_rows(); -135 ¦ } -136 ¦ if (key == 'g' || key == TB_KEY_HOME) { -137 ¦ ¦ ¦ Top_of_screen = 0; -138 ¦ ¦ ¦ Last_printed_row = 0; -139 ¦ ¦ ¦ Display_row = 0; -140 ¦ ¦ ¦ refresh_screen_rows(); -141 ¦ } -142 ¦ if (key == 'G' || key == TB_KEY_END) { -143 ¦ ¦ // go to bottom of screen; largely like page-up, interestingly -144 ¦ ¦ Top_of_screen = SIZE(Trace_stream->past_lines)-1; -145 ¦ ¦ for (int screen_row = tb_height(); screen_row > 0 && Top_of_screen > 0; --screen_row) { -146 ¦ ¦ ¦ --Top_of_screen; -147 ¦ ¦ ¦ if (Top_of_screen <= 0) break; -148 ¦ ¦ ¦ while (Top_of_screen > 0 && !contains_key(Visible, Top_of_screen)) -149 ¦ ¦ ¦ ¦ --Top_of_screen; -150 ¦ ¦ } -151 ¦ ¦ refresh_screen_rows(); -152 ¦ ¦ // move cursor to bottom -153 ¦ ¦ Display_row = Last_printed_row; -154 ¦ ¦ refresh_screen_rows(); -155 ¦ } -156 ¦ if (key == TB_KEY_CARRIAGE_RETURN) { -157 ¦ ¦ // expand lines under current by one level -158 ¦ ¦ assert(contains_key(Trace_index, Display_row)); -159 ¦ ¦ int start_index = get(Trace_index, Display_row); -160 ¦ ¦ int index = 0; -161 ¦ ¦ // simultaneously compute end_index and min_depth -162 ¦ ¦ int min_depth = 9999; -163 ¦ ¦ for (index = start_index+1; index < SIZE(Trace_stream->past_lines); ++index) { -164 ¦ ¦ ¦ if (contains_key(Visible, index)) break; -165 ¦ ¦ ¦ trace_line& curr_line = Trace_stream->past_lines.at(index); -166 ¦ ¦ ¦ assert(curr_line.depth > Trace_stream->past_lines.at(start_index).depth); -167 ¦ ¦ ¦ if (curr_line.depth < min_depth) min_depth = curr_line.depth; -168 ¦ ¦ } -169 ¦ ¦ int end_index = index; -170 ¦ ¦ // mark as visible all intervening indices at min_depth -171 ¦ ¦ for (index = start_index; index < end_index; ++index) { -172 ¦ ¦ ¦ trace_line& curr_line = Trace_stream->past_lines.at(index); -173 ¦ ¦ ¦ if (curr_line.depth == min_depth) { -174 ¦ ¦ ¦ ¦ Visible.insert(index); -175 ¦ ¦ ¦ } -176 ¦ ¦ } -177 ¦ ¦ refresh_screen_rows(); -178 ¦ } -179 ¦ if (key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2) { -180 ¦ ¦ // collapse all lines under current -181 ¦ ¦ assert(contains_key(Trace_index, Display_row)); -182 ¦ ¦ int start_index = get(Trace_index, Display_row); -183 ¦ ¦ int index = 0; -184 ¦ ¦ // end_index is the next line at a depth same as or lower than start_index -185 ¦ ¦ int initial_depth = Trace_stream->past_lines.at(start_index).depth; -186 ¦ ¦ for (index = start_index+1; index < SIZE(Trace_stream->past_lines); ++index) { -187 ¦ ¦ ¦ if (!contains_key(Visible, index)) continue; -188 ¦ ¦ ¦ trace_line& curr_line = Trace_stream->past_lines.at(index); -189 ¦ ¦ ¦ if (curr_line.depth <= initial_depth) break; -190 ¦ ¦ } -191 ¦ ¦ int end_index = index; -192 ¦ ¦ // mark as visible all intervening indices at min_depth -193 ¦ ¦ for (index = start_index+1; index < end_index; ++index) { -194 ¦ ¦ ¦ Visible.erase(index); -195 ¦ ¦ } -196 ¦ ¦ refresh_screen_rows(); -197 ¦ } -198 } -199 tb_shutdown(); -200 } -201 -202 // update Trace_indices for each screen_row on the basis of Top_of_screen and Visible -203 void refresh_screen_rows() { -204 int screen_row = 0, index = 0; -205 Trace_index.clear(); -206 for (screen_row = 0, index = Top_of_screen; screen_row < tb_height() && index < SIZE(Trace_stream->past_lines); ++screen_row, ++index) { -207 ¦ // skip lines without depth for now -208 ¦ while (!contains_key(Visible, index)) { -209 ¦ ¦ ++index; -210 ¦ ¦ if (index >= SIZE(Trace_stream->past_lines)) goto done; -211 ¦ } -212 ¦ assert(index < SIZE(Trace_stream->past_lines)); -213 ¦ put(Trace_index, screen_row, index); -214 } -215 done:; -216 } -217 -218 void render() { -219 int screen_row = 0; -220 for (screen_row = 0; screen_row < tb_height(); ++screen_row) { -221 ¦ if (!contains_key(Trace_index, screen_row)) break; -222 ¦ trace_line& curr_line = Trace_stream->past_lines.at(get(Trace_index, screen_row)); -223 ¦ ostringstream out; -224 ¦ out << std::setw(4) << curr_line.depth << ' ' << curr_line.label << ": " << curr_line.contents; -225 ¦ if (screen_row < tb_height()-1) { -226 ¦ ¦ int delta = lines_hidden(screen_row); -227 ¦ ¦ // home-brew escape sequence for red -228 ¦ ¦ if (delta > 999) out << static_cast<char>(1); -229 ¦ ¦ out << " (" << delta << ")"; -230 ¦ ¦ if (delta > 999) out << static_cast<char>(2); -231 ¦ } -232 ¦ render_line(screen_row, out.str(), screen_row == Display_row); -233 } -234 // clear rest of screen -235 Last_printed_row = screen_row-1; -236 for (; screen_row < tb_height(); ++screen_row) { -237 ¦ render_line(screen_row, "~", /*highlight?*/false); -238 } -239 // move cursor back to display row at the end -240 tb_set_cursor(0, Display_row); -241 tb_present(); -242 } -243 -244 int lines_hidden(int screen_row) { -245 assert(contains_key(Trace_index, screen_row)); -246 if (!contains_key(Trace_index, screen_row+1)) -247 ¦ return SIZE(Trace_stream->past_lines) - get(Trace_index, screen_row); -248 else -249 ¦ return get(Trace_index, screen_row+1) - get(Trace_index, screen_row); -250 } -251 -252 void render_line(int screen_row, const string& s, bool highlight) { -253 int col = 0; -254 int color = TB_WHITE; -255 for (col = 0; col < tb_width() && col < SIZE(s); ++col) { -256 ¦ char c = s.at(col); // todo: unicode -257 ¦ if (c == '\n') c = ';'; // replace newlines with semi-colons -258 ¦ // escapes. hack: can't start a line with them. -259 ¦ if (c == '\1') { color = /*red*/1; c = ' '; } -260 ¦ if (c == '\2') { color = TB_WHITE; c = ' '; } -261 ¦ tb_change_cell(col, screen_row, c, color, highlight ? /*subtle grey*/240 : TB_BLACK); -262 } -263 for (; col < tb_width(); ++col) -264 ¦ tb_change_cell(col, screen_row, ' ', TB_WHITE, highlight ? /*subtle grey*/240 : TB_BLACK); -265 } -266 -267 void load_trace(const char* filename) { -268 ifstream tin(filename); -269 if (!tin) { -270 ¦ cerr << "no such file: " << filename << '\n'; -271 ¦ exit(1); -272 } -273 Trace_stream = new trace_stream; -274 while (has_data(tin)) { -275 ¦ tin >> std::noskipws; -276 ¦ ¦ skip_whitespace_but_not_newline(tin); -277 ¦ ¦ if (!isdigit(tin.peek())) { -278 ¦ ¦ ¦ string dummy; -279 ¦ ¦ ¦ getline(tin, dummy); -280 ¦ ¦ ¦ continue; -281 ¦ ¦ } -282 ¦ tin >> std::skipws; -283 ¦ int depth; -284 ¦ tin >> depth; -285 ¦ string label; -286 ¦ tin >> label; -287 ¦ if (*--label.end() == ':') label.erase(--label.end()); -288 ¦ string line; -289 ¦ getline(tin, line); -290 ¦ Trace_stream->past_lines.push_back(trace_line(depth, label, line)); -291 } -292 cerr << "lines read: " << Trace_stream->past_lines.size() << '\n'; -293 } + 42 :(before "End Primitive Recipe Declarations") + 43 _BROWSE_TRACE, + 44 :(before "End Primitive Recipe Numbers") + 45 put(Recipe_ordinal, "$browse-trace", _BROWSE_TRACE); + 46 :(before "End Primitive Recipe Checks") + 47 case _BROWSE_TRACE: { + 48 break; + 49 } + 50 :(before "End Primitive Recipe Implementations") + 51 case _BROWSE_TRACE: { + 52 start_trace_browser(); + 53 break; + 54 } + 55 + 56 //: browse a trace loaded from a file + 57 :(after "Commandline Parsing") + 58 if (argc == 3 && is_equal(argv[1], "browse-trace")) { + 59 load_trace(argv[2]); + 60 start_trace_browser(); + 61 return 0; + 62 } + 63 + 64 :(before "End Globals") + 65 set<int> Visible; + 66 int Top_of_screen = 0; + 67 int Last_printed_row = 0; + 68 map<int, int> Trace_index; // screen row -> trace index + 69 + 70 :(code) + 71 void start_trace_browser() { + 72 if (!Trace_stream) return; + 73 cerr << "computing min depth to display\n"; + 74 int min_depth = 9999; + 75 for (int i = 0; i < SIZE(Trace_stream->past_lines); ++i) { + 76 ¦ trace_line& curr_line = Trace_stream->past_lines.at(i); + 77 ¦ if (curr_line.depth < min_depth) min_depth = curr_line.depth; + 78 } + 79 cerr << "min depth is " << min_depth << '\n'; + 80 cerr << "computing lines to display\n"; + 81 for (int i = 0; i < SIZE(Trace_stream->past_lines); ++i) { + 82 ¦ if (Trace_stream->past_lines.at(i).depth == min_depth) + 83 ¦ ¦ Visible.insert(i); + 84 } + 85 tb_init(); + 86 Display_row = Display_column = 0; + 87 tb_event event; + 88 Top_of_screen = 0; + 89 refresh_screen_rows(); + 90 while (true) { + 91 ¦ render(); + 92 ¦ do { + 93 ¦ ¦ tb_poll_event(&event); + 94 ¦ } while (event.type != TB_EVENT_KEY); + 95 ¦ int key = event.key ? event.key : event.ch; + 96 ¦ if (key == 'q' || key == 'Q' || key == TB_KEY_CTRL_C) break; + 97 ¦ if (key == 'j' || key == TB_KEY_ARROW_DOWN) { + 98 ¦ ¦ // move cursor one line down + 99 ¦ ¦ if (Display_row < Last_printed_row) ++Display_row; +100 ¦ } +101 ¦ if (key == 'k' || key == TB_KEY_ARROW_UP) { +102 ¦ ¦ // move cursor one line up +103 ¦ ¦ if (Display_row > 0) --Display_row; +104 ¦ } +105 ¦ if (key == 'H') { +106 ¦ ¦ // move cursor to top of screen +107 ¦ ¦ Display_row = 0; +108 ¦ } +109 ¦ if (key == 'M') { +110 ¦ ¦ // move cursor to center of screen +111 ¦ ¦ Display_row = tb_height()/2; +112 ¦ } +113 ¦ if (key == 'L') { +114 ¦ ¦ // move cursor to bottom of screen +115 ¦ ¦ Display_row = tb_height()-1; +116 ¦ } +117 ¦ if (key == 'J' || key == TB_KEY_PGDN || key == TB_KEY_CTRL_F) { +118 ¦ ¦ // page-down +119 ¦ ¦ if (Trace_index.find(tb_height()-1) != Trace_index.end()) { +120 ¦ ¦ ¦ Top_of_screen = get(Trace_index, tb_height()-1) + 1; +121 ¦ ¦ ¦ refresh_screen_rows(); +122 ¦ ¦ } +123 ¦ } +124 ¦ if (key == 'K' || key == TB_KEY_PGUP || key == TB_KEY_CTRL_B) { +125 ¦ ¦ // page-up is more convoluted +126 ¦ ¦ for (int screen_row = tb_height(); screen_row > 0 && Top_of_screen > 0; --screen_row) { +127 ¦ ¦ ¦ --Top_of_screen; +128 ¦ ¦ ¦ if (Top_of_screen <= 0) break; +129 ¦ ¦ ¦ while (Top_of_screen > 0 && !contains_key(Visible, Top_of_screen)) +130 ¦ ¦ ¦ ¦ --Top_of_screen; +131 ¦ ¦ } +132 ¦ ¦ if (Top_of_screen >= 0) +133 ¦ ¦ ¦ refresh_screen_rows(); +134 ¦ } +135 ¦ if (key == 'g' || key == TB_KEY_HOME) { +136 ¦ ¦ ¦ Top_of_screen = 0; +137 ¦ ¦ ¦ Last_printed_row = 0; +138 ¦ ¦ ¦ Display_row = 0; +139 ¦ ¦ ¦ refresh_screen_rows(); +140 ¦ } +141 ¦ if (key == 'G' || key == TB_KEY_END) { +142 ¦ ¦ // go to bottom of screen; largely like page-up, interestingly +143 ¦ ¦ Top_of_screen = SIZE(Trace_stream->past_lines)-1; +144 ¦ ¦ for (int screen_row = tb_height(); screen_row > 0 && Top_of_screen > 0; --screen_row) { +145 ¦ ¦ ¦ --Top_of_screen; +146 ¦ ¦ ¦ if (Top_of_screen <= 0) break; +147 ¦ ¦ ¦ while (Top_of_screen > 0 && !contains_key(Visible, Top_of_screen)) +148 ¦ ¦ ¦ ¦ --Top_of_screen; +149 ¦ ¦ } +150 ¦ ¦ refresh_screen_rows(); +151 ¦ ¦ // move cursor to bottom +152 ¦ ¦ Display_row = Last_printed_row; +153 ¦ ¦ refresh_screen_rows(); +154 ¦ } +155 ¦ if (key == TB_KEY_CARRIAGE_RETURN) { +156 ¦ ¦ // expand lines under current by one level +157 ¦ ¦ assert(contains_key(Trace_index, Display_row)); +158 ¦ ¦ int start_index = get(Trace_index, Display_row); +159 ¦ ¦ int index = 0; +160 ¦ ¦ // simultaneously compute end_index and min_depth +161 ¦ ¦ int min_depth = 9999; +162 ¦ ¦ for (index = start_index+1; index < SIZE(Trace_stream->past_lines); ++index) { +163 ¦ ¦ ¦ if (contains_key(Visible, index)) break; +164 ¦ ¦ ¦ trace_line& curr_line = Trace_stream->past_lines.at(index); +165 ¦ ¦ ¦ assert(curr_line.depth > Trace_stream->past_lines.at(start_index).depth); +166 ¦ ¦ ¦ if (curr_line.depth < min_depth) min_depth = curr_line.depth; +167 ¦ ¦ } +168 ¦ ¦ int end_index = index; +169 ¦ ¦ // mark as visible all intervening indices at min_depth +170 ¦ ¦ for (index = start_index; index < end_index; ++index) { +171 ¦ ¦ ¦ trace_line& curr_line = Trace_stream->past_lines.at(index); +172 ¦ ¦ ¦ if (curr_line.depth == min_depth) { +173 ¦ ¦ ¦ ¦ Visible.insert(index); +174 ¦ ¦ ¦ } +175 ¦ ¦ } +176 ¦ ¦ refresh_screen_rows(); +177 ¦ } +178 ¦ if (key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2) { +179 ¦ ¦ // collapse all lines under current +180 ¦ ¦ assert(contains_key(Trace_index, Display_row)); +181 ¦ ¦ int start_index = get(Trace_index, Display_row); +182 ¦ ¦ int index = 0; +183 ¦ ¦ // end_index is the next line at a depth same as or lower than start_index +184 ¦ ¦ int initial_depth = Trace_stream->past_lines.at(start_index).depth; +185 ¦ ¦ for (index = start_index+1; index < SIZE(Trace_stream->past_lines); ++index) { +186 ¦ ¦ ¦ if (!contains_key(Visible, index)) continue; +187 ¦ ¦ ¦ trace_line& curr_line = Trace_stream->past_lines.at(index); +188 ¦ ¦ ¦ if (curr_line.depth <= initial_depth) break; +189 ¦ ¦ } +190 ¦ ¦ int end_index = index; +191 ¦ ¦ // mark as visible all intervening indices at min_depth +192 ¦ ¦ for (index = start_index+1; index < end_index; ++index) { +193 ¦ ¦ ¦ Visible.erase(index); +194 ¦ ¦ } +195 ¦ ¦ refresh_screen_rows(); +196 ¦ } +197 } +198 tb_shutdown(); +199 } +200 +201 // update Trace_indices for each screen_row on the basis of Top_of_screen and Visible +202 void refresh_screen_rows() { +203 int screen_row = 0, index = 0; +204 Trace_index.clear(); +205 for (screen_row = 0, index = Top_of_screen; screen_row < tb_height() && index < SIZE(Trace_stream->past_lines); ++screen_row, ++index) { +206 ¦ // skip lines without depth for now +207 ¦ while (!contains_key(Visible, index)) { +208 ¦ ¦ ++index; +209 ¦ ¦ if (index >= SIZE(Trace_stream->past_lines)) goto done; +210 ¦ } +211 ¦ assert(index < SIZE(Trace_stream->past_lines)); +212 ¦ put(Trace_index, screen_row, index); +213 } +214 done:; +215 } +216 +217 void render() { +218 int screen_row = 0; +219 for (screen_row = 0; screen_row < tb_height(); ++screen_row) { +220 ¦ if (!contains_key(Trace_index, screen_row)) break; +221 ¦ trace_line& curr_line = Trace_stream->past_lines.at(get(Trace_index, screen_row)); +222 ¦ ostringstream out; +223 ¦ out << std::setw(4) << curr_line.depth << ' ' << curr_line.label << ": " << curr_line.contents; +224 ¦ if (screen_row < tb_height()-1) { +225 ¦ ¦ int delta = lines_hidden(screen_row); +226 ¦ ¦ // home-brew escape sequence for red +227 ¦ ¦ if (delta > 999) out << static_cast<char>(1); +228 ¦ ¦ out << " (" << delta << ")"; +229 ¦ ¦ if (delta > 999) out << static_cast<char>(2); +230 ¦ } +231 ¦ render_line(screen_row, out.str(), screen_row == Display_row); +232 } +233 // clear rest of screen +234 Last_printed_row = screen_row-1; +235 for (; screen_row < tb_height(); ++screen_row) { +236 ¦ render_line(screen_row, "~", /*highlight?*/false); +237 } +238 // move cursor back to display row at the end +239 tb_set_cursor(0, Display_row); +240 tb_present(); +241 } +242 +243 int lines_hidden(int screen_row) { +244 assert(contains_key(Trace_index, screen_row)); +245 if (!contains_key(Trace_index, screen_row+1)) +246 ¦ return SIZE(Trace_stream->past_lines) - get(Trace_index, screen_row); +247 else +248 ¦ return get(Trace_index, screen_row+1) - get(Trace_index, screen_row); +249 } +250 +251 void render_line(int screen_row, const string& s, bool highlight) { +252 int col = 0; +253 int color = TB_WHITE; +254 for (col = 0; col < tb_width() && col < SIZE(s); ++col) { +255 ¦ char c = s.at(col); // todo: unicode +256 ¦ if (c == '\n') c = ';'; // replace newlines with semi-colons +257 ¦ // escapes. hack: can't start a line with them. +258 ¦ if (c == '\1') { color = /*red*/1; c = ' '; } +259 ¦ if (c == '\2') { color = TB_WHITE; c = ' '; } +260 ¦ tb_change_cell(col, screen_row, c, color, highlight ? /*subtle grey*/240 : TB_BLACK); +261 } +262 for (; col < tb_width(); ++col) +263 ¦ tb_change_cell(col, screen_row, ' ', TB_WHITE, highlight ? /*subtle grey*/240 : TB_BLACK); +264 } +265 +266 void load_trace(const char* filename) { +267 ifstream tin(filename); +268 if (!tin) { +269 ¦ cerr << "no such file: " << filename << '\n'; +270 ¦ exit(1); +271 } +272 Trace_stream = new trace_stream; +273 while (has_data(tin)) { +274 ¦ tin >> std::noskipws; +275 ¦ ¦ skip_whitespace_but_not_newline(tin); +276 ¦ ¦ if (!isdigit(tin.peek())) { +277 ¦ ¦ ¦ string dummy; +278 ¦ ¦ ¦ getline(tin, dummy); +279 ¦ ¦ ¦ continue; +280 ¦ ¦ } +281 ¦ tin >> std::skipws; +282 ¦ int depth; +283 ¦ tin >> depth; +284 ¦ string label; +285 ¦ tin >> label; +286 ¦ if (*--label.end() == ':') label.erase(--label.end()); +287 ¦ string line; +288 ¦ getline(tin, line); +289 ¦ Trace_stream->past_lines.push_back(trace_line(depth, label, line)); +290 } +291 cerr << "lines read: " << Trace_stream->past_lines.size() << '\n'; +292 } -- cgit 1.4.1-2-gfad0