mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r2332) - Feature: Add 'clear' command and CTRL+L to empty the console window
- Fix: do not execute emtpy commands anymore
This commit is contained in:
parent
4554daa130
commit
653000bdd6
15
console.c
15
console.c
@ -151,6 +151,9 @@ static void IConsoleWndProc(Window* w, WindowEvent* e)
|
|||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case (WKC_CTRL | 'L'):
|
||||||
|
IConsoleCmdExec("clear");
|
||||||
|
break;
|
||||||
case WKC_BACKSPACE: case WKC_DELETE:
|
case WKC_BACKSPACE: case WKC_DELETE:
|
||||||
if (DeleteTextBufferChar(&_iconsole_cmdline, e->keypress.keycode)) {
|
if (DeleteTextBufferChar(&_iconsole_cmdline, e->keypress.keycode)) {
|
||||||
IConsoleResetHistoryPos();
|
IConsoleResetHistoryPos();
|
||||||
@ -222,13 +225,19 @@ void IConsoleInit(void)
|
|||||||
IConsoleHistoryAdd("");
|
IConsoleHistoryAdd("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IConsoleClear(void)
|
void IConsoleClearBuffer(void)
|
||||||
{
|
{
|
||||||
uint i;
|
uint i;
|
||||||
for (i = 0; i <= ICON_BUFFER; i++)
|
for (i = 0; i <= ICON_BUFFER; i++) {
|
||||||
free(_iconsole_buffer[i]);
|
free(_iconsole_buffer[i]);
|
||||||
|
_iconsole_buffer[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void IConsoleClear(void)
|
||||||
|
{
|
||||||
free(_iconsole_cmdline.buf);
|
free(_iconsole_cmdline.buf);
|
||||||
|
IConsoleClearBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IConsoleWriteToLogFile(const char* string)
|
static void IConsoleWriteToLogFile(const char* string)
|
||||||
@ -1022,6 +1031,8 @@ void IConsoleCmdExec(const char *cmdstr)
|
|||||||
bool longtoken = false;
|
bool longtoken = false;
|
||||||
bool foundtoken = false;
|
bool foundtoken = false;
|
||||||
|
|
||||||
|
if (*cmdstr == '\0') return; // don't execute empty commands
|
||||||
|
|
||||||
for (cmdptr = cmdstr; *cmdptr != '\0'; cmdptr++) {
|
for (cmdptr = cmdstr; *cmdptr != '\0'; cmdptr++) {
|
||||||
if (!IsValidAsciiChar(*cmdptr)) {
|
if (!IsValidAsciiChar(*cmdptr)) {
|
||||||
IConsoleError("command contains malformed characters, aborting");
|
IConsoleError("command contains malformed characters, aborting");
|
||||||
|
@ -114,8 +114,8 @@ VARDEF IConsoleModes _iconsole_mode;
|
|||||||
|
|
||||||
// ** console functions ** //
|
// ** console functions ** //
|
||||||
void IConsoleInit(void);
|
void IConsoleInit(void);
|
||||||
void IConsoleClear(void);
|
|
||||||
void IConsoleFree(void);
|
void IConsoleFree(void);
|
||||||
|
void IConsoleClearBuffer(void);
|
||||||
void IConsoleResize(void);
|
void IConsoleResize(void);
|
||||||
void IConsoleSwitch(void);
|
void IConsoleSwitch(void);
|
||||||
void IConsoleClose(void);
|
void IConsoleClose(void);
|
||||||
|
@ -268,7 +268,6 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
|
DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
|
||||||
{
|
{
|
||||||
const char *path;
|
const char *path;
|
||||||
@ -287,6 +286,18 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEF_CONSOLE_CMD(ConClearBuffer)
|
||||||
|
{
|
||||||
|
if (argc == 0) {
|
||||||
|
IConsoleHelp("Clear the console buffer. Usage: 'clear'");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IConsoleClearBuffer();
|
||||||
|
InvalidateWindow(WC_CONSOLE, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ********************************* //
|
// ********************************* //
|
||||||
// * Network Core Console Commands * //
|
// * Network Core Console Commands * //
|
||||||
@ -1217,6 +1228,7 @@ void IConsoleStdLibRegister(void)
|
|||||||
IConsoleCmdRegister("ls", ConListFiles);
|
IConsoleCmdRegister("ls", ConListFiles);
|
||||||
IConsoleCmdRegister("cd", ConChangeDirectory);
|
IConsoleCmdRegister("cd", ConChangeDirectory);
|
||||||
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
|
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
|
||||||
|
IConsoleCmdRegister("clear", ConClearBuffer);
|
||||||
|
|
||||||
IConsoleAliasRegister("dir", "ls");
|
IConsoleAliasRegister("dir", "ls");
|
||||||
IConsoleAliasRegister("newmap", "newgame");
|
IConsoleAliasRegister("newmap", "newgame");
|
||||||
|
Loading…
Reference in New Issue
Block a user