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
+30 -28
View File
@@ -2,6 +2,8 @@ global using Sys = Cosmos.Kernel.System;
using Cosmos.Kernel.Core; using Cosmos.Kernel.Core;
using RemSox.Processes;
using RemSox.Processing;
using RemSox.Processing.IPC; using RemSox.Processing.IPC;
using RemSox.UI.CLI; using RemSox.UI.CLI;
using RemSox.UI.CLI.Commands; using RemSox.UI.CLI.Commands;
@@ -20,62 +22,62 @@ public class Kernel : Sys.Kernel
{ {
protected override void BeforeRun() protected override void BeforeRun()
{ {
Console.WriteLine("Cosmos booted successfully!"); CommandManager.RegisterCommands([
Console.WriteLine("Type a command to get it executed.");
CommandManager.RegisterCommands(
[
new HelpCommand(), new HelpCommand(),
new ClearCommand(), new ClearCommand(),
new HaltCommand(), new HaltCommand(),
new SpawnTestProcessCommand(), new SpawnTestProcessCommand(),
new ListProcessesCommand(), new ListProcessesCommand(),
new StopProcessCommand(), new StopProcessCommand(),
new StartGuiCommand() new StartGuiCommand(),
new StopGuiCommand()
]); ]);
Sys.Mouse.MouseManager.Initialize(); Sys.Mouse.MouseManager.Initialize();
Sys.Keyboard.KeyboardManager.Initialize(); Sys.Keyboard.KeyboardManager.Initialize();
for (int i = 0; i < 5; i++) ProcessManager.SpawnProcess<CliProcess>();
{
//ProcessManager.SpawnProcess<TestProcess>();
}
Console.WriteLine(CosmosFeatures.MouseEnabled);
Console.WriteLine(CosmosFeatures.KeyboardEnabled);
} }
protected override void Run() 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. ProcessManager.SpawnProcess<CliProcess>();
return;
}
if (desktopRunning && cliRunning)
{
foreach (Process process in ProcessManager.GetProcessesOfType<CliProcess>())
{
ProcessManager.StopProcess(process.Id);
}
}
Thread.Sleep(1000); Thread.Sleep(1000);
return; }
} }
Console.Write("> ");
string? input = Console.ReadLine();
if (string.IsNullOrEmpty(input)) [AttributeUsage(AttributeTargets.Class)]
public class TestAttribute : Attribute
{ {
return; public string Name { get; set; } = "default";
} }
if (CommandManager.TryExecute(input, line => Console.WriteLine(line))) [Test(Name = "HelloCosmos")]
public class TestClass
{ {
return;
} }
Console.WriteLine($"\"{input}\" is not a command"); public class TestProcess() : Process("Test Process")
}
}
public class TestProcess() : Processing.Process("Test Process")
{ {
internal override void Run() internal override void Run(string[] args)
{ {
Window window = WindowManager.CreateWindow(this, "Test Window", Point.Empty, new Size(200, 150)); Window window = WindowManager.CreateWindow(this, "Test Window", Point.Empty, new Size(200, 150));
window.AutoFlush = true; 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) public void Execute(string? arguments, Action<string> printLine)
{ {
printLine("Starting Desktop Process..."); 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>(); _ = 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>();
}
}