Commands allow you to run some code in response to a certain string being entered into the console
Register a command by calling RegisterCommand. Callback will be fired when "start server" is entered into the console. The optional Description will be shown if the "help" command is run. If the command already exists it will be overwritten
C#PowerConsole.RegisterCommand(new CustomCommand()
{
Command = "start server",
Description = "Starts a web server",
Callback = StartServerCallback
});
C#private void StartServerCallback(CommandCallback callback)
{
// Raised when "start server" is entered into the terminal
}
Argument names must begin with a "-", e.g. "-f"
Optional arguments can be specified that can be entered after the command
C#PowerConsole.RegisterCommand(new CustomCommand()
{
Command = "start server",
Description = "Starts a web server",
Args = new List<CommandArgument>()
{
new CommandArgument() { Name = "-p", Description = "Port number to host on" },
new CommandArgument() { Name = "-t", Description = "Title of the window" }
},
Callback = Command1Callback
});
C#private void StartServerCallback(CommandCallback callback)
{
// Raised when "start server" is entered into the terminal
// Arguments are parsed and available in callback.Args
var port = callback.Args["-p"];
var title = callback.Args["-t"];
}
Argument values must not contain spaces unless they are quoted
Commandstart server -p 3000 -t "Window Title"
Removes a command if it exists. This can also be used to remove built in commands
C#PowerConsole.UnregisterCommand("start server");
If you don't want to register commands you can listen to the CommandEntered event which will be raised everytime a command is entered
C#PowerConsole.CommandEntered += (s, e) =>
{
var enteredCommand = e.Command;
};
These commands are available by default
| Command | Description |
|---|---|
| help | Displays descriptions for all registered commands |
| clear | Clears the console |
| exit | Closes the console |
| position fullscreen | Fullscreen the console |
| position top | Position the console at the top of the screen |
| position bottom | Position the console at the bottom of the screen |
Use the keyboard up and down arrows to cycle through previously entered commands