diff --git a/TermEngine/CommandInterpreter.cs b/TermEngine/CommandInterpreter.cs deleted file mode 100644 index 1bba8b8..0000000 --- a/TermEngine/CommandInterpreter.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - - -public class CommandInterpreter -{ - public readonly Dictionary _commands = new(); - - public CommandInterpreter() - { - - RegisterCommand(new GreetCommand()); - RegisterCommand(new HelpCommand(this)); - - } - public void RegisterCommand(ICommand command) - { - - _commands[command.Name.ToLower()] = command; - - } - - public void Execute(string input) - { - string[] parts = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); - if (parts.Length == 0) return; - - string commandName = parts[0].ToLower(); - string[] args = parts.Length > 1 ? parts[1..] : new string[0]; - - if (_commands.TryGetValue(commandName, out var command)) - { - - command.Execute(args); - - } - else - { - Console.WriteLine("Err - uknown Command : '{commandName}'. Type help For a list of commands"); - } - - - } - - public IEnumerable GetAllCommands() - { - - return _commands.Values; - - } - - -} \ No newline at end of file diff --git a/TermEngine/Commands/AddCommand.cs b/TermEngine/Commands/AddCommand.cs new file mode 100644 index 0000000..566e140 --- /dev/null +++ b/TermEngine/Commands/AddCommand.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel; +using TermApp.Core; + + +namespace TermApp.Commands +{ + + +public class AddCommand : ICommand +{ + public string Name => "add"; + public string Description => "Adds two integers together args : a + b"; + + public void Execute(string[] args, string input = null) + { + + if (args.Length < 1) + { + + Console.WriteLine(Description); + return; + + } + + if (int.TryParse(args[0], out int a) && int.TryParse(args[1], out int b)) + { + + int result = a + b; + Console.WriteLine(result); + return; + + } + else + { + + Console.WriteLine("Make sure Both Args are integers!"); + + } + + + + } + +} +} diff --git a/TermEngine/Commands/ClearCommand.cs b/TermEngine/Commands/ClearCommand.cs new file mode 100644 index 0000000..d924109 --- /dev/null +++ b/TermEngine/Commands/ClearCommand.cs @@ -0,0 +1,26 @@ +using TermApp.Core; + +namespace TermApp.Commands +{ + + public class ClearCommand : ICommand + { + + public string Name => "clear"; + public string Description => "Clears the Terminal"; + + public void Execute(string[] args, string input = null) + { + + Console.Clear(); + if (args.Length != 0) + { + if (args[0] == "log") Console.WriteLine("Cleared :)"); + + } + + } + + } + +} \ No newline at end of file diff --git a/TermEngine/Commands/EchoCommand.cs b/TermEngine/Commands/EchoCommand.cs new file mode 100644 index 0000000..cd6a882 --- /dev/null +++ b/TermEngine/Commands/EchoCommand.cs @@ -0,0 +1,31 @@ +using TermApp.Core; +using System; +using System.ComponentModel; + + +namespace TermApp.Commands +{ + + public class EchoCommand : ICommand + { + + public string Name => "echo"; + public string Description => "Prints Input"; + + + public void Execute(string[] args, string input = null) + { + + if (args.Length > 0) + Console.WriteLine(String.Join(" ", args)); + else if (input != null) + Console.WriteLine(input); + else + Console.WriteLine(); + + } + + } + + +} \ No newline at end of file diff --git a/TermEngine/GreetCommand.cs b/TermEngine/Commands/GreetCommand.cs similarity index 65% rename from TermEngine/GreetCommand.cs rename to TermEngine/Commands/GreetCommand.cs index 32a35bf..1c5ac93 100644 --- a/TermEngine/GreetCommand.cs +++ b/TermEngine/Commands/GreetCommand.cs @@ -1,11 +1,15 @@ using System; +using TermApp.Core; -public class GreetCommand : ICommand +namespace TermApp.Commands +{ + + public class GreetCommand : ICommand { public string Name => "greet"; public string Description => "greets someone.. args [name]"; - public void Execute(string[] args) + public void Execute(string[] args, string input = null) { if (args.Length == 0) @@ -19,4 +23,7 @@ public class GreetCommand : ICommand Console.WriteLine("Greetings , " + args[0]); } -} \ No newline at end of file +} + +} + diff --git a/TermEngine/HelpCommand.cs b/TermEngine/Commands/HelpCommand.cs similarity index 72% rename from TermEngine/HelpCommand.cs rename to TermEngine/Commands/HelpCommand.cs index 071e2c2..a8e06d6 100644 --- a/TermEngine/HelpCommand.cs +++ b/TermEngine/Commands/HelpCommand.cs @@ -1,4 +1,10 @@ using System; +using TermApp.Core; + +namespace TermApp.Commands +{ + + public class HelpCommand : ICommand { @@ -13,10 +19,10 @@ public class HelpCommand : ICommand public string Name => "help"; public String Description => "Shows the Help pop Up"; - public void Execute(string[] args) + public void Execute(string[] args, string input = null) { Console.WriteLine("Avaliable Commands:"); - foreach (var cmd in _interpreter.GetAllCommands()) + foreach (var cmd in _interpreter.GetAllCommands()) { Console.WriteLine($"Command : {cmd.Name} | {cmd.Description}"); @@ -24,4 +30,6 @@ public class HelpCommand : ICommand } -} \ No newline at end of file +} +} + diff --git a/TermEngine/Core/CommandInterpreter.cs b/TermEngine/Core/CommandInterpreter.cs new file mode 100644 index 0000000..ba9710f --- /dev/null +++ b/TermEngine/Core/CommandInterpreter.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using TermApp.Commands; + + + +namespace TermApp.Core +{ + + public class CommandInterpreter + { + public readonly Dictionary _commands = new(); + + public CommandInterpreter() + { + + RegisterCommand(new GreetCommand()); + RegisterCommand(new HelpCommand(this)); + RegisterCommand(new AddCommand()); + RegisterCommand(new EchoCommand()); + RegisterCommand(new ClearCommand()); + + } + public void RegisterCommand(ICommand command) + { + + _commands[command.Name.ToLower()] = command; + + } + + public void Execute(string input) + { + + string[] pipedCommands = input.Split("|", StringSplitOptions.RemoveEmptyEntries); + string pipedOutput = null; + + foreach (var cmdInput in pipedCommands) + { + + string trimmed = cmdInput.Trim(); + + string[] parts = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); + if (parts.Length == 0) continue; + string commandName = parts[0].ToLower(); + string[] args = parts.Length > 1 ? parts[1..] : new string[0]; + + + + if (_commands.TryGetValue(commandName, out var command)) + { + + command.Execute(args); + + } + else + { + Console.WriteLine($"Err - uknown Command : '{commandName}'. Type help For a list of commands"); + return; + } + + + } + + + if (!string.IsNullOrWhiteSpace(pipedOutput)) + { + + Console.WriteLine(pipedOutput); + + } + + } + + + + + + + + public IEnumerable GetAllCommands() + { + + return _commands.Values; + + } + + + } +} + diff --git a/TermEngine/Core/ICOmmand.cs b/TermEngine/Core/ICOmmand.cs new file mode 100644 index 0000000..35d72c8 --- /dev/null +++ b/TermEngine/Core/ICOmmand.cs @@ -0,0 +1,14 @@ +namespace TermApp.Core +{ + + public interface ICommand + { + + string Name { get; } + string Description { get; } + void Execute(string[] args, string input = null); + + } + +} + diff --git a/TermEngine/ICOmmand.cs b/TermEngine/ICOmmand.cs deleted file mode 100644 index a7756e6..0000000 --- a/TermEngine/ICOmmand.cs +++ /dev/null @@ -1,8 +0,0 @@ -public interface ICommand -{ - - string Name { get; } - string Description { get; } - void Execute(string[] args); - -} \ No newline at end of file diff --git a/TermEngine/Program.cs b/TermEngine/Program.cs index 443edbe..6ab08ab 100644 --- a/TermEngine/Program.cs +++ b/TermEngine/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using TermApp.Core; namespace TermApp { @@ -8,20 +9,21 @@ namespace TermApp static void Main(string[] args) { - + Console.WriteLine("Hello, Works!"); CommandInterpreter interpreter = new CommandInterpreter(); Console.WriteLine("Type help to see avaliable Commands :.) or type exit to quit"); - + string lastCommand = "Command Cache :)"; while (true) { - Console.Write("Input >"); - string input = Console.ReadLine(); + Console.Write($"[{lastCommand}] - Input >"); + string input = Console.ReadLine() ?? throw new ArgumentException(); + lastCommand = input; if (string.IsNullOrWhiteSpace(input)) continue; - if (input.ToLower() == "exit") break; + if (input.ToLower() == "exit" || input.ToLower() == "e") break; interpreter.Execute(input); diff --git a/TermEngine/bin/Debug/net8.0/TermEngine.dll b/TermEngine/bin/Debug/net8.0/TermEngine.dll index de21ca4..9277044 100644 Binary files a/TermEngine/bin/Debug/net8.0/TermEngine.dll and b/TermEngine/bin/Debug/net8.0/TermEngine.dll differ diff --git a/TermEngine/bin/Debug/net8.0/TermEngine.pdb b/TermEngine/bin/Debug/net8.0/TermEngine.pdb index ce4dbc2..4d5c4d9 100644 Binary files a/TermEngine/bin/Debug/net8.0/TermEngine.pdb and b/TermEngine/bin/Debug/net8.0/TermEngine.pdb differ diff --git a/TermEngine/obj/Debug/net8.0/TermEngine.AssemblyInfo.cs b/TermEngine/obj/Debug/net8.0/TermEngine.AssemblyInfo.cs index c812d7e..bb13ff9 100644 --- a/TermEngine/obj/Debug/net8.0/TermEngine.AssemblyInfo.cs +++ b/TermEngine/obj/Debug/net8.0/TermEngine.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("TermEngine")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+fd78d9283e191920ee4f6e700fc03391a8880f43")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e3dc8d9d420fc51fad3a8526f470c6c1f428a000")] [assembly: System.Reflection.AssemblyProductAttribute("TermEngine")] [assembly: System.Reflection.AssemblyTitleAttribute("TermEngine")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/TermEngine/obj/Debug/net8.0/TermEngine.AssemblyInfoInputs.cache b/TermEngine/obj/Debug/net8.0/TermEngine.AssemblyInfoInputs.cache index 1725603..9eb64df 100644 --- a/TermEngine/obj/Debug/net8.0/TermEngine.AssemblyInfoInputs.cache +++ b/TermEngine/obj/Debug/net8.0/TermEngine.AssemblyInfoInputs.cache @@ -1 +1 @@ -432712ba9dc98f037959cf0668caa1627ade9f0aa69473645068c6ea52208868 +3d48c29292f9b3da258d45e3bdc45d2e18ec03103ca4e7baa8461e515fbe4981 diff --git a/TermEngine/obj/Debug/net8.0/TermEngine.csproj.CoreCompileInputs.cache b/TermEngine/obj/Debug/net8.0/TermEngine.csproj.CoreCompileInputs.cache index 3b2553a..4c73c71 100644 --- a/TermEngine/obj/Debug/net8.0/TermEngine.csproj.CoreCompileInputs.cache +++ b/TermEngine/obj/Debug/net8.0/TermEngine.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -4fba7de9be587e6bc37da5c47243a26c97f753def2985a170b262675dd805d5f +a2dd4e9d73438a6245251deea74b31585bcc1a2fd3c9c3f80d70811058104251 diff --git a/TermEngine/obj/Debug/net8.0/TermEngine.dll b/TermEngine/obj/Debug/net8.0/TermEngine.dll index de21ca4..9277044 100644 Binary files a/TermEngine/obj/Debug/net8.0/TermEngine.dll and b/TermEngine/obj/Debug/net8.0/TermEngine.dll differ diff --git a/TermEngine/obj/Debug/net8.0/TermEngine.pdb b/TermEngine/obj/Debug/net8.0/TermEngine.pdb index ce4dbc2..4d5c4d9 100644 Binary files a/TermEngine/obj/Debug/net8.0/TermEngine.pdb and b/TermEngine/obj/Debug/net8.0/TermEngine.pdb differ diff --git a/TermEngine/obj/Debug/net8.0/ref/TermEngine.dll b/TermEngine/obj/Debug/net8.0/ref/TermEngine.dll index 35785ae..7035747 100644 Binary files a/TermEngine/obj/Debug/net8.0/ref/TermEngine.dll and b/TermEngine/obj/Debug/net8.0/ref/TermEngine.dll differ diff --git a/TermEngine/obj/Debug/net8.0/refint/TermEngine.dll b/TermEngine/obj/Debug/net8.0/refint/TermEngine.dll index 35785ae..7035747 100644 Binary files a/TermEngine/obj/Debug/net8.0/refint/TermEngine.dll and b/TermEngine/obj/Debug/net8.0/refint/TermEngine.dll differ