(svn r16409) -Change: don't add empty lines/duplicates of the previous command to the console's history

pull/155/head
rubidium 16 years ago
parent b9e911170a
commit 65d2a381d9

@ -332,7 +332,6 @@ void IConsoleGUIInit()
IConsolePrint(CC_WHITE, "use \"help\" for more information"); IConsolePrint(CC_WHITE, "use \"help\" for more information");
IConsolePrint(CC_WHITE, ""); IConsolePrint(CC_WHITE, "");
IConsoleClearCommand(); IConsoleClearCommand();
IConsoleHistoryAdd("");
} }
void IConsoleClearBuffer() void IConsoleClearBuffer()
@ -388,10 +387,20 @@ void IConsoleOpen() {if (_iconsole_mode == ICONSOLE_CLOSED) IConsoleSwitch();}
*/ */
static void IConsoleHistoryAdd(const char *cmd) 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)); /* Do not put empty command in history */
_iconsole_history[0] = strdup(cmd); 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(); IConsoleResetHistoryPos();
} }
@ -401,6 +410,7 @@ static void IConsoleHistoryAdd(const char *cmd)
*/ */
static void IConsoleHistoryNavigate(int direction) static void IConsoleHistoryNavigate(int direction)
{ {
if (_iconsole_history[0] == NULL) return; // Empty history
int i = _iconsole_historypos + direction; int i = _iconsole_historypos + direction;
/* watch out for overflows, just wrap around */ /* watch out for overflows, just wrap around */

Loading…
Cancel
Save