Mercurial > hg > openttd
changeset 12003:dae3a822e71b draft
(svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 23 May 2009 22:40:14 +0000 |
parents | f625db21b8e2 |
children | c2d9b54aaa63 |
files | src/console_gui.cpp |
diffstat | 1 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -332,7 +332,6 @@ IConsolePrint(CC_WHITE, "use \"help\" for more information"); IConsolePrint(CC_WHITE, ""); IConsoleClearCommand(); - IConsoleHistoryAdd(""); } void IConsoleClearBuffer() @@ -388,10 +387,20 @@ */ static void IConsoleHistoryAdd(const char *cmd) { - free(_iconsole_history[ICON_HISTORY_SIZE - 1]); + /* Strip all spaces at the begin */ + while (IsWhitespace(*cmd)) cmd++; + + /* Do not put empty command in history */ + if (StrEmpty(cmd)) return; - memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1)); - _iconsole_history[0] = strdup(cmd); + /* Do not put in history if command is same as previous */ + if (_iconsole_history[0] == NULL || strcmp(_iconsole_history[0], cmd) != 0) { + free(_iconsole_history[ICON_HISTORY_SIZE - 1]); + memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1)); + _iconsole_history[0] = strdup(cmd); + } + + /* Reset the history position */ IConsoleResetHistoryPos(); } @@ -401,6 +410,7 @@ */ static void IConsoleHistoryNavigate(int direction) { + if (_iconsole_history[0] == NULL) return; // Empty history int i = _iconsole_historypos + direction; /* watch out for overflows, just wrap around */