mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Console command completions v1.
I think it works™️
* Unify cvar commands
* Handle no-completions-at-all better.
* Don't crash if you tab complete while no completions available.
* Always show hints if available
* Properly null completion hint over the wire
* Unify help command, localize it.
* Clean up + localize cvar command.
* Remove debug logging
* List command unified & localized.
* Remove server completions debug logging
* Remote execute command.
Had to make everything async for this.
* Don't lower case enums or bools
Why
* GC commands converted and localized.
* Fix remote command completions.
Whoops
* Kick command completions
* lsasm unified & localized.
* Revert "Don't lower case enums or bools"
This reverts commit 2f825347c3.
* ToString gc_mode command enums instead of trying to fix Fluent.
Ah well.
* Unify szr_stats
* Unify log commands, completions
* Fix compile
* Improve completion with complex cases (quotes, escapes)
* Code cleanup, comments.
* Fix tab completion with empty arg ruining everything.
* Fix RegisteredCommand completions
* Add more complex completion options system.
* Refactor content directory entries into a proper resource manager API.
* Implement GetEntries for DirLoader
* Make type hint darker.
* Exec command autocomplete, pulled play global sound code out to engine.
71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using System.Text.RegularExpressions;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.ContentPack;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Shared.Console.Commands
|
|
{
|
|
[UsedImplicitly]
|
|
internal sealed class ExecCommand : IConsoleCommand
|
|
{
|
|
private static readonly Regex CommentRegex = new Regex(@"^\s*#");
|
|
|
|
public string Command => "exec";
|
|
public string Description => Loc.GetString("cmd-exec-desc");
|
|
public string Help => Loc.GetString("cmd-exec-help");
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
var res = IoCManager.Resolve<IResourceManager>();
|
|
|
|
if (args.Length < 1)
|
|
{
|
|
shell.WriteError("No file specified!");
|
|
return;
|
|
}
|
|
|
|
var path = new ResourcePath(args[0]).ToRootedPath();
|
|
if (!res.UserData.Exists(path))
|
|
{
|
|
shell.WriteError("File does not exist.");
|
|
return;
|
|
}
|
|
|
|
using var text = res.UserData.OpenText(path);
|
|
while (true)
|
|
{
|
|
var line = text.ReadLine();
|
|
if (line == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(line) || CommentRegex.IsMatch(line))
|
|
{
|
|
// Comment or whitespace.
|
|
continue;
|
|
}
|
|
|
|
shell.ConsoleHost.AppendCommand(line);
|
|
}
|
|
}
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
var res = IoCManager.Resolve<IResourceManager>();
|
|
|
|
var hint = Loc.GetString("cmd-exec-arg-filename");
|
|
var options = CompletionHelper.UserFilePath(args[0], res.UserData);
|
|
|
|
return CompletionResult.FromHintOptions(options, hint);
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
}
|