So I was thinking of making a C# REPL, as I didn't find any viable solution that would work for me, so I made a simple, basic one, I am sure it can be improved, as it seems once the REPL class is initialized it's hard to add an event handler to it, or access the logs, so I am looking for a way to improve it, here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CS_REPL
{
public class REPL
{
List<string> inputLog;
public delegate void InputReceived(string input);
public event InputReceived InputHandler;
private bool loopEnabled = true;
public REPL(InputReceived handler)
{
inputLog = new List<string>();
InputHandler += handler;
while (loopEnabled)
{
string input = ReadLine();
inputLog.Add(input);
InputHandler?.Invoke(input);
}
}
public string ReadLine()
{
PrintShellIndicator();
return ReadInput();
}
public void PrintShellIndicator()
{
Console.Write("> ");
}
public string ReadInput()
{
return Console.ReadLine();
}
public void setRunning(bool flag)
{
loopEnabled = flag;
}
}
}