diff --git a/Kernel.cs b/Kernel.cs index 5d10996..b499b20 100644 --- a/Kernel.cs +++ b/Kernel.cs @@ -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(); - } - - Console.WriteLine(CosmosFeatures.MouseEnabled); - Console.WriteLine(CosmosFeatures.KeyboardEnabled); + ProcessManager.SpawnProcess(); } protected override void Run() { - if (Processes.DesktopProcess.IsRunning) + bool desktopRunning = ProcessManager.IsProcessRunning(); + bool cliRunning = ProcessManager.IsProcessRunning(); + + if (!desktopRunning && !cliRunning) { - // Suspend the CLI while the GUI is active to prevent blocking and console corruption. - Thread.Sleep(1000); + ProcessManager.SpawnProcess(); return; } - Console.Write("> "); - - string? input = Console.ReadLine(); - - if (string.IsNullOrEmpty(input)) + if (desktopRunning && cliRunning) { - return; + foreach (Process process in ProcessManager.GetProcessesOfType()) + { + 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; diff --git a/Processes/CliProcess.cs b/Processes/CliProcess.cs new file mode 100644 index 0000000..a38ee3b --- /dev/null +++ b/Processes/CliProcess.cs @@ -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"); + } + } + } +} diff --git a/UI/CLI/Commands/StartGuiCommand.cs b/UI/CLI/Commands/StartGuiCommand.cs index e3ee874..e0b7e89 100644 --- a/UI/CLI/Commands/StartGuiCommand.cs +++ b/UI/CLI/Commands/StartGuiCommand.cs @@ -11,6 +11,18 @@ public class StartGuiCommand : ICommand public void Execute(string? arguments, Action printLine) { printLine("Starting Desktop Process..."); + + if (ProcessManager.IsProcessRunning()) + { + printLine("Desktop Process is already running."); + return; + } + + foreach (Process process in ProcessManager.GetProcessesOfType()) + { + ProcessManager.StopProcess(process.Id); + } + _ = ProcessManager.SpawnProcess(); } } diff --git a/UI/CLI/Commands/StopGuiCommand.cs b/UI/CLI/Commands/StopGuiCommand.cs new file mode 100644 index 0000000..9bc2dbb --- /dev/null +++ b/UI/CLI/Commands/StopGuiCommand.cs @@ -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 printLine) + { + printLine("Stopping Desktop Process..."); + + if (!ProcessManager.IsProcessRunning()) + { + printLine("Desktop Process is not running."); + return; + } + + foreach (Process process in ProcessManager.GetProcessesOfType()) + { + await ProcessManager.StopProcessAndWaitAsync(process.Id); + } + + _ = ProcessManager.SpawnProcess(); + } +}