Refactor process lifecycle to use Start, Tick, Stop methods and metrics

This commit is contained in:
Stone_Red
2026-06-10 02:28:57 +02:00
parent 31e54c1637
commit b3c98b1b1d
7 changed files with 163 additions and 81 deletions
+50 -13
View File
@@ -5,29 +5,66 @@ namespace RemSox.Processes;
internal class CliProcess() : Process("Cli")
{
internal override void Run(string[] args)
private string currentInput = string.Empty;
internal override void Start(string[] args)
{
Console.Clear();
Console.WriteLine("Welcome RemSox!");
Console.WriteLine("Type 'help' to see available commands.");
Console.Write("> ");
}
while (!StopRequested)
internal override void Tick()
{
while (Console.KeyAvailable)
{
Console.Write("> ");
ConsoleKeyInfo key = Console.ReadKey(intercept: true);
string? input = Console.ReadLine();
if (string.IsNullOrWhiteSpace(input))
switch (key.Key)
{
continue;
}
case ConsoleKey.Enter:
Console.WriteLine();
bool handled = CommandManager.TryExecute(input, line => Console.WriteLine(line));
HandleCommand(currentInput);
if (!handled)
{
Console.WriteLine($"\"{input}\" is not a command");
currentInput = string.Empty;
Console.Write("> ");
break;
case ConsoleKey.Backspace:
if (currentInput.Length > 0)
{
currentInput = currentInput[..^1];
Console.Write("\b \b");
}
break;
default:
currentInput += key.KeyChar;
Console.Write(key.KeyChar);
break;
}
}
}
}
internal override void Stop()
{
Console.Clear();
}
private static void HandleCommand(string input)
{
if (string.IsNullOrWhiteSpace(input))
return;
bool handled = CommandManager.TryExecute(
input,
line => Console.WriteLine(line));
if (!handled)
{
Console.WriteLine($"\"{input}\" is not a command");
}
}
}