From 341239c91126c58b9c37f0ca7d9ee0a583840af5 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 22 May 2015 18:25:27 -0700 Subject: 1421 - more snappy cursor movement Persist the mapping from screen row to trace index between refreshes. Now we have to remember to refresh the mapping anytime we change state. --- 077trace_browser.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/077trace_browser.cc b/077trace_browser.cc index 8d426ec9..b8a61977 100644 --- a/077trace_browser.cc +++ b/077trace_browser.cc @@ -12,6 +12,7 @@ case _BROWSE_TRACE: { set Visible; long long int Top_of_screen = 0; long long int Last_printed_row = 0; +map Trace_index; // screen row -> trace index :(code) void start_trace_browser() { @@ -32,6 +33,8 @@ void start_trace_browser() { tb_init(); Display_row = Display_column = 0; struct tb_event event; + Top_of_screen = 0; + refresh_screen_rows(); while (true) { render(); do { @@ -49,8 +52,10 @@ void start_trace_browser() { tb_shutdown(); } -void render() { +// update Trace_indices for each screen_row on the basis of Top_of_screen and Visible +void refresh_screen_rows() { long long int screen_row = 0, index = 0; + Trace_index.clear(); for (screen_row = 0, index = Top_of_screen; screen_row < tb_height() && index < SIZE(Trace_stream->past_lines); ++screen_row, ++index) { // skip lines without depth for now while (Visible.find(index) == Visible.end()) { @@ -58,13 +63,20 @@ void render() { if (index >= SIZE(Trace_stream->past_lines)) goto done; } assert(index < SIZE(Trace_stream->past_lines)); - // render trace line at index - trace_line& curr_line = Trace_stream->past_lines.at(index); + Trace_index[screen_row] = index; + } +done:; +} + +void render() { + long long int screen_row = 0; + for (screen_row = 0; screen_row < tb_height(); ++screen_row) { + if (Trace_index.find(screen_row) == Trace_index.end()) break; + trace_line& curr_line = Trace_stream->past_lines.at(Trace_index[screen_row]); ostringstream out; out << std::setw(4) << curr_line.depth << ' ' << curr_line.label << ": " << curr_line.contents; render_line(screen_row, out.str()); } -done: // clear rest of screen Last_printed_row = screen_row-1; for (; screen_row < tb_height(); ++screen_row) { -- cgit 1.4.1-2-gfad0