Add CLI process and GUI start/stop commands with process management

This commit is contained in:
Stone_Red
2026-06-09 22:55:51 +02:00
parent f7eea21de5
commit a583a5ab44
4 changed files with 108 additions and 30 deletions
+32 -30
View File
@@ -2,6 +2,8 @@ global using Sys = Cosmos.Kernel.System;
using Cosmos.Kernel.Core;
using RemSox.Processes;
using RemSox.Processing;
using RemSox.Processing.IPC;
using RemSox.UI.CLI;
using RemSox.UI.CLI.Commands;
@@ -20,62 +22,62 @@ public class Kernel : Sys.Kernel
{
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully!");
Console.WriteLine("Type a command to get it executed.");
CommandManager.RegisterCommands(
[
CommandManager.RegisterCommands([
new HelpCommand(),
new ClearCommand(),
new HaltCommand(),
new SpawnTestProcessCommand(),
new ListProcessesCommand(),
new StopProcessCommand(),
new StartGuiCommand()
new StartGuiCommand(),
new StopGuiCommand()
]);
Sys.Mouse.MouseManager.Initialize();
Sys.Keyboard.KeyboardManager.Initialize();
for (int i = 0; i < 5; i++)
{
//ProcessManager.SpawnProcess<TestProcess>();
}
Console.WriteLine(CosmosFeatures.MouseEnabled);
Console.WriteLine(CosmosFeatures.KeyboardEnabled);
ProcessManager.SpawnProcess<CliProcess>();
}
protected override void Run()
{
if (Processes.DesktopProcess.IsRunning)
bool desktopRunning = ProcessManager.IsProcessRunning<DesktopProcess>();
bool cliRunning = ProcessManager.IsProcessRunning<CliProcess>();
if (!desktopRunning && !cliRunning)
{
// Suspend the CLI while the GUI is active to prevent blocking and console corruption.
Thread.Sleep(1000);
ProcessManager.SpawnProcess<CliProcess>();
return;
}
Console.Write("> ");
string? input = Console.ReadLine();
if (string.IsNullOrEmpty(input))
if (desktopRunning && cliRunning)
{
return;
foreach (Process process in ProcessManager.GetProcessesOfType<CliProcess>())
{
ProcessManager.StopProcess(process.Id);
}
}
if (CommandManager.TryExecute(input, line => Console.WriteLine(line)))
{
return;
}
Console.WriteLine($"\"{input}\" is not a command");
Thread.Sleep(1000);
}
}
public class TestProcess() : Processing.Process("Test Process")
[AttributeUsage(AttributeTargets.Class)]
public class TestAttribute : Attribute
{
internal override void Run()
public string Name { get; set; } = "default";
}
[Test(Name = "HelloCosmos")]
public class TestClass
{
}
public class TestProcess() : Process("Test Process")
{
internal override void Run(string[] args)
{
Window window = WindowManager.CreateWindow(this, "Test Window", Point.Empty, new Size(200, 150));
window.AutoFlush = true;
+33
View File
@@ -0,0 +1,33 @@
using RemSox.Processing;
using RemSox.UI.CLI;
namespace RemSox.Processes;
internal class CliProcess() : Process("Cli")
{
internal override void Run(string[] args)
{
Console.Clear();
Console.WriteLine("Welcome RemSox!");
Console.WriteLine("Type 'help' to see available commands.");
while (!StopRequested)
{
Console.Write("> ");
string? input = Console.ReadLine();
if (string.IsNullOrWhiteSpace(input))
{
continue;
}
bool handled = CommandManager.TryExecute(input, line => Console.WriteLine(line));
if (!handled)
{
Console.WriteLine($"\"{input}\" is not a command");
}
}
}
}
+12
View File
@@ -11,6 +11,18 @@ public class StartGuiCommand : ICommand
public void Execute(string? arguments, Action<string> printLine)
{
printLine("Starting Desktop Process...");
if (ProcessManager.IsProcessRunning<DesktopProcess>())
{
printLine("Desktop Process is already running.");
return;
}
foreach (Process process in ProcessManager.GetProcessesOfType<CliProcess>())
{
ProcessManager.StopProcess(process.Id);
}
_ = ProcessManager.SpawnProcess<DesktopProcess>();
}
}
+31
View File
@@ -0,0 +1,31 @@
using Cosmos.Kernel.System.Graphics;
using Org.BouncyCastle.Bcpg;
using RemSox.Processes;
using RemSox.Processing;
using RemSox.UI.GUI.Windows;
namespace RemSox.UI.CLI.Commands;
public class StopGuiCommand : ICommand
{
public string Name => "stop-gui";
public string Description => "Stops the Graphical User Interface (Desktop Process)";
public async void Execute(string? arguments, Action<string> printLine)
{
printLine("Stopping Desktop Process...");
if (!ProcessManager.IsProcessRunning<DesktopProcess>())
{
printLine("Desktop Process is not running.");
return;
}
foreach (Process process in ProcessManager.GetProcessesOfType<DesktopProcess>())
{
await ProcessManager.StopProcessAndWaitAsync(process.Id);
}
_ = ProcessManager.SpawnProcess<CliProcess>();
}
}