BosonWare.TerminalApp is a modern, extensible .NET terminal application framework designed to simplify the creation of interactive command-line tools. It provides a robust command registry, built-in commands, command history, and flexible parsing utilities, making it ideal for building rich terminal experiences.
- Command Registry: Easily register and manage commands with attributes and aliases.
- Built-in Commands: Includes common commands like
help,clear,exit,version, andtime. - Command History: Persistent command history with disk storage.
- Command Parsing: Advanced command-line parsing with support for quoted arguments.
- Extensibility: Add custom commands by implementing the
ICommandinterface or deriving fromCommand<TOptions>. - Colorful Output: Integrates with BosonWare.TUI for styled console output.
- .NET 8.0 or later
Add the NuGet package to your project:
dotnet add package BosonWare.TerminalAppCreate a simple terminal app:
using BosonWare.TerminalApp;
using BosonWare.TerminalApp.BuiltIn;
CommandRegistry.LoadCommands<Program>(typeof(IBuiltInAssemblyMarker));
var app = new ConsoleApplication() {
Prompt = "[Crimson]Boson Terminal[/] > ",
History = CommandHistory.CreateAsync("command_history.json").GetAwaiter().GetResult()
};
await app.RunAsync();Commands are registered using the [Command] attribute:
[Command("greet", Aliases = ["hello"], Description = "Greets the user.")]
public sealed class GreetCommand : ICommand
{
public Task Execute(string arguments)
{
Console.WriteLine($"Hello, {arguments}!");
return Task.CompletedTask;
}
}Or use options parsing:
public class EchoOptions
{
[Option('u', "upper", HelpText = "Uppercase output.")]
public bool Upper { get; set; }
}
[Command("echo", Description = "Echoes input.")]
public sealed class EchoCommand : Command<EchoOptions>
{
public override Task Execute(EchoOptions options)
{
// Implementation here
return Task.CompletedTask;
}
}help/info/-h/?— Displays helpclear/cls— Clears the terminalexit/shutdown— Exits the applicationversion/ver— Shows version infotime— Shows current time (--utcfor UTC)
Command history is persisted to disk and loaded on startup. The default limit is 1000 entries.
MIT License. See LICENSE for details.
Contributions are welcome! Please submit issues or pull requests via GitHub.
The following changes have been implemented: an ExitHandler has been added, the capability to run multiple nested applications has been removed, and improvements have been made to the CommandGroup and CommandRegistry.