diff options
author | rubidium <rubidium@openttd.org> | 2009-05-23 22:40:14 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-05-23 22:40:14 +0000 |
commit | de1a9b95c785112e18b587c029e343cad8834760 (patch) | |
tree | 5984f6135445328083c229278b4a734057d9b44b /src | |
parent | 607583f0916471dccb97634ef3d90bacd09778b5 (diff) | |
download | openttd-de1a9b95c785112e18b587c029e343cad8834760.tar.xz |
(svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history
Diffstat (limited to 'src')
-rw-r--r-- | src/console_gui.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/console_gui.cpp b/src/console_gui.cpp index 9f158d341..6ca976d0a 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -332,7 +332,6 @@ void IConsoleGUIInit() IConsolePrint(CC_WHITE, "use \"help\" for more information"); IConsolePrint(CC_WHITE, ""); IConsoleClearCommand(); - IConsoleHistoryAdd(""); } void IConsoleClearBuffer() @@ -388,10 +387,20 @@ void IConsoleOpen() {if (_iconsole_mode == ICONSOLE_CLOSED) IConsoleSwitch();} */ static void IConsoleHistoryAdd(const char *cmd) { - free(_iconsole_history[ICON_HISTORY_SIZE - 1]); + /* Strip all spaces at the begin */ + while (IsWhitespace(*cmd)) cmd++; - memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1)); - _iconsole_history[0] = strdup(cmd); + /* Do not put empty command in history */ + if (StrEmpty(cmd)) return; + + /* 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 IConsoleHistoryAdd(const char *cmd) */ 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 */ |