OpenTTD Source 20241224-master-gf74b0cf984
console_internal.h
Go to the documentation of this file.
1/*
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/>.
6 */
7
10#ifndef CONSOLE_INTERNAL_H
11#define CONSOLE_INTERNAL_H
12
13#include "gfx_type.h"
14
15static const uint ICON_CMDLN_SIZE = 1024;
16static const uint ICON_MAX_STREAMSIZE = 2048;
17
24
33typedef bool IConsoleCmdProc(uint8_t argc, char *argv[]);
34typedef ConsoleHookResult IConsoleHook(bool echo);
36 IConsoleCmd(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook) : name(name), proc(proc), hook(hook) {}
37
38 std::string name;
40 IConsoleHook *hook;
41};
42
56 IConsoleAlias(const std::string &name, const std::string &cmdline) : name(name), cmdline(cmdline) {}
57
58 std::string name;
59 std::string cmdline;
60};
61
63{
64 typedef std::map<std::string, IConsoleCmd> CommandList;
65 typedef std::map<std::string, IConsoleAlias> AliasList;
66
67 /* console parser */
68 static CommandList &Commands();
69 static AliasList &Aliases();
70
71 /* Commands */
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);
76};
77
78/* console functions */
79void IConsoleClearBuffer();
80
81/* console std lib (register ingame commands/aliases) */
82void IConsoleStdLibRegister();
83
84/* Supporting functions */
85bool GetArgumentInteger(uint32_t *value, const char *arg);
86
87void IConsoleGUIInit();
88void IConsoleGUIFree();
89void IConsoleGUIPrint(TextColour colour_code, const std::string &string);
90
91#endif /* CONSOLE_INTERNAL_H */
Commands
List of commands.
bool GetArgumentInteger(uint32_t *value, const char *arg)
Change a string into its number representation.
Definition console.cpp:127
static const uint ICON_MAX_STREAMSIZE
maximum length of a totally expanded command
ConsoleHookResult
Return values of console hooks (IConsoleHook).
@ CHR_HIDE
Hide the existence of the command.
@ CHR_DISALLOW
Disallow command execution.
@ CHR_ALLOW
Allow command execution.
void IConsoleGUIPrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
bool IConsoleCmdProc(uint8_t argc, char *argv[])
–Commands– Commands are commands, or functions.
Types related to the graphics and/or input devices.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:260
–Aliases– Aliases are like shortcuts for complex functions, variable assignments, etc.
std::string cmdline
command(s) that is/are being aliased
std::string name
name of the alias
IConsoleCmdProc * proc
process executed when command is typed
IConsoleHook * hook
any special trigger action that needs executing
std::string name
name of command
static IConsoleAlias * AliasGet(const std::string &name)
Find the alias pointed to by its string.
Definition console.cpp:193
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook=nullptr)
Register a new command to be used in the console.
Definition console.cpp:160
static IConsoleCmd * CmdGet(const std::string &name)
Find the command pointed to by its string.
Definition console.cpp:170
static void AliasRegister(const std::string &name, const std::string &cmd)
Register a an alias for an already existing command in the console.
Definition console.cpp:182