mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-06 15:56:29 +02:00
Add printLine support for commands and implement basic UI controls rendering
This commit is contained in:
@@ -24,7 +24,7 @@ public static class CommandManager
|
||||
return commands.Values.OrderBy(command => command.Name);
|
||||
}
|
||||
|
||||
public static bool TryExecute(string input)
|
||||
public static bool TryExecute(string input, Action<string> printLine)
|
||||
{
|
||||
string trimmedInput = input.Trim();
|
||||
|
||||
@@ -51,7 +51,7 @@ public static class CommandManager
|
||||
arguments = trimmedInput.Substring(commandName.Length).TrimStart();
|
||||
}
|
||||
|
||||
entry.Value.Execute(arguments);
|
||||
entry.Value.Execute(arguments, printLine);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public sealed class ClearCommand : ICommand
|
||||
|
||||
public string Description => "Clear the screen";
|
||||
|
||||
public void Execute(string? arguments)
|
||||
public void Execute(string? arguments, Action<string> printLine)
|
||||
{
|
||||
Console.Clear();
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ public sealed class HaltCommand : ICommand
|
||||
|
||||
public string Description => "Halt the system";
|
||||
|
||||
public void Execute(string? arguments)
|
||||
public void Execute(string? arguments, Action<string> printLine)
|
||||
{
|
||||
Console.WriteLine("Halting system...");
|
||||
printLine("Halting system...");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,13 @@ public sealed class HelpCommand : ICommand
|
||||
|
||||
public string Description => "Show this help message";
|
||||
|
||||
public void Execute(string? arguments)
|
||||
public void Execute(string? arguments, Action<string> printLine)
|
||||
{
|
||||
Console.WriteLine("Available commands:");
|
||||
printLine("Available commands:");
|
||||
|
||||
foreach (ICommand command in CommandManager.GetCommands())
|
||||
{
|
||||
Console.WriteLine($" {command.Name,-12} - {command.Description}");
|
||||
printLine($" {command.Name,-12} - {command.Description}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,10 @@ public sealed class SpawnTestProcessCommand : ICommand
|
||||
|
||||
public string Description => "Spawn the test process";
|
||||
|
||||
public void Execute(string? arguments)
|
||||
public void Execute(string? arguments, Action<string> printLine)
|
||||
{
|
||||
int processId = ProcessManager.SpawnProcess<TestProcess>();
|
||||
Console.WriteLine($"Spawned TestProcess with ID {processId}");
|
||||
printLine($"Spawned TestProcess with ID {processId}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ public sealed class ListProcessesCommand : ICommand
|
||||
|
||||
public string Description => "List running processes";
|
||||
|
||||
public void Execute(string? arguments)
|
||||
public void Execute(string? arguments, Action<string> printLine)
|
||||
{
|
||||
IEnumerable<Process> processes = ProcessManager.GetAllProcesses();
|
||||
|
||||
Console.WriteLine("Running processes:");
|
||||
printLine("Running processes:");
|
||||
|
||||
foreach (Process process in processes)
|
||||
{
|
||||
Console.WriteLine($" ID: {process.Id}, Name: {process.Name}");
|
||||
printLine($" ID: {process.Id}, Name: {process.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,23 +41,23 @@ public sealed class StopProcessCommand : ICommand
|
||||
|
||||
public string Description => "Stop a process by ID";
|
||||
|
||||
public void Execute(string? arguments)
|
||||
public void Execute(string? arguments, Action<string> printLine)
|
||||
{
|
||||
string? idText = arguments;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(idText))
|
||||
{
|
||||
Console.WriteLine("Usage: stop <process-id>");
|
||||
printLine("Usage: stop <process-id>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (int.TryParse(idText, out int processId))
|
||||
{
|
||||
ProcessManager.StopProcess(processId);
|
||||
Console.WriteLine($"Stopped process with ID {processId}");
|
||||
printLine($"Stopped process with ID {processId}");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Invalid process ID");
|
||||
printLine("Invalid process ID");
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -1,10 +1,12 @@
|
||||
namespace RemSox.UI.GUI.CLI;
|
||||
|
||||
using System;
|
||||
|
||||
public interface ICommand
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
string Description { get; }
|
||||
|
||||
void Execute(string? arguments);
|
||||
void Execute(string? arguments, Action<string> printLine);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user