Skip to content

Commit

Permalink
feat: Add IAliasable for e.g. commands which can be shortened by leav…
Browse files Browse the repository at this point in the history
…ing out the name
  • Loading branch information
Computerdores committed Apr 10, 2024
1 parent cea2f8e commit c93dcf1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions AdvancedTerminalAPI/IAliasable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Collections.Generic;

namespace Computerdores;

public interface IAliasable {
public IEnumerable<ICommand> GetAll(ITerminal term);
}
15 changes: 10 additions & 5 deletions AdvancedTerminalAPI/Vanillin/VanillinTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ public class VanillinTerminal : ITerminal {

public InputFieldDriver GetDriver() => _driver;

private void AddBuiltinCommand(ICommand command) {
_builtinCommands[command.GetName()] = command;
}
public void AddCommand(ICommand command) {
_commands[command.GetName()] = command;
private void AddBuiltinCommand(ICommand command) => AddCommand(_builtinCommands, command);
public void AddCommand(ICommand command) => AddCommand(_commands, command);

private void AddCommand(IDictionary<string, ICommand> commands, ICommand command) {
commands[command.GetName()] = command;
if (command is not IAliasable aliasable) return;
foreach (ICommand cmd in aliasable.GetAll(this)) {
AddCommand(commands, cmd);
}
}

public void CopyCommandsTo(ITerminal terminal) {
foreach (ICommand command in _commands.Values) {
terminal.AddCommand(command);
Expand Down

0 comments on commit c93dcf1

Please sign in to comment.