-
Notifications
You must be signed in to change notification settings - Fork 0
Plugins
Console contains a full-control plugin system. They are installed manually.
These plugins are written in C# and must implement a few things. For the hands-on learners, go here for an already done plugin.
If you haven't already, install the application.
This will be found inside the folder you installed the application to. The DLL you're looking for is called Console.dll
. Once you have found this, keep its location in mind. It will be needed in further steps.
You need to create a C# application that has a type of Class Library
, once this project is made, make sure the project references Console.dll
from before. To do this is Visual Studio 22, follow these steps:
- Right click your project in the folder display
- Hover over
Add
- Click
Add a Project Reference
- On the new window click the
Browse
Tab, then press theBrowse
button in the bottom right. - Select
Console.dll
. - Done!
using Console;
using Console.Commands;
using Console.Plugins;
using Console.Utilitys.Configuration;
using Console.Utilitys.Options;
These are needed for this little plugin we will write.
We need to define a class that implements IConsolePlugin
. We will call our class AutoConfigPlugin
.
class AutoConfigPlugin : IConsolePlugin {
}
We will have an error now because we haven't implemented IPlugin. Console requires a couple of fields from the plugin to provide information about itself. These are:
- Its name
- A description about itself
- Its authors name
- Its Id
Lets implement these
class AutoConfigPlugin : IConsolePlugin {
public string Name => "AutoConfig";
public string Description => "Nice utility plugin to keep your configuration straight!";
public string Author => "Your Name";
// note: Console will automatically change this. So theres no point setting it to anything other
// than empty.
public Guid Id { get; set; } = Guid.Empty;
}
This is because we need to implement hook functions. Console plugins work by simply reacting to changes. This is done with the following functions:
- OnLoaded -- This is ran once the plugin is loaded
- OnUnloaded -- This is ran just before the plugin is unloaded
- OnUserInput -- This is ran after the user enters a command
- OnCommandExecuted -- This is ran just before a command has been executed
- OnSettingChange -- This is ran just before a setting changes.
If OnUserInput
or OnSettingChange
returns false
the input/setting change will be ignored.
These are special functions that can modify the actual behaviour of Console.
We need to implement these functions, lets do it now as bare bones as possible. NOTE: These functions are inside the class, we just showing them without it here to keep it clean
public void OnLoaded(IConsole terminal) {}
public void OnUnloaded(IConsole terminal) {}
public bool OnUserInput(IConsole terminal, string input) {}
public void OnCommandExecuted(IConsole terminal, Commands.ICommand command) {}
public bool OnSettingChange(IConsole terminal, ISettings settings, string settingName, object? newValue) {}
We will need to return true in OnUserInput
and OnSettingChange
to make sure it compiles. Note that returning true allows the input to go through and other plugins to have their say.
public bool OnUserInput(IConsole console, string input) { return true; }
public bool OnSettingChange(IConsole terminal, ISettings settings, string settingName, object? newValue) { return true; }
Cool, now your plugin is ready. You can begin implementing whatever you like. Here are a couple things you might find useful while making your plugin:
Please note that you can also implement and add commands in plugins.
You can load commands using a plugin. All commands must implement BaseBuiltinCommand
. Here is a small example following all guidelines that you should.
public class AboutCommand : BaseBuiltinCommand
{
public override string Name => "about";
public override string Description => "About Console";
public override DateTime? LastRunTime { get; set; } = null;
public override int Run(List<string> args, IConsole parent)
{
base.Run(args, parent);
WriteLine("Terminal is a project, made for fun.");
WriteLine("It attempts to emulate Windows cmd.");
WriteLine("While also keeping the nice feel of bash alive.");
WriteLine($"This project can be found at [link={Terminal.GithubLink}]this github repo[/]. It is open source.");
return CommandReturnValues.DontShowText;
}
public override string DocString => $@"
This command will display some basic information about this application.
";
}
If you then wished to load this command, add the following code to your OnLoaded
function.
terminal.Commands.LoadCustomCommand(new AboutCommand());
That'd do it! For more information on creating custom commands, see here
main repo here