# HG changeset patch # User John Tsiombikas # Date 1402406108 -10800 # Node ID b9294cd6b9dc24996969a9953b131ec1b47bec21 # Parent 2e817711d0f6260f31c9408316669bb941b1bbb2 console input history with up/down diff -r 2e817711d0f6 -r b9294cd6b9dc src/console.cc --- a/src/console.cc Tue Jun 10 12:28:56 2014 +0300 +++ b/src/console.cc Tue Jun 10 16:15:08 2014 +0300 @@ -19,6 +19,8 @@ max_hist_lines = 64; max_output_lines = 128; + hist_iter_valid = false; + echo = true; font = 0; font_size = 0; @@ -142,6 +144,8 @@ if((int)hist.size() > max_hist_lines) { hist.pop_front(); } + hist_iter_valid = false; + set_cursor(0); must_redraw = true; break; @@ -164,6 +168,36 @@ } break; + case KEY_UP: + if(!hist.empty()) { + if(!hist_iter_valid) { + hist_iter = hist.rbegin(); + hist_iter_valid = true; + input = *hist_iter; + } else { + if(++hist_iter == hist.rend()) { + --hist_iter; + break; + } + input = *hist_iter; + } + set_cursor(input.size()); + } + break; + + case KEY_DOWN: + if(!hist.empty()) { + if(!hist_iter_valid) { + hist_iter = hist.rbegin(); + hist_iter_valid = true; + } + if(hist_iter != hist.rbegin()) { + input = *--hist_iter; + set_cursor(input.size()); + } + } + break; + case KEY_LEFT: if(cursor > 0) { set_cursor(get_cursor() - 1); @@ -190,7 +224,7 @@ case KEY_PGUP: case KEY_PGDOWN: - // TODO history + // TODO scroll output buffer break; default: @@ -284,8 +318,8 @@ float cursor_x = dtx_char_pos(inpline.c_str(), cursor - input_win + prompt.size()); glBegin(GL_QUADS); glColor4f(1, 1, 1, 0.7); - glVertex2f(cursor_x, 0); - glVertex2f(cursor_x + 2, 0); + glVertex2f(cursor_x, -2); + glVertex2f(cursor_x + 2, -2); glVertex2f(cursor_x + 2, line_height - 2); glVertex2f(cursor_x, line_height - 2); glEnd(); diff -r 2e817711d0f6 -r b9294cd6b9dc src/console.h --- a/src/console.h Tue Jun 10 12:28:56 2014 +0300 +++ b/src/console.h Tue Jun 10 16:15:08 2014 +0300 @@ -25,6 +25,8 @@ // input history int max_hist_lines; std::list hist; + bool hist_iter_valid; + std::list::const_reverse_iterator hist_iter; // console output int max_output_lines;