Add printLine support for commands and implement basic UI controls rendering

This commit is contained in:
Stone_Red
2026-06-08 19:51:22 +02:00
parent fc71af028f
commit 8b900c9d58
14 changed files with 178 additions and 29 deletions
+2 -2
View File
@@ -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;
}
+1 -1
View File
@@ -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();
}
+2 -2
View File
@@ -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);
}
}
+3 -3
View File
@@ -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 -9
View File
@@ -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
View File
@@ -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);
}