Commands

Commands allow you to run some code in response to a certain string being entered into the console

Register a command

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 }

Arguments

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

Command
start server -p 3000 -t "Window Title"

Unregister a command

Removes a command if it exists. This can also be used to remove built in commands

C#
PowerConsole.UnregisterCommand("start server");

Manually handling commands

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; };

Built in commands

These commands are available by default

CommandDescription
helpDisplays descriptions for all registered commands
clearClears the console
exitCloses the console
position fullscreenFullscreen the console
position topPosition the console at the top of the screen
position bottomPosition the console at the bottom of the screen

Command history

Use the keyboard up and down arrows to cycle through previously entered commands