mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
Add CLI process and GUI start/stop commands with process management
This commit is contained in:
@@ -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.
|
||||
ProcessManager.SpawnProcess<CliProcess>();
|
||||
return;
|
||||
}
|
||||
|
||||
if (desktopRunning && cliRunning)
|
||||
{
|
||||
foreach (Process process in ProcessManager.GetProcessesOfType<CliProcess>())
|
||||
{
|
||||
ProcessManager.StopProcess(process.Id);
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1000);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.Write("> ");
|
||||
|
||||
string? input = Console.ReadLine();
|
||||
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (CommandManager.TryExecute(input, line => Console.WriteLine(line)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine($"\"{input}\" is not a command");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user