Skip to content

Add /clear as an alias to /cls #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion shell/AIShell.Kernel/Command/ClearCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ namespace AIShell.Kernel.Commands;
internal sealed class ClearCommand : CommandBase
{
public ClearCommand()
: base("cls", "Clear the screen.")
: base("clear", "Clear the screen.")
{
this.SetHandler(ClearAction);
this.AddAlias("cls");
}

private void ClearAction()
Expand Down
17 changes: 15 additions & 2 deletions shell/AIShell.Kernel/Command/CommandRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ internal void LoadCommands(IEnumerable<CommandBase> commands, string agentName)
{
command.Shell = _shell;
command.Source = agentName;
_commands.Add(command.Name, command);

// The 'command.Name' is included in the 'command.Aliases' collection.
// TODO: need to think about how to handle command names/aliases collision.
// We don't handle collision today -- it will throw when collision happens.
foreach (string alias in command.Aliases)
{
_commands.Add(alias, command);
}
}
}

Expand All @@ -79,7 +86,13 @@ internal void UnloadAgentCommands()

foreach (var command in agentCommands)
{
_commands.Remove(command.Name);
// The 'command.Name' is included in the 'command.Aliases' collection.
// TODO: need to update accordingly when we handle command names/aliases collision.
foreach (string alias in command.Aliases)
{
_commands.Remove(alias);
}

command.Dispose();
}
}
Expand Down
2 changes: 1 addition & 1 deletion shell/AIShell.Kernel/Command/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private void HelpAction()
var host = shellImpl.Host;

var commands = shellImpl.CommandRunner.Commands;
var list = commands.Values.Order(new CommandComparer()).ToList();
var list = commands.Values.Distinct().Order(new CommandComparer()).ToList();

host.WriteLine();
host.MarkupLine("[bold white]-[/] Type then press [bold olive underline]Enter[/] to chat with the chosen AI agent.");
Expand Down