mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
Add printLine support for commands and implement basic UI controls rendering
This commit is contained in:
@@ -41,7 +41,7 @@ public class Kernel : Sys.Kernel
|
|||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
ProcessManager.SpawnProcess<TestProcess>();
|
//ProcessManager.SpawnProcess<TestProcess>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine(CosmosFeatures.MouseEnabled);
|
Console.WriteLine(CosmosFeatures.MouseEnabled);
|
||||||
@@ -66,7 +66,7 @@ public class Kernel : Sys.Kernel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CommandManager.TryExecute(input))
|
if (CommandManager.TryExecute(input, line => Console.WriteLine(line)))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,34 @@ public class DesktopProcess : Process
|
|||||||
// Start the terminal process within the desktop environment
|
// Start the terminal process within the desktop environment
|
||||||
ProcessManager.SpawnProcess<TerminalProcess>();
|
ProcessManager.SpawnProcess<TerminalProcess>();
|
||||||
|
|
||||||
|
// Create a test window for new UI controls
|
||||||
|
Window testWindow = WindowManager.CreateWindow(this, "UI Controls Test", new System.Drawing.Point(500, 50), new System.Drawing.Size(200, 180));
|
||||||
|
|
||||||
|
testWindow.CreateUIElement<RemSox.UI.GUI.UIEelements.Controls.Button>(b =>
|
||||||
|
{
|
||||||
|
b.Position = new System.Drawing.Point(20, 30);
|
||||||
|
b.Size = new System.Drawing.Size(100, 30);
|
||||||
|
b.Text = "Click Me";
|
||||||
|
b.BackgroundColor = System.Drawing.Color.LightBlue;
|
||||||
|
});
|
||||||
|
|
||||||
|
testWindow.CreateUIElement<RemSox.UI.GUI.UIEelements.Controls.CheckBox>(c =>
|
||||||
|
{
|
||||||
|
c.Position = new System.Drawing.Point(20, 80);
|
||||||
|
c.Text = "Check Me";
|
||||||
|
c.IsChecked = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
testWindow.CreateUIElement<RemSox.UI.GUI.UIEelements.Shapes.Line>(l =>
|
||||||
|
{
|
||||||
|
l.Position = new System.Drawing.Point(20, 130);
|
||||||
|
l.EndPosition = new System.Drawing.Point(180, 130);
|
||||||
|
l.Color = System.Drawing.Color.Red;
|
||||||
|
});
|
||||||
|
|
||||||
|
testWindow.AutoFlush = true;
|
||||||
|
testWindow.Flush();
|
||||||
|
|
||||||
while (!StopRequested)
|
while (!StopRequested)
|
||||||
{
|
{
|
||||||
WindowManager.Update();
|
WindowManager.Update();
|
||||||
|
|||||||
@@ -77,15 +77,11 @@ public class TerminalProcess : Process
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool found = CommandManager.TryExecute(cmd);
|
bool found = CommandManager.TryExecute(cmd, line => PrintLine(line));
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
PrintLine($"\"{cmd}\" is not a command");
|
PrintLine($"\"{cmd}\" is not a command");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
PrintLine("Command executed. (Output sent to background console)");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateDisplay();
|
UpdateDisplay();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public static class CommandManager
|
|||||||
return commands.Values.OrderBy(command => command.Name);
|
return commands.Values.OrderBy(command => command.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryExecute(string input)
|
public static bool TryExecute(string input, Action<string> printLine)
|
||||||
{
|
{
|
||||||
string trimmedInput = input.Trim();
|
string trimmedInput = input.Trim();
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public static class CommandManager
|
|||||||
arguments = trimmedInput.Substring(commandName.Length).TrimStart();
|
arguments = trimmedInput.Substring(commandName.Length).TrimStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.Value.Execute(arguments);
|
entry.Value.Execute(arguments, printLine);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public sealed class ClearCommand : ICommand
|
|||||||
|
|
||||||
public string Description => "Clear the screen";
|
public string Description => "Clear the screen";
|
||||||
|
|
||||||
public void Execute(string? arguments)
|
public void Execute(string? arguments, Action<string> printLine)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ public sealed class HaltCommand : ICommand
|
|||||||
|
|
||||||
public string Description => "Halt the system";
|
public string Description => "Halt the system";
|
||||||
|
|
||||||
public void Execute(string? arguments)
|
public void Execute(string? arguments, Action<string> printLine)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Halting system...");
|
printLine("Halting system...");
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,13 @@ public sealed class HelpCommand : ICommand
|
|||||||
|
|
||||||
public string Description => "Show this help message";
|
public string Description => "Show this help message";
|
||||||
|
|
||||||
public void Execute(string? arguments)
|
public void Execute(string? arguments, Action<string> printLine)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Available commands:");
|
printLine("Available commands:");
|
||||||
|
|
||||||
foreach (ICommand command in CommandManager.GetCommands())
|
foreach (ICommand command in CommandManager.GetCommands())
|
||||||
{
|
{
|
||||||
Console.WriteLine($" {command.Name,-12} - {command.Description}");
|
printLine($" {command.Name,-12} - {command.Description}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,10 +9,10 @@ public sealed class SpawnTestProcessCommand : ICommand
|
|||||||
|
|
||||||
public string Description => "Spawn the test process";
|
public string Description => "Spawn the test process";
|
||||||
|
|
||||||
public void Execute(string? arguments)
|
public void Execute(string? arguments, Action<string> printLine)
|
||||||
{
|
{
|
||||||
int processId = ProcessManager.SpawnProcess<TestProcess>();
|
int processId = ProcessManager.SpawnProcess<TestProcess>();
|
||||||
Console.WriteLine($"Spawned TestProcess with ID {processId}");
|
printLine($"Spawned TestProcess with ID {processId}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,15 +22,15 @@ public sealed class ListProcessesCommand : ICommand
|
|||||||
|
|
||||||
public string Description => "List running processes";
|
public string Description => "List running processes";
|
||||||
|
|
||||||
public void Execute(string? arguments)
|
public void Execute(string? arguments, Action<string> printLine)
|
||||||
{
|
{
|
||||||
IEnumerable<Process> processes = ProcessManager.GetAllProcesses();
|
IEnumerable<Process> processes = ProcessManager.GetAllProcesses();
|
||||||
|
|
||||||
Console.WriteLine("Running processes:");
|
printLine("Running processes:");
|
||||||
|
|
||||||
foreach (Process process in processes)
|
foreach (Process process in processes)
|
||||||
{
|
{
|
||||||
Console.WriteLine($" ID: {process.Id}, Name: {process.Name}");
|
printLine($" ID: {process.Id}, Name: {process.Name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,23 +41,23 @@ public sealed class StopProcessCommand : ICommand
|
|||||||
|
|
||||||
public string Description => "Stop a process by ID";
|
public string Description => "Stop a process by ID";
|
||||||
|
|
||||||
public void Execute(string? arguments)
|
public void Execute(string? arguments, Action<string> printLine)
|
||||||
{
|
{
|
||||||
string? idText = arguments;
|
string? idText = arguments;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(idText))
|
if (string.IsNullOrWhiteSpace(idText))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Usage: stop <process-id>");
|
printLine("Usage: stop <process-id>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (int.TryParse(idText, out int processId))
|
if (int.TryParse(idText, out int processId))
|
||||||
{
|
{
|
||||||
ProcessManager.StopProcess(processId);
|
ProcessManager.StopProcess(processId);
|
||||||
Console.WriteLine($"Stopped process with ID {processId}");
|
printLine($"Stopped process with ID {processId}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Invalid process ID");
|
printLine("Invalid process ID");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-1
@@ -1,10 +1,12 @@
|
|||||||
namespace RemSox.UI.GUI.CLI;
|
namespace RemSox.UI.GUI.CLI;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
public interface ICommand
|
public interface ICommand
|
||||||
{
|
{
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
|
||||||
string Description { get; }
|
string Description { get; }
|
||||||
|
|
||||||
void Execute(string? arguments);
|
void Execute(string? arguments, Action<string> printLine);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ public class StartGuiCommand : ICommand
|
|||||||
public string Name => "start-gui";
|
public string Name => "start-gui";
|
||||||
public string Description => "Starts the Graphical User Interface (Desktop Process)";
|
public string Description => "Starts the Graphical User Interface (Desktop Process)";
|
||||||
|
|
||||||
public void Execute(string? args)
|
public void Execute(string? arguments, Action<string> printLine)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Starting Desktop Process...");
|
printLine("Starting Desktop Process...");
|
||||||
ProcessManager.SpawnProcess<DesktopProcess>();
|
ProcessManager.SpawnProcess<DesktopProcess>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,21 @@ public sealed class CanvasRenderSource : IRenderSource
|
|||||||
{
|
{
|
||||||
RenderText(windowCanvas, command);
|
RenderText(windowCanvas, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command.ElementType == "Line")
|
||||||
|
{
|
||||||
|
RenderLine(windowCanvas, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.ElementType == "Button")
|
||||||
|
{
|
||||||
|
RenderButton(windowCanvas, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.ElementType == "CheckBox")
|
||||||
|
{
|
||||||
|
RenderCheckBox(windowCanvas, command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
@@ -111,7 +126,7 @@ public sealed class CanvasRenderSource : IRenderSource
|
|||||||
isZOrderDirty = false;
|
isZOrderDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//screenCanvas.Clear(Color.Black);
|
screenCanvas.Clear(Color.Black);
|
||||||
|
|
||||||
foreach (var windowId in orderedWindowsCache)
|
foreach (var windowId in orderedWindowsCache)
|
||||||
{
|
{
|
||||||
@@ -195,7 +210,61 @@ public sealed class CanvasRenderSource : IRenderSource
|
|||||||
|
|
||||||
if (!string.IsNullOrEmpty(content))
|
if (!string.IsNullOrEmpty(content))
|
||||||
{
|
{
|
||||||
canvas.DrawString(content, Cosmos.Kernel.System.Graphics.Fonts.PCScreenFont.DefaultFont, color, command.Position.X, command.Position.Y);
|
canvas.DrawString(content, PCScreenFont.DefaultFont, color, command.Position.X, command.Position.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RenderLine(Canvas canvas, RenderCommand command)
|
||||||
|
{
|
||||||
|
Color color = command.Properties.TryGetValue("Color", out object? rawColor) && rawColor is Color lineColor
|
||||||
|
? lineColor
|
||||||
|
: Color.White;
|
||||||
|
|
||||||
|
Point endPosition = command.Properties.TryGetValue("EndPosition", out object? rawEnd) && rawEnd is Point endPoint
|
||||||
|
? endPoint
|
||||||
|
: command.Position;
|
||||||
|
|
||||||
|
canvas.DrawLine(color, command.Position.X, command.Position.Y, endPosition.X, endPosition.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RenderButton(Canvas canvas, RenderCommand command)
|
||||||
|
{
|
||||||
|
Color bgColor = command.Properties.TryGetValue("BackgroundColor", out object? rawBgColor) && rawBgColor is Color c1 ? c1 : Color.LightGray;
|
||||||
|
Color textColor = command.Properties.TryGetValue("TextColor", out object? rawTextColor) && rawTextColor is Color c2 ? c2 : Color.Black;
|
||||||
|
Size size = command.Properties.TryGetValue("Size", out object? rawSize) && rawSize is Size s ? s : new Size(60, 20);
|
||||||
|
string text = command.Properties.TryGetValue("Text", out object? rawText) && rawText is string t ? t : string.Empty;
|
||||||
|
|
||||||
|
canvas.DrawFilledRectangle(bgColor, command.Position.X, command.Position.Y, size.Width, size.Height);
|
||||||
|
canvas.DrawRectangle(Color.DarkGray, command.Position.X, command.Position.Y, size.Width, size.Height);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
int textX = command.Position.X + (size.Width / 2) - (text.Length * 8 / 2);
|
||||||
|
int textY = command.Position.Y + (size.Height / 2) - 8;
|
||||||
|
canvas.DrawString(text, PCScreenFont.DefaultFont, textColor, textX, textY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RenderCheckBox(Canvas canvas, RenderCommand command)
|
||||||
|
{
|
||||||
|
Color bgColor = command.Properties.TryGetValue("BackgroundColor", out object? rawBgColor) && rawBgColor is Color c1 ? c1 : Color.LightGray;
|
||||||
|
Color textColor = command.Properties.TryGetValue("TextColor", out object? rawTextColor) && rawTextColor is Color c2 ? c2 : Color.White;
|
||||||
|
bool isChecked = command.Properties.TryGetValue("IsChecked", out object? rawChecked) && rawChecked is bool chk ? chk : false;
|
||||||
|
string text = command.Properties.TryGetValue("Text", out object? rawText) && rawText is string t ? t : string.Empty;
|
||||||
|
|
||||||
|
int boxSize = 12;
|
||||||
|
|
||||||
|
canvas.DrawFilledRectangle(bgColor, command.Position.X, command.Position.Y, boxSize, boxSize);
|
||||||
|
canvas.DrawRectangle(Color.DarkGray, command.Position.X, command.Position.Y, boxSize, boxSize);
|
||||||
|
|
||||||
|
if (isChecked)
|
||||||
|
{
|
||||||
|
canvas.DrawFilledRectangle(Color.Black, command.Position.X + 3, command.Position.Y + 3, boxSize - 6, boxSize - 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
canvas.DrawString(text, PCScreenFont.DefaultFont, textColor, command.Position.X + boxSize + 5, command.Position.Y - 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace RemSox.UI.GUI.UIEelements.Controls;
|
||||||
|
|
||||||
|
public class Button() : Control("Button")
|
||||||
|
{
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set => SetProperty(nameof(Text), ref field, value);
|
||||||
|
} = string.Empty;
|
||||||
|
|
||||||
|
public Color TextColor
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set => SetProperty(nameof(TextColor), ref field, value);
|
||||||
|
} = Color.Black;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace RemSox.UI.GUI.UIEelements.Controls;
|
||||||
|
|
||||||
|
public class CheckBox() : Control("CheckBox")
|
||||||
|
{
|
||||||
|
public bool IsChecked
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set => SetProperty(nameof(IsChecked), ref field, value);
|
||||||
|
} = false;
|
||||||
|
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set => SetProperty(nameof(Text), ref field, value);
|
||||||
|
} = string.Empty;
|
||||||
|
|
||||||
|
public Color TextColor
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set => SetProperty(nameof(TextColor), ref field, value);
|
||||||
|
} = Color.White;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
||||||
|
|
||||||
|
public class Line() : Shape("Line")
|
||||||
|
{
|
||||||
|
public Point EndPosition
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set => SetProperty(nameof(EndPosition), ref field, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user