diff --git a/source/src/console.cpp b/source/src/console.cpp index 98acc778..d2f4a565 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -336,6 +336,8 @@ struct hline vector history; int histpos = 0; +VARP(maxhistory, 0, 1000, 10000); + void history_(int n) { static bool inhistory = false; @@ -391,11 +393,12 @@ void consolekey(int code, bool isdown, int cooked) break; case SDLK_UP: - if(histpos>0) history[--histpos]->restore(); + if(histpos > history.length()) histpos = history.length(); + if(histpos > 0) history[--histpos]->restore(); break; case SDLK_DOWN: - if(histpos+1restore(); + if(histpos + 1 < history.length()) history[++histpos]->restore(); break; case SDLK_TAB: @@ -420,7 +423,14 @@ void consolekey(int code, bool isdown, int cooked) if(cmdline.buf[0]) { if(history.empty() || history.last()->shouldsave()) - history.add(h = new hline)->save(); // cap this? + { + if(maxhistory && history.length() >= maxhistory) + { + loopi(history.length()-maxhistory+1) delete history[i]; + history.remove(0, history.length()-maxhistory+1); + } + history.add(h = new hline)->save(); + } else h = history.last(); } histpos = history.length();