2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file console_internal.h Internally used functions for the console. */
10 #ifndef CONSOLE_INTERNAL_H
11 #define CONSOLE_INTERNAL_H
15 static const uint ICON_CMDLN_SIZE
= 1024; ///< maximum length of a typed in command
16 static const uint ICON_MAX_STREAMSIZE
= 2048; ///< maximum length of a totally expanded command
18 /** Return values of console hooks (#IConsoleHook). */
19 enum ConsoleHookResult
{
20 CHR_ALLOW
, ///< Allow command execution.
21 CHR_DISALLOW
, ///< Disallow command execution.
22 CHR_HIDE
, ///< Hide the existence of the command.
27 * Commands are commands, or functions. They get executed once and any
28 * effect they produce are carried out. The arguments to the commands
29 * are given to them, each input word separated by a double-quote (") is an argument
30 * If you want to handle multiple words as one, enclose them in double-quotes
31 * eg. 'say "hello everybody"'
33 typedef bool IConsoleCmdProc(byte argc
, char *argv
[]);
34 typedef ConsoleHookResult
IConsoleHook(bool echo
);
36 IConsoleCmd(const std::string
&name
, IConsoleCmdProc
*proc
, IConsoleHook
*hook
) : name(name
), proc(proc
), hook(hook
) {}
38 std::string name
; ///< name of command
39 IConsoleCmdProc
*proc
; ///< process executed when command is typed
40 IConsoleHook
*hook
; ///< any special trigger action that needs executing
45 * Aliases are like shortcuts for complex functions, variable assignments,
46 * etc. You can use a simple alias to rename a longer command (eg 'set' for
47 * 'setting' for example), or concatenate more commands into one
48 * (eg. 'ng' for 'load %A; unpause; debug_level 5'). Aliases can parse the arguments
49 * given to them in the command line.
50 * - "%A - %Z" substitute arguments 1 t/m 26
51 * - "%+" lists all parameters keeping them separated
52 * - "%!" also lists all parameters but presenting them to the aliased command as one argument
53 * - ";" allows for combining commands (see example 'ng')
55 struct IConsoleAlias
{
56 IConsoleAlias(const std::string
&name
, const std::string
&cmdline
) : name(name
), cmdline(cmdline
) {}
58 std::string name
; ///< name of the alias
59 std::string cmdline
; ///< command(s) that is/are being aliased
64 typedef std::map
<std::string
, IConsoleCmd
> CommandList
;
65 typedef std::map
<std::string
, IConsoleAlias
> AliasList
;
68 static CommandList
&Commands();
69 static AliasList
&Aliases();
72 static void CmdRegister(const std::string
&name
, IConsoleCmdProc
*proc
, IConsoleHook
*hook
= nullptr);
73 static IConsoleCmd
*CmdGet(const std::string
&name
);
74 static void AliasRegister(const std::string
&name
, const std::string
&cmd
);
75 static IConsoleAlias
*AliasGet(const std::string
&name
);
78 /* console functions */
79 void IConsoleClearBuffer();
81 /* console std lib (register ingame commands/aliases) */
82 void IConsoleStdLibRegister();
84 /* Supporting functions */
85 bool GetArgumentInteger(uint32_t *value
, const char *arg
);
87 void IConsoleGUIInit();
88 void IConsoleGUIFree();
89 void IConsoleGUIPrint(TextColour colour_code
, const std::string
&string
);
91 #endif /* CONSOLE_INTERNAL_H */